src/HOL/Isar_Examples/Basic_Logic.thy
author wenzelm
Mon, 02 Nov 2015 13:58:19 +0100
changeset 61541 846c72206207
parent 58882 6e2010ab8bd9
child 61542 b3eb789616c3
permissions -rw-r--r--
tuned document;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33026
8f35633c4922 modernized session Isar_Examples;
wenzelm
parents: 31758
diff changeset
     1
(*  Title:      HOL/Isar_Examples/Basic_Logic.thy
6444
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
     2
    Author:     Markus Wenzel, TU Muenchen
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
     3
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
     4
Basic propositional and quantifier reasoning.
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
     5
*)
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
     6
58882
6e2010ab8bd9 modernized header;
wenzelm
parents: 58614
diff changeset
     7
section \<open>Basic logical reasoning\<close>
7748
5b9c45b21782 improved presentation;
wenzelm
parents: 7740
diff changeset
     8
31758
3edd5f813f01 observe standard theory naming conventions;
wenzelm
parents: 23393
diff changeset
     9
theory Basic_Logic
3edd5f813f01 observe standard theory naming conventions;
wenzelm
parents: 23393
diff changeset
    10
imports Main
3edd5f813f01 observe standard theory naming conventions;
wenzelm
parents: 23393
diff changeset
    11
begin
6444
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
    12
7761
7fab9592384f improved presentation;
wenzelm
parents: 7748
diff changeset
    13
58614
7338eb25226c more cartouches;
wenzelm
parents: 55656
diff changeset
    14
subsection \<open>Pure backward reasoning\<close>
7740
2fbe5ce9845f tuned comments;
wenzelm
parents: 7604
diff changeset
    15
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    16
text \<open>In order to get a first idea of how Isabelle/Isar proof documents may
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    17
  look like, we consider the propositions \<open>I\<close>, \<open>K\<close>, and \<open>S\<close>. The following
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    18
  (rather explicit) proofs should require little extra explanations.\<close>
7001
8121e11ed765 Deriving rules in Isabelle;
wenzelm
parents: 6892
diff changeset
    19
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
    20
lemma I: "A \<longrightarrow> A"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
    21
proof
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
    22
  assume A
23393
31781b2de73d tuned proofs: avoid implicit prems;
wenzelm
parents: 23373
diff changeset
    23
  show A by fact
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
    24
qed
6444
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
    25
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
    26
lemma K: "A \<longrightarrow> B \<longrightarrow> A"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
    27
proof
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
    28
  assume A
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
    29
  show "B \<longrightarrow> A"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
    30
  proof
23393
31781b2de73d tuned proofs: avoid implicit prems;
wenzelm
parents: 23373
diff changeset
    31
    show A by fact
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
    32
  qed
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
    33
qed
6444
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
    34
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
    35
lemma S: "(A \<longrightarrow> B \<longrightarrow> C) \<longrightarrow> (A \<longrightarrow> B) \<longrightarrow> A \<longrightarrow> C"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
    36
proof
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
    37
  assume "A \<longrightarrow> B \<longrightarrow> C"
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
    38
  show "(A \<longrightarrow> B) \<longrightarrow> A \<longrightarrow> C"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
    39
  proof
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
    40
    assume "A \<longrightarrow> B"
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
    41
    show "A \<longrightarrow> C"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
    42
    proof
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
    43
      assume A
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
    44
      show C
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
    45
      proof (rule mp)
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
    46
        show "B \<longrightarrow> C" by (rule mp) fact+
23393
31781b2de73d tuned proofs: avoid implicit prems;
wenzelm
parents: 23373
diff changeset
    47
        show B by (rule mp) fact+
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
    48
      qed
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
    49
    qed
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
    50
  qed
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
    51
qed
6444
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
    52
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    53
text \<open>Isar provides several ways to fine-tune the reasoning, avoiding
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    54
  excessive detail. Several abbreviated language elements are available,
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    55
  enabling the writer to express proofs in a more concise way, even without
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    56
  referring to any automated proof tools yet.
7761
7fab9592384f improved presentation;
wenzelm
parents: 7748
diff changeset
    57
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    58
  First of all, proof by assumption may be abbreviated as a single dot.\<close>
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
    59
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
    60
lemma "A \<longrightarrow> A"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
    61
proof
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
    62
  assume A
23393
31781b2de73d tuned proofs: avoid implicit prems;
wenzelm
parents: 23373
diff changeset
    63
  show A by fact+
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
    64
qed
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
    65
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    66
text \<open>In fact, concluding any (sub-)proof already involves solving any
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    67
  remaining goals by assumption\footnote{This is not a completely trivial
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    68
  operation, as proof by assumption may involve full higher-order
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    69
  unification.}. Thus we may skip the rather vacuous body of the above proof
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    70
  as well.\<close>
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
    71
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
    72
lemma "A \<longrightarrow> A"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
    73
proof
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
    74
qed
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
    75
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    76
text \<open>Note that the \isacommand{proof} command refers to the \<open>rule\<close> method
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    77
  (without arguments) by default. Thus it implicitly applies a single rule,
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    78
  as determined from the syntactic form of the statements involved. The
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    79
  \isacommand{by} command abbreviates any proof with empty body, so the
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    80
  proof may be further pruned.\<close>
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
    81
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
    82
lemma "A \<longrightarrow> A"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
    83
  by rule
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
    84
58614
7338eb25226c more cartouches;
wenzelm
parents: 55656
diff changeset
    85
text \<open>Proof by a single rule may be abbreviated as double-dot.\<close>
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
    86
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
    87
lemma "A \<longrightarrow> A" ..
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
    88
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    89
text \<open>Thus we have arrived at an adequate representation of the proof of a
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    90
  tautology that holds by a single standard rule.\footnote{Apparently, the
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    91
  rule here is implication introduction.}
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
    92
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    93
  \<^medskip>
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    94
  Let us also reconsider \<open>K\<close>. Its statement is composed of iterated
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    95
  connectives. Basic decomposition is by a single rule at a time, which is
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    96
  why our first version above was by nesting two proofs.
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
    97
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    98
  The \<open>intro\<close> proof method repeatedly decomposes a goal's
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
    99
  conclusion.\footnote{The dual method is \<open>elim\<close>, acting on a goal's
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   100
  premises.}\<close>
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
   101
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   102
lemma "A \<longrightarrow> B \<longrightarrow> A"
12387
fe2353a8d1e8 fixed intro steps;
wenzelm
parents: 10636
diff changeset
   103
proof (intro impI)
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   104
  assume A
23393
31781b2de73d tuned proofs: avoid implicit prems;
wenzelm
parents: 23373
diff changeset
   105
  show A by fact
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   106
qed
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
   107
58614
7338eb25226c more cartouches;
wenzelm
parents: 55656
diff changeset
   108
text \<open>Again, the body may be collapsed.\<close>
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
   109
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   110
lemma "A \<longrightarrow> B \<longrightarrow> A"
12387
fe2353a8d1e8 fixed intro steps;
wenzelm
parents: 10636
diff changeset
   111
  by (intro impI)
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
   112
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   113
text \<open>Just like \<open>rule\<close>, the \<open>intro\<close> and \<open>elim\<close> proof methods pick standard
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   114
  structural rules, in case no explicit arguments are given. While implicit
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   115
  rules are usually just fine for single rule application, this may go too
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   116
  far with iteration. Thus in practice, \<open>intro\<close> and \<open>elim\<close> would be
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   117
  typically restricted to certain structures by giving a few rules only,
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   118
  e.g.\ \isacommand{proof}~\<open>(intro impI allI)\<close> to strip implications and
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   119
  universal quantifiers.
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
   120
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   121
  Such well-tuned iterated decomposition of certain structures is the prime
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   122
  application of \<open>intro\<close> and \<open>elim\<close>. In contrast, terminal steps that solve
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   123
  a goal completely are usually performed by actual automated proof methods
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   124
  (such as \isacommand{by}~\<open>blast\<close>.\<close>
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
   125
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
   126
58614
7338eb25226c more cartouches;
wenzelm
parents: 55656
diff changeset
   127
subsection \<open>Variations of backward vs.\ forward reasoning\<close>
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
   128
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   129
text \<open>Certainly, any proof may be performed in backward-style only. On the
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   130
  other hand, small steps of reasoning are often more naturally expressed in
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   131
  forward-style. Isar supports both backward and forward reasoning as a
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   132
  first-class concept. In order to demonstrate the difference, we consider
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   133
  several proofs of \<open>A \<and> B \<longrightarrow> B \<and> A\<close>.
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
   134
58614
7338eb25226c more cartouches;
wenzelm
parents: 55656
diff changeset
   135
  The first version is purely backward.\<close>
7001
8121e11ed765 Deriving rules in Isabelle;
wenzelm
parents: 6892
diff changeset
   136
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   137
lemma "A \<and> B \<longrightarrow> B \<and> A"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   138
proof
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   139
  assume "A \<and> B"
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   140
  show "B \<and> A"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   141
  proof
23393
31781b2de73d tuned proofs: avoid implicit prems;
wenzelm
parents: 23373
diff changeset
   142
    show B by (rule conjunct2) fact
31781b2de73d tuned proofs: avoid implicit prems;
wenzelm
parents: 23373
diff changeset
   143
    show A by (rule conjunct1) fact
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   144
  qed
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   145
qed
6444
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
   146
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   147
text \<open>Above, the projection rules \<open>conjunct1\<close> / \<open>conjunct2\<close> had to be named
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   148
  explicitly, since the goals \<open>B\<close> and \<open>A\<close> did not provide any structural
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   149
  clue. This may be avoided using \isacommand{from} to focus on the \<open>A \<and> B\<close>
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   150
  assumption as the current facts, enabling the use of double-dot proofs.
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   151
  Note that \isacommand{from} already does forward-chaining, involving the
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   152
  \<open>conjE\<close> rule here.\<close>
6444
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
   153
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   154
lemma "A \<and> B \<longrightarrow> B \<and> A"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   155
proof
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   156
  assume "A \<and> B"
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   157
  show "B \<and> A"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   158
  proof
58614
7338eb25226c more cartouches;
wenzelm
parents: 55656
diff changeset
   159
    from \<open>A \<and> B\<close> show B ..
7338eb25226c more cartouches;
wenzelm
parents: 55656
diff changeset
   160
    from \<open>A \<and> B\<close> show A ..
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   161
  qed
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   162
qed
7604
wenzelm
parents: 7480
diff changeset
   163
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   164
text \<open>In the next version, we move the forward step one level upwards.
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   165
  Forward-chaining from the most recent facts is indicated by the
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   166
  \isacommand{then} command. Thus the proof of \<open>B \<and> A\<close> from \<open>A \<and> B\<close> actually
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   167
  becomes an elimination, rather than an introduction. The resulting proof
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   168
  structure directly corresponds to that of the \<open>conjE\<close> rule, including the
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   169
  repeated goal proposition that is abbreviated as \<open>?thesis\<close> below.\<close>
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
   170
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   171
lemma "A \<and> B \<longrightarrow> B \<and> A"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   172
proof
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   173
  assume "A \<and> B"
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   174
  then show "B \<and> A"
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   175
  proof                    -- \<open>rule \<open>conjE\<close> of \<open>A \<and> B\<close>\<close>
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 18193
diff changeset
   176
    assume B A
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   177
    then show ?thesis ..   -- \<open>rule \<open>conjI\<close> of \<open>B \<and> A\<close>\<close>
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   178
  qed
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   179
qed
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
   180
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   181
text \<open>In the subsequent version we flatten the structure of the main body by
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   182
  doing forward reasoning all the time. Only the outermost decomposition
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   183
  step is left as backward.\<close>
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
   184
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   185
lemma "A \<and> B \<longrightarrow> B \<and> A"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   186
proof
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   187
  assume "A \<and> B"
58614
7338eb25226c more cartouches;
wenzelm
parents: 55656
diff changeset
   188
  from \<open>A \<and> B\<close> have A ..
7338eb25226c more cartouches;
wenzelm
parents: 55656
diff changeset
   189
  from \<open>A \<and> B\<close> have B ..
7338eb25226c more cartouches;
wenzelm
parents: 55656
diff changeset
   190
  from \<open>B\<close> \<open>A\<close> show "B \<and> A" ..
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   191
qed
6444
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
   192
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   193
text \<open>We can still push forward-reasoning a bit further, even at the risk of
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   194
  getting ridiculous. Note that we force the initial proof step to do
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   195
  nothing here, by referring to the \<open>-\<close> proof method.\<close>
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
   196
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   197
lemma "A \<and> B \<longrightarrow> B \<and> A"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   198
proof -
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   199
  {
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   200
    assume "A \<and> B"
58614
7338eb25226c more cartouches;
wenzelm
parents: 55656
diff changeset
   201
    from \<open>A \<and> B\<close> have A ..
7338eb25226c more cartouches;
wenzelm
parents: 55656
diff changeset
   202
    from \<open>A \<and> B\<close> have B ..
7338eb25226c more cartouches;
wenzelm
parents: 55656
diff changeset
   203
    from \<open>B\<close> \<open>A\<close> have "B \<and> A" ..
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   204
  }
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   205
  then show ?thesis ..         -- \<open>rule \<open>impI\<close>\<close>
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   206
qed
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
   207
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   208
text \<open>
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   209
  \<^medskip>
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   210
  With these examples we have shifted through a whole range from purely
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   211
  backward to purely forward reasoning. Apparently, in the extreme ends we
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   212
  get slightly ill-structured proofs, which also require much explicit
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   213
  naming of either rules (backward) or local facts (forward).
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
   214
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   215
  The general lesson learned here is that good proof style would achieve
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   216
  just the \<^emph>\<open>right\<close> balance of top-down backward decomposition, and
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   217
  bottom-up forward composition. In general, there is no single best way to
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   218
  arrange some pieces of formal reasoning, of course. Depending on the
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   219
  actual applications, the intended audience etc., rules (and methods) on
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   220
  the one hand vs.\ facts on the other hand have to be emphasized in an
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   221
  appropriate way. This requires the proof writer to develop good taste, and
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   222
  some practice, of course.
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
   223
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   224
  \<^medskip>
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   225
  For our example the most appropriate way of reasoning is probably the
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   226
  middle one, with conjunction introduction done after elimination.\<close>
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
   227
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   228
lemma "A \<and> B \<longrightarrow> B \<and> A"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   229
proof
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   230
  assume "A \<and> B"
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   231
  then show "B \<and> A"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   232
  proof
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 18193
diff changeset
   233
    assume B A
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 18193
diff changeset
   234
    then show ?thesis ..
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   235
  qed
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   236
qed
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
   237
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
   238
6444
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
   239
58614
7338eb25226c more cartouches;
wenzelm
parents: 55656
diff changeset
   240
subsection \<open>A few examples from ``Introduction to Isabelle''\<close>
7001
8121e11ed765 Deriving rules in Isabelle;
wenzelm
parents: 6892
diff changeset
   241
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   242
text \<open>We rephrase some of the basic reasoning examples of @{cite
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   243
  "isabelle-intro"}, using HOL rather than FOL.\<close>
37671
fa53d267dab3 misc tuning and modernization;
wenzelm
parents: 33026
diff changeset
   244
7820
cad7cc30fa40 more explanations;
wenzelm
parents: 7761
diff changeset
   245
58614
7338eb25226c more cartouches;
wenzelm
parents: 55656
diff changeset
   246
subsubsection \<open>A propositional proof\<close>
7833
f5288e4b95d1 improved presentation;
wenzelm
parents: 7820
diff changeset
   247
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   248
text \<open>We consider the proposition \<open>P \<or> P \<longrightarrow> P\<close>. The proof below involves
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   249
  forward-chaining from \<open>P \<or> P\<close>, followed by an explicit case-analysis on
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   250
  the two \<^emph>\<open>identical\<close> cases.\<close>
6444
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
   251
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   252
lemma "P \<or> P \<longrightarrow> P"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   253
proof
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   254
  assume "P \<or> P"
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 18193
diff changeset
   255
  then show P
58614
7338eb25226c more cartouches;
wenzelm
parents: 55656
diff changeset
   256
  proof                    -- \<open>
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   257
    rule \<open>disjE\<close>: \smash{$\infer{C}{A \disj B & \infer*{C}{[A]} & \infer*{C}{[B]}}$}
58614
7338eb25226c more cartouches;
wenzelm
parents: 55656
diff changeset
   258
\<close>
23393
31781b2de73d tuned proofs: avoid implicit prems;
wenzelm
parents: 23373
diff changeset
   259
    assume P show P by fact
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   260
  next
23393
31781b2de73d tuned proofs: avoid implicit prems;
wenzelm
parents: 23373
diff changeset
   261
    assume P show P by fact
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   262
  qed
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   263
qed
7833
f5288e4b95d1 improved presentation;
wenzelm
parents: 7820
diff changeset
   264
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   265
text \<open>Case splits are \<^emph>\<open>not\<close> hardwired into the Isar language as a
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   266
  special feature. The \isacommand{next} command used to separate the cases
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   267
  above is just a short form of managing block structure.
7833
f5288e4b95d1 improved presentation;
wenzelm
parents: 7820
diff changeset
   268
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   269
  \<^medskip>
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   270
  In general, applying proof methods may split up a goal into separate
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   271
  ``cases'', i.e.\ new subgoals with individual local assumptions. The
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   272
  corresponding proof text typically mimics this by establishing results in
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   273
  appropriate contexts, separated by blocks.
7833
f5288e4b95d1 improved presentation;
wenzelm
parents: 7820
diff changeset
   274
18193
54419506df9e tuned document;
wenzelm
parents: 16417
diff changeset
   275
  In order to avoid too much explicit parentheses, the Isar system
54419506df9e tuned document;
wenzelm
parents: 16417
diff changeset
   276
  implicitly opens an additional block for any new goal, the
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   277
  \isacommand{next} statement then closes one block level, opening a new
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   278
  one. The resulting behaviour is what one would expect from separating
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   279
  cases, only that it is more flexible. E.g.\ an induction base case (which
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   280
  does not introduce local assumptions) would \<^emph>\<open>not\<close> require
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   281
  \isacommand{next} to separate the subsequent step case.
7833
f5288e4b95d1 improved presentation;
wenzelm
parents: 7820
diff changeset
   282
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   283
  \<^medskip>
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   284
  In our example the situation is even simpler, since the two cases actually
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   285
  coincide. Consequently the proof may be rephrased as follows.\<close>
7833
f5288e4b95d1 improved presentation;
wenzelm
parents: 7820
diff changeset
   286
55656
eb07b0acbebc more symbols;
wenzelm
parents: 55640
diff changeset
   287
lemma "P \<or> P \<longrightarrow> P"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   288
proof
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   289
  assume "P \<or> P"
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 18193
diff changeset
   290
  then show P
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   291
  proof
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   292
    assume P
23393
31781b2de73d tuned proofs: avoid implicit prems;
wenzelm
parents: 23373
diff changeset
   293
    show P by fact
31781b2de73d tuned proofs: avoid implicit prems;
wenzelm
parents: 23373
diff changeset
   294
    show P by fact
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   295
  qed
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   296
qed
6444
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
   297
58614
7338eb25226c more cartouches;
wenzelm
parents: 55656
diff changeset
   298
text \<open>Again, the rather vacuous body of the proof may be collapsed.
37671
fa53d267dab3 misc tuning and modernization;
wenzelm
parents: 33026
diff changeset
   299
  Thus the case analysis degenerates into two assumption steps, which
fa53d267dab3 misc tuning and modernization;
wenzelm
parents: 33026
diff changeset
   300
  are implicitly performed when concluding the single rule step of the
58614
7338eb25226c more cartouches;
wenzelm
parents: 55656
diff changeset
   301
  double-dot proof as follows.\<close>
7833
f5288e4b95d1 improved presentation;
wenzelm
parents: 7820
diff changeset
   302
55656
eb07b0acbebc more symbols;
wenzelm
parents: 55640
diff changeset
   303
lemma "P \<or> P \<longrightarrow> P"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   304
proof
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   305
  assume "P \<or> P"
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 18193
diff changeset
   306
  then show P ..
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   307
qed
6444
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
   308
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
   309
58614
7338eb25226c more cartouches;
wenzelm
parents: 55656
diff changeset
   310
subsubsection \<open>A quantifier proof\<close>
7833
f5288e4b95d1 improved presentation;
wenzelm
parents: 7820
diff changeset
   311
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   312
text \<open>To illustrate quantifier reasoning, let us prove
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   313
  \<open>(\<exists>x. P (f x)) \<longrightarrow> (\<exists>y. P y)\<close>. Informally, this holds because any \<open>a\<close> with
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   314
  \<open>P (f a)\<close> may be taken as a witness for the second existential statement.
6444
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
   315
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   316
  The first proof is rather verbose, exhibiting quite a lot of (redundant)
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   317
  detail. It gives explicit rules, even with some instantiation.
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   318
  Furthermore, we encounter two new language elements: the \isacommand{fix}
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   319
  command augments the context by some new ``arbitrary, but fixed'' element;
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   320
  the \isacommand{is} annotation binds term abbreviations by higher-order
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   321
  pattern matching.\<close>
7833
f5288e4b95d1 improved presentation;
wenzelm
parents: 7820
diff changeset
   322
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   323
lemma "(\<exists>x. P (f x)) \<longrightarrow> (\<exists>y. P y)"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   324
proof
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   325
  assume "\<exists>x. P (f x)"
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   326
  then show "\<exists>y. P y"
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   327
  proof (rule exE)             --
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   328
    \<open>rule \<open>exE\<close>: \smash{$\infer{B}{\ex x A(x) & \infer*{B}{[A(x)]_x}}$}\<close>
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   329
    fix a
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   330
    assume "P (f a)" (is "P ?witness")
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 18193
diff changeset
   331
    then show ?thesis by (rule exI [of P ?witness])
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   332
  qed
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   333
qed
6444
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
   334
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   335
text \<open>While explicit rule instantiation may occasionally improve readability
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   336
  of certain aspects of reasoning, it is usually quite redundant. Above, the
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   337
  basic proof outline gives already enough structural clues for the system
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   338
  to infer both the rules and their instances (by higher-order unification).
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   339
  Thus we may as well prune the text as follows.\<close>
7833
f5288e4b95d1 improved presentation;
wenzelm
parents: 7820
diff changeset
   340
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   341
lemma "(\<exists>x. P (f x)) \<longrightarrow> (\<exists>y. P y)"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   342
proof
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   343
  assume "\<exists>x. P (f x)"
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   344
  then show "\<exists>y. P y"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   345
  proof
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   346
    fix a
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   347
    assume "P (f a)"
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 18193
diff changeset
   348
    then show ?thesis ..
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   349
  qed
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   350
qed
6444
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
   351
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   352
text \<open>Explicit \<open>\<exists>\<close>-elimination as seen above can become quite cumbersome in
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   353
  practice. The derived Isar language element ``\isakeyword{obtain}''
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   354
  provides a more handsome way to do generalized existence reasoning.\<close>
9477
9506127f6fbb obtain;
wenzelm
parents: 8902
diff changeset
   355
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   356
lemma "(\<exists>x. P (f x)) \<longrightarrow> (\<exists>y. P y)"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   357
proof
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   358
  assume "\<exists>x. P (f x)"
10636
wenzelm
parents: 10007
diff changeset
   359
  then obtain a where "P (f a)" ..
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   360
  then show "\<exists>y. P y" ..
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   361
qed
9477
9506127f6fbb obtain;
wenzelm
parents: 8902
diff changeset
   362
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   363
text \<open>Technically, \isakeyword{obtain} is similar to \isakeyword{fix} and
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   364
  \isakeyword{assume} together with a soundness proof of the elimination
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   365
  involved. Thus it behaves similar to any other forward proof element. Also
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   366
  note that due to the nature of general existence reasoning involved here,
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   367
  any result exported from the context of an \isakeyword{obtain} statement
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   368
  may \<^emph>\<open>not\<close> refer to the parameters introduced there.\<close>
9477
9506127f6fbb obtain;
wenzelm
parents: 8902
diff changeset
   369
6444
2ebe9e630cab Miscellaneous Isabelle/Isar examples for Higher-Order Logic.
wenzelm
parents:
diff changeset
   370
58614
7338eb25226c more cartouches;
wenzelm
parents: 55656
diff changeset
   371
subsubsection \<open>Deriving rules in Isabelle\<close>
7001
8121e11ed765 Deriving rules in Isabelle;
wenzelm
parents: 6892
diff changeset
   372
61541
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   373
text \<open>We derive the conjunction elimination rule from the corresponding
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   374
  projections. The proof is quite straight-forward, since Isabelle/Isar
846c72206207 tuned document;
wenzelm
parents: 58882
diff changeset
   375
  supports non-atomic goals and assumptions fully transparently.\<close>
7001
8121e11ed765 Deriving rules in Isabelle;
wenzelm
parents: 6892
diff changeset
   376
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   377
theorem conjE: "A \<and> B \<Longrightarrow> (A \<Longrightarrow> B \<Longrightarrow> C) \<Longrightarrow> C"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   378
proof -
55640
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   379
  assume "A \<and> B"
abc140f21caa tuned proofs;
wenzelm
parents: 37671
diff changeset
   380
  assume r: "A \<Longrightarrow> B \<Longrightarrow> C"
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   381
  show C
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   382
  proof (rule r)
23393
31781b2de73d tuned proofs: avoid implicit prems;
wenzelm
parents: 23373
diff changeset
   383
    show A by (rule conjunct1) fact
31781b2de73d tuned proofs: avoid implicit prems;
wenzelm
parents: 23373
diff changeset
   384
    show B by (rule conjunct2) fact
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   385
  qed
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   386
qed
7001
8121e11ed765 Deriving rules in Isabelle;
wenzelm
parents: 6892
diff changeset
   387
10007
64bf7da1994a isar-strip-terminators;
wenzelm
parents: 9659
diff changeset
   388
end