doc-src/IsarRef/Thy/First_Order_Logic.thy
author wenzelm
Mon, 03 Oct 2011 11:14:19 +0200
changeset 45988 a45121ffcfcb
parent 43522 e3fdb7c96be5
permissions -rw-r--r--
some amendments due to Jean Pichon;
wenzelm@30056
     1
wenzelm@30056
     2
header {* Example: First-Order Logic *}
wenzelm@30056
     3
wenzelm@30056
     4
theory %visible First_Order_Logic
wenzelm@43522
     5
imports Base  (* FIXME Pure!? *)
wenzelm@30056
     6
begin
wenzelm@30056
     7
wenzelm@30056
     8
text {*
wenzelm@30058
     9
  \noindent In order to commence a new object-logic within
wenzelm@30058
    10
  Isabelle/Pure we introduce abstract syntactic categories @{text "i"}
wenzelm@30058
    11
  for individuals and @{text "o"} for object-propositions.  The latter
wenzelm@30058
    12
  is embedded into the language of Pure propositions by means of a
wenzelm@30058
    13
  separate judgment.
wenzelm@30056
    14
*}
wenzelm@30056
    15
wenzelm@30056
    16
typedecl i
wenzelm@30056
    17
typedecl o
wenzelm@30056
    18
wenzelm@30056
    19
judgment
wenzelm@30056
    20
  Trueprop :: "o \<Rightarrow> prop"    ("_" 5)
wenzelm@30056
    21
wenzelm@30056
    22
text {*
wenzelm@30056
    23
  \noindent Note that the object-logic judgement is implicit in the
wenzelm@30056
    24
  syntax: writing @{prop A} produces @{term "Trueprop A"} internally.
wenzelm@30056
    25
  From the Pure perspective this means ``@{prop A} is derivable in the
wenzelm@30056
    26
  object-logic''.
wenzelm@30056
    27
*}
wenzelm@30056
    28
wenzelm@30056
    29
wenzelm@30056
    30
subsection {* Equational reasoning \label{sec:framework-ex-equal} *}
wenzelm@30056
    31
wenzelm@30056
    32
text {*
wenzelm@30056
    33
  Equality is axiomatized as a binary predicate on individuals, with
wenzelm@30056
    34
  reflexivity as introduction, and substitution as elimination
wenzelm@30056
    35
  principle.  Note that the latter is particularly convenient in a
wenzelm@30056
    36
  framework like Isabelle, because syntactic congruences are
wenzelm@30056
    37
  implicitly produced by unification of @{term "B x"} against
wenzelm@30056
    38
  expressions containing occurrences of @{term x}.
wenzelm@30056
    39
*}
wenzelm@30056
    40
wenzelm@30056
    41
axiomatization
wenzelm@30056
    42
  equal :: "i \<Rightarrow> i \<Rightarrow> o"  (infix "=" 50)
wenzelm@30056
    43
where
wenzelm@30056
    44
  refl [intro]: "x = x" and
wenzelm@30056
    45
  subst [elim]: "x = y \<Longrightarrow> B x \<Longrightarrow> B y"
wenzelm@30056
    46
wenzelm@30056
    47
text {*
wenzelm@30056
    48
  \noindent Substitution is very powerful, but also hard to control in
wenzelm@30056
    49
  full generality.  We derive some common symmetry~/ transitivity
wenzelm@45988
    50
  schemes of @{term equal} as particular consequences.
wenzelm@30056
    51
*}
wenzelm@30056
    52
wenzelm@30056
    53
theorem sym [sym]:
wenzelm@30056
    54
  assumes "x = y"
wenzelm@30056
    55
  shows "y = x"
wenzelm@30056
    56
proof -
wenzelm@30056
    57
  have "x = x" ..
wenzelm@30056
    58
  with `x = y` show "y = x" ..
wenzelm@30056
    59
qed
wenzelm@30056
    60
wenzelm@30056
    61
theorem forw_subst [trans]:
wenzelm@30056
    62
  assumes "y = x" and "B x"
wenzelm@30056
    63
  shows "B y"
wenzelm@30056
    64
proof -
wenzelm@30056
    65
  from `y = x` have "x = y" ..
wenzelm@30056
    66
  from this and `B x` show "B y" ..
wenzelm@30056
    67
qed
wenzelm@30056
    68
wenzelm@30056
    69
theorem back_subst [trans]:
wenzelm@30056
    70
  assumes "B x" and "x = y"
wenzelm@30056
    71
  shows "B y"
wenzelm@30056
    72
proof -
wenzelm@30056
    73
  from `x = y` and `B x`
wenzelm@30056
    74
  show "B y" ..
wenzelm@30056
    75
qed
wenzelm@30056
    76
wenzelm@30056
    77
theorem trans [trans]:
wenzelm@30056
    78
  assumes "x = y" and "y = z"
wenzelm@30056
    79
  shows "x = z"
wenzelm@30056
    80
proof -
wenzelm@30056
    81
  from `y = z` and `x = y`
wenzelm@30056
    82
  show "x = z" ..
wenzelm@30056
    83
qed
wenzelm@30056
    84
wenzelm@30056
    85
wenzelm@30056
    86
subsection {* Basic group theory *}
wenzelm@30056
    87
wenzelm@30056
    88
text {*
wenzelm@30056
    89
  As an example for equational reasoning we consider some bits of
wenzelm@30056
    90
  group theory.  The subsequent locale definition postulates group
wenzelm@30056
    91
  operations and axioms; we also derive some consequences of this
wenzelm@30056
    92
  specification.
wenzelm@30056
    93
*}
wenzelm@30056
    94
wenzelm@30056
    95
locale group =
wenzelm@30056
    96
  fixes prod :: "i \<Rightarrow> i \<Rightarrow> i"  (infix "\<circ>" 70)
wenzelm@30056
    97
    and inv :: "i \<Rightarrow> i"  ("(_\<inverse>)" [1000] 999)
wenzelm@30056
    98
    and unit :: i  ("1")
wenzelm@30056
    99
  assumes assoc: "(x \<circ> y) \<circ> z = x \<circ> (y \<circ> z)"
wenzelm@30056
   100
    and left_unit:  "1 \<circ> x = x"
wenzelm@30056
   101
    and left_inv: "x\<inverse> \<circ> x = 1"
wenzelm@30056
   102
begin
wenzelm@30056
   103
wenzelm@30056
   104
theorem right_inv: "x \<circ> x\<inverse> = 1"
wenzelm@30056
   105
proof -
wenzelm@30056
   106
  have "x \<circ> x\<inverse> = 1 \<circ> (x \<circ> x\<inverse>)" by (rule left_unit [symmetric])
wenzelm@30056
   107
  also have "\<dots> = (1 \<circ> x) \<circ> x\<inverse>" by (rule assoc [symmetric])
wenzelm@30056
   108
  also have "1 = (x\<inverse>)\<inverse> \<circ> x\<inverse>" by (rule left_inv [symmetric])
wenzelm@30056
   109
  also have "\<dots> \<circ> x = (x\<inverse>)\<inverse> \<circ> (x\<inverse> \<circ> x)" by (rule assoc)
wenzelm@30056
   110
  also have "x\<inverse> \<circ> x = 1" by (rule left_inv)
wenzelm@30056
   111
  also have "((x\<inverse>)\<inverse> \<circ> \<dots>) \<circ> x\<inverse> = (x\<inverse>)\<inverse> \<circ> (1 \<circ> x\<inverse>)" by (rule assoc)
wenzelm@30056
   112
  also have "1 \<circ> x\<inverse> = x\<inverse>" by (rule left_unit)
wenzelm@30056
   113
  also have "(x\<inverse>)\<inverse> \<circ> \<dots> = 1" by (rule left_inv)
wenzelm@30056
   114
  finally show "x \<circ> x\<inverse> = 1" .
wenzelm@30056
   115
qed
wenzelm@30056
   116
wenzelm@30056
   117
theorem right_unit: "x \<circ> 1 = x"
wenzelm@30056
   118
proof -
wenzelm@30056
   119
  have "1 = x\<inverse> \<circ> x" by (rule left_inv [symmetric])
wenzelm@30056
   120
  also have "x \<circ> \<dots> = (x \<circ> x\<inverse>) \<circ> x" by (rule assoc [symmetric])
wenzelm@30056
   121
  also have "x \<circ> x\<inverse> = 1" by (rule right_inv)
wenzelm@30056
   122
  also have "\<dots> \<circ> x = x" by (rule left_unit)
wenzelm@30056
   123
  finally show "x \<circ> 1 = x" .
wenzelm@30056
   124
qed
wenzelm@30056
   125
wenzelm@30056
   126
text {*
wenzelm@30058
   127
  \noindent Reasoning from basic axioms is often tedious.  Our proofs
wenzelm@30058
   128
  work by producing various instances of the given rules (potentially
wenzelm@30058
   129
  the symmetric form) using the pattern ``@{command have}~@{text
wenzelm@30056
   130
  eq}~@{command "by"}~@{text "(rule r)"}'' and composing the chain of
wenzelm@30056
   131
  results via @{command also}/@{command finally}.  These steps may
wenzelm@30056
   132
  involve any of the transitivity rules declared in
wenzelm@30056
   133
  \secref{sec:framework-ex-equal}, namely @{thm trans} in combining
wenzelm@30056
   134
  the first two results in @{thm right_inv} and in the final steps of
wenzelm@30056
   135
  both proofs, @{thm forw_subst} in the first combination of @{thm
wenzelm@30056
   136
  right_unit}, and @{thm back_subst} in all other calculational steps.
wenzelm@30056
   137
wenzelm@30056
   138
  Occasional substitutions in calculations are adequate, but should
wenzelm@30056
   139
  not be over-emphasized.  The other extreme is to compose a chain by
wenzelm@30056
   140
  plain transitivity only, with replacements occurring always in
wenzelm@30056
   141
  topmost position. For example:
wenzelm@30056
   142
*}
wenzelm@30056
   143
wenzelm@30056
   144
(*<*)
wenzelm@30056
   145
theorem "\<And>A. PROP A \<Longrightarrow> PROP A"
wenzelm@30056
   146
proof -
wenzelm@30056
   147
  assume [symmetric, defn]: "\<And>x y. (x \<equiv> y) \<equiv> Trueprop (x = y)"
wenzelm@30056
   148
(*>*)
wenzelm@30056
   149
  have "x \<circ> 1 = x \<circ> (x\<inverse> \<circ> x)" unfolding left_inv ..
wenzelm@30056
   150
  also have "\<dots> = (x \<circ> x\<inverse>) \<circ> x" unfolding assoc ..
wenzelm@30056
   151
  also have "\<dots> = 1 \<circ> x" unfolding right_inv ..
wenzelm@30056
   152
  also have "\<dots> = x" unfolding left_unit ..
wenzelm@30056
   153
  finally have "x \<circ> 1 = x" .
wenzelm@30056
   154
(*<*)
wenzelm@30056
   155
qed
wenzelm@30056
   156
(*>*)
wenzelm@30056
   157
wenzelm@30056
   158
text {*
wenzelm@30056
   159
  \noindent Here we have re-used the built-in mechanism for unfolding
wenzelm@30056
   160
  definitions in order to normalize each equational problem.  A more
wenzelm@30056
   161
  realistic object-logic would include proper setup for the Simplifier
wenzelm@30056
   162
  (\secref{sec:simplifier}), the main automated tool for equational
wenzelm@30058
   163
  reasoning in Isabelle.  Then ``@{command unfolding}~@{thm
wenzelm@30056
   164
  left_inv}~@{command ".."}'' would become ``@{command "by"}~@{text
wenzelm@30061
   165
  "(simp only: left_inv)"}'' etc.
wenzelm@30056
   166
*}
wenzelm@30056
   167
wenzelm@30056
   168
end
wenzelm@30056
   169
wenzelm@30056
   170
wenzelm@30060
   171
subsection {* Propositional logic \label{sec:framework-ex-prop} *}
wenzelm@30056
   172
wenzelm@30056
   173
text {*
wenzelm@30056
   174
  We axiomatize basic connectives of propositional logic: implication,
wenzelm@30056
   175
  disjunction, and conjunction.  The associated rules are modeled
wenzelm@30058
   176
  after Gentzen's system of Natural Deduction \cite{Gentzen:1935}.
wenzelm@30056
   177
*}
wenzelm@30056
   178
wenzelm@30056
   179
axiomatization
wenzelm@30056
   180
  imp :: "o \<Rightarrow> o \<Rightarrow> o"  (infixr "\<longrightarrow>" 25) where
wenzelm@30056
   181
  impI [intro]: "(A \<Longrightarrow> B) \<Longrightarrow> A \<longrightarrow> B" and
wenzelm@30056
   182
  impD [dest]: "(A \<longrightarrow> B) \<Longrightarrow> A \<Longrightarrow> B"
wenzelm@30056
   183
wenzelm@30056
   184
axiomatization
wenzelm@30056
   185
  disj :: "o \<Rightarrow> o \<Rightarrow> o"  (infixr "\<or>" 30) where
wenzelm@30056
   186
  disjI\<^isub>1 [intro]: "A \<Longrightarrow> A \<or> B" and
wenzelm@30060
   187
  disjI\<^isub>2 [intro]: "B \<Longrightarrow> A \<or> B" and
wenzelm@30060
   188
  disjE [elim]: "A \<or> B \<Longrightarrow> (A \<Longrightarrow> C) \<Longrightarrow> (B \<Longrightarrow> C) \<Longrightarrow> C"
wenzelm@30056
   189
wenzelm@30056
   190
axiomatization
wenzelm@30056
   191
  conj :: "o \<Rightarrow> o \<Rightarrow> o"  (infixr "\<and>" 35) where
wenzelm@30056
   192
  conjI [intro]: "A \<Longrightarrow> B \<Longrightarrow> A \<and> B" and
wenzelm@30060
   193
  conjD\<^isub>1: "A \<and> B \<Longrightarrow> A" and
wenzelm@30060
   194
  conjD\<^isub>2: "A \<and> B \<Longrightarrow> B"
wenzelm@30056
   195
wenzelm@30056
   196
text {*
wenzelm@30056
   197
  \noindent The conjunctive destructions have the disadvantage that
wenzelm@30056
   198
  decomposing @{prop "A \<and> B"} involves an immediate decision which
wenzelm@30056
   199
  component should be projected.  The more convenient simultaneous
wenzelm@30056
   200
  elimination @{prop "A \<and> B \<Longrightarrow> (A \<Longrightarrow> B \<Longrightarrow> C) \<Longrightarrow> C"} can be derived as
wenzelm@30056
   201
  follows:
wenzelm@30056
   202
*}
wenzelm@30056
   203
wenzelm@30056
   204
theorem conjE [elim]:
wenzelm@30056
   205
  assumes "A \<and> B"
wenzelm@30056
   206
  obtains A and B
wenzelm@30056
   207
proof
wenzelm@30060
   208
  from `A \<and> B` show A by (rule conjD\<^isub>1)
wenzelm@30060
   209
  from `A \<and> B` show B by (rule conjD\<^isub>2)
wenzelm@30056
   210
qed
wenzelm@30056
   211
wenzelm@30056
   212
text {*
wenzelm@30056
   213
  \noindent Here is an example of swapping conjuncts with a single
wenzelm@30056
   214
  intermediate elimination step:
wenzelm@30056
   215
*}
wenzelm@30056
   216
wenzelm@30056
   217
(*<*)
wenzelm@30056
   218
lemma "\<And>A. PROP A \<Longrightarrow> PROP A"
wenzelm@30056
   219
proof -
wenzelm@30056
   220
(*>*)
wenzelm@30056
   221
  assume "A \<and> B"
wenzelm@30056
   222
  then obtain B and A ..
wenzelm@30056
   223
  then have "B \<and> A" ..
wenzelm@30056
   224
(*<*)
wenzelm@30056
   225
qed
wenzelm@30056
   226
(*>*)
wenzelm@30056
   227
wenzelm@30056
   228
text {*
wenzelm@30058
   229
  \noindent Note that the analogous elimination rule for disjunction
wenzelm@30058
   230
  ``@{text "\<ASSUMES> A \<or> B \<OBTAINS> A \<BBAR> B"}'' coincides with
wenzelm@30058
   231
  the original axiomatization of @{thm disjE}.
wenzelm@30056
   232
wenzelm@30056
   233
  \medskip We continue propositional logic by introducing absurdity
wenzelm@30056
   234
  with its characteristic elimination.  Plain truth may then be
wenzelm@30056
   235
  defined as a proposition that is trivially true.
wenzelm@30056
   236
*}
wenzelm@30056
   237
wenzelm@30056
   238
axiomatization
wenzelm@30056
   239
  false :: o  ("\<bottom>") where
wenzelm@30056
   240
  falseE [elim]: "\<bottom> \<Longrightarrow> A"
wenzelm@30056
   241
wenzelm@30056
   242
definition
wenzelm@30056
   243
  true :: o  ("\<top>") where
wenzelm@30056
   244
  "\<top> \<equiv> \<bottom> \<longrightarrow> \<bottom>"
wenzelm@30056
   245
wenzelm@30056
   246
theorem trueI [intro]: \<top>
wenzelm@30056
   247
  unfolding true_def ..
wenzelm@30056
   248
wenzelm@30056
   249
text {*
wenzelm@30058
   250
  \medskip\noindent Now negation represents an implication towards
wenzelm@30058
   251
  absurdity:
wenzelm@30056
   252
*}
wenzelm@30056
   253
wenzelm@30056
   254
definition
wenzelm@30056
   255
  not :: "o \<Rightarrow> o"  ("\<not> _" [40] 40) where
wenzelm@30056
   256
  "\<not> A \<equiv> A \<longrightarrow> \<bottom>"
wenzelm@30056
   257
wenzelm@30056
   258
theorem notI [intro]:
wenzelm@30056
   259
  assumes "A \<Longrightarrow> \<bottom>"
wenzelm@30056
   260
  shows "\<not> A"
wenzelm@30056
   261
unfolding not_def
wenzelm@30056
   262
proof
wenzelm@30056
   263
  assume A
wenzelm@30056
   264
  then show \<bottom> by (rule `A \<Longrightarrow> \<bottom>`)
wenzelm@30056
   265
qed
wenzelm@30056
   266
wenzelm@30056
   267
theorem notE [elim]:
wenzelm@30056
   268
  assumes "\<not> A" and A
wenzelm@30056
   269
  shows B
wenzelm@30056
   270
proof -
wenzelm@30056
   271
  from `\<not> A` have "A \<longrightarrow> \<bottom>" unfolding not_def .
wenzelm@30056
   272
  from `A \<longrightarrow> \<bottom>` and `A` have \<bottom> ..
wenzelm@30056
   273
  then show B ..
wenzelm@30056
   274
qed
wenzelm@30056
   275
wenzelm@30056
   276
wenzelm@30056
   277
subsection {* Classical logic *}
wenzelm@30056
   278
wenzelm@30056
   279
text {*
wenzelm@30056
   280
  Subsequently we state the principle of classical contradiction as a
wenzelm@30056
   281
  local assumption.  Thus we refrain from forcing the object-logic
wenzelm@30056
   282
  into the classical perspective.  Within that context, we may derive
wenzelm@30056
   283
  well-known consequences of the classical principle.
wenzelm@30056
   284
*}
wenzelm@30056
   285
wenzelm@30056
   286
locale classical =
wenzelm@30056
   287
  assumes classical: "(\<not> C \<Longrightarrow> C) \<Longrightarrow> C"
wenzelm@30056
   288
begin
wenzelm@30056
   289
wenzelm@30056
   290
theorem double_negation:
wenzelm@30056
   291
  assumes "\<not> \<not> C"
wenzelm@30056
   292
  shows C
wenzelm@30056
   293
proof (rule classical)
wenzelm@30056
   294
  assume "\<not> C"
wenzelm@30056
   295
  with `\<not> \<not> C` show C ..
wenzelm@30056
   296
qed
wenzelm@30056
   297
wenzelm@30056
   298
theorem tertium_non_datur: "C \<or> \<not> C"
wenzelm@30056
   299
proof (rule double_negation)
wenzelm@30056
   300
  show "\<not> \<not> (C \<or> \<not> C)"
wenzelm@30056
   301
  proof
wenzelm@30056
   302
    assume "\<not> (C \<or> \<not> C)"
wenzelm@30056
   303
    have "\<not> C"
wenzelm@30056
   304
    proof
wenzelm@30056
   305
      assume C then have "C \<or> \<not> C" ..
wenzelm@30056
   306
      with `\<not> (C \<or> \<not> C)` show \<bottom> ..
wenzelm@30056
   307
    qed
wenzelm@30056
   308
    then have "C \<or> \<not> C" ..
wenzelm@30056
   309
    with `\<not> (C \<or> \<not> C)` show \<bottom> ..
wenzelm@30056
   310
  qed
wenzelm@30056
   311
qed
wenzelm@30056
   312
wenzelm@30056
   313
text {*
wenzelm@30061
   314
  \noindent These examples illustrate both classical reasoning and
wenzelm@30061
   315
  non-trivial propositional proofs in general.  All three rules
wenzelm@30061
   316
  characterize classical logic independently, but the original rule is
wenzelm@30061
   317
  already the most convenient to use, because it leaves the conclusion
wenzelm@30061
   318
  unchanged.  Note that @{prop "(\<not> C \<Longrightarrow> C) \<Longrightarrow> C"} fits again into our
wenzelm@30061
   319
  format for eliminations, despite the additional twist that the
wenzelm@30061
   320
  context refers to the main conclusion.  So we may write @{thm
wenzelm@30061
   321
  classical} as the Isar statement ``@{text "\<OBTAINS> \<not> thesis"}''.
wenzelm@30061
   322
  This also explains nicely how classical reasoning really works:
wenzelm@30061
   323
  whatever the main @{text thesis} might be, we may always assume its
wenzelm@30061
   324
  negation!
wenzelm@30056
   325
*}
wenzelm@30056
   326
wenzelm@30056
   327
end
wenzelm@30056
   328
wenzelm@30056
   329
wenzelm@30060
   330
subsection {* Quantifiers \label{sec:framework-ex-quant} *}
wenzelm@30056
   331
wenzelm@30056
   332
text {*
wenzelm@30056
   333
  Representing quantifiers is easy, thanks to the higher-order nature
wenzelm@30056
   334
  of the underlying framework.  According to the well-known technique
wenzelm@30056
   335
  introduced by Church \cite{church40}, quantifiers are operators on
wenzelm@30056
   336
  predicates, which are syntactically represented as @{text "\<lambda>"}-terms
wenzelm@30058
   337
  of type @{typ "i \<Rightarrow> o"}.  Binder notation turns @{text "All (\<lambda>x. B
wenzelm@30058
   338
  x)"} into @{text "\<forall>x. B x"} etc.
wenzelm@30056
   339
*}
wenzelm@30056
   340
wenzelm@30056
   341
axiomatization
wenzelm@30056
   342
  All :: "(i \<Rightarrow> o) \<Rightarrow> o"  (binder "\<forall>" 10) where
wenzelm@30056
   343
  allI [intro]: "(\<And>x. B x) \<Longrightarrow> \<forall>x. B x" and
wenzelm@30056
   344
  allD [dest]: "(\<forall>x. B x) \<Longrightarrow> B a"
wenzelm@30056
   345
wenzelm@30056
   346
axiomatization
wenzelm@30056
   347
  Ex :: "(i \<Rightarrow> o) \<Rightarrow> o"  (binder "\<exists>" 10) where
wenzelm@30056
   348
  exI [intro]: "B a \<Longrightarrow> (\<exists>x. B x)" and
wenzelm@30056
   349
  exE [elim]: "(\<exists>x. B x) \<Longrightarrow> (\<And>x. B x \<Longrightarrow> C) \<Longrightarrow> C"
wenzelm@30056
   350
wenzelm@30056
   351
text {*
wenzelm@30061
   352
  \noindent The statement of @{thm exE} corresponds to ``@{text
wenzelm@30061
   353
  "\<ASSUMES> \<exists>x. B x \<OBTAINS> x \<WHERE> B x"}'' in Isar.  In the
wenzelm@30061
   354
  subsequent example we illustrate quantifier reasoning involving all
wenzelm@30061
   355
  four rules:
wenzelm@30056
   356
*}
wenzelm@30056
   357
wenzelm@30056
   358
theorem
wenzelm@30056
   359
  assumes "\<exists>x. \<forall>y. R x y"
wenzelm@30056
   360
  shows "\<forall>y. \<exists>x. R x y"
wenzelm@30056
   361
proof    -- {* @{text "\<forall>"} introduction *}
wenzelm@30056
   362
  obtain x where "\<forall>y. R x y" using `\<exists>x. \<forall>y. R x y` ..    -- {* @{text "\<exists>"} elimination *}
wenzelm@30056
   363
  fix y have "R x y" using `\<forall>y. R x y` ..    -- {* @{text "\<forall>"} destruction *}
wenzelm@30056
   364
  then show "\<exists>x. R x y" ..    -- {* @{text "\<exists>"} introduction *}
wenzelm@30056
   365
qed
wenzelm@30056
   366
wenzelm@30060
   367
wenzelm@30060
   368
subsection {* Canonical reasoning patterns *}
wenzelm@30060
   369
wenzelm@30060
   370
text {*
wenzelm@30060
   371
  The main rules of first-order predicate logic from
wenzelm@30060
   372
  \secref{sec:framework-ex-prop} and \secref{sec:framework-ex-quant}
wenzelm@30060
   373
  can now be summarized as follows, using the native Isar statement
wenzelm@30060
   374
  format of \secref{sec:framework-stmt}.
wenzelm@30060
   375
wenzelm@30060
   376
  \medskip
wenzelm@30060
   377
  \begin{tabular}{l}
wenzelm@30060
   378
  @{text "impI: \<ASSUMES> A \<Longrightarrow> B \<SHOWS> A \<longrightarrow> B"} \\
wenzelm@30060
   379
  @{text "impD: \<ASSUMES> A \<longrightarrow> B \<AND> A \<SHOWS> B"} \\[1ex]
wenzelm@30060
   380
wenzelm@30060
   381
  @{text "disjI\<^isub>1: \<ASSUMES> A \<SHOWS> A \<or> B"} \\
wenzelm@30060
   382
  @{text "disjI\<^isub>2: \<ASSUMES> B \<SHOWS> A \<or> B"} \\
wenzelm@30060
   383
  @{text "disjE: \<ASSUMES> A \<or> B \<OBTAINS> A \<BBAR> B"} \\[1ex]
wenzelm@30060
   384
wenzelm@30060
   385
  @{text "conjI: \<ASSUMES> A \<AND> B \<SHOWS> A \<and> B"} \\
wenzelm@30060
   386
  @{text "conjE: \<ASSUMES> A \<and> B \<OBTAINS> A \<AND> B"} \\[1ex]
wenzelm@30060
   387
wenzelm@30060
   388
  @{text "falseE: \<ASSUMES> \<bottom> \<SHOWS> A"} \\
wenzelm@30060
   389
  @{text "trueI: \<SHOWS> \<top>"} \\[1ex]
wenzelm@30060
   390
wenzelm@30060
   391
  @{text "notI: \<ASSUMES> A \<Longrightarrow> \<bottom> \<SHOWS> \<not> A"} \\
wenzelm@30060
   392
  @{text "notE: \<ASSUMES> \<not> A \<AND> A \<SHOWS> B"} \\[1ex]
wenzelm@30060
   393
wenzelm@30060
   394
  @{text "allI: \<ASSUMES> \<And>x. B x \<SHOWS> \<forall>x. B x"} \\
wenzelm@30060
   395
  @{text "allE: \<ASSUMES> \<forall>x. B x \<SHOWS> B a"} \\[1ex]
wenzelm@30060
   396
wenzelm@30060
   397
  @{text "exI: \<ASSUMES> B a \<SHOWS> \<exists>x. B x"} \\
wenzelm@30060
   398
  @{text "exE: \<ASSUMES> \<exists>x. B x \<OBTAINS> a \<WHERE> B a"}
wenzelm@30060
   399
  \end{tabular}
wenzelm@30060
   400
  \medskip
wenzelm@30060
   401
wenzelm@30060
   402
  \noindent This essentially provides a declarative reading of Pure
wenzelm@30060
   403
  rules as Isar reasoning patterns: the rule statements tells how a
wenzelm@30060
   404
  canonical proof outline shall look like.  Since the above rules have
wenzelm@30061
   405
  already been declared as @{attribute (Pure) intro}, @{attribute
wenzelm@30061
   406
  (Pure) elim}, @{attribute (Pure) dest} --- each according to its
wenzelm@30061
   407
  particular shape --- we can immediately write Isar proof texts as
wenzelm@30061
   408
  follows:
wenzelm@30060
   409
*}
wenzelm@30060
   410
wenzelm@30060
   411
(*<*)
wenzelm@30060
   412
theorem "\<And>A. PROP A \<Longrightarrow> PROP A"
wenzelm@30060
   413
proof -
wenzelm@30060
   414
(*>*)
wenzelm@30060
   415
wenzelm@30060
   416
  txt_raw {*\begin{minipage}[t]{0.4\textwidth}*}(*<*)next(*>*)
wenzelm@30060
   417
wenzelm@30060
   418
  have "A \<longrightarrow> B"
wenzelm@30060
   419
  proof
wenzelm@30060
   420
    assume A
wenzelm@30060
   421
    show B sorry %noproof
wenzelm@30060
   422
  qed
wenzelm@30060
   423
wenzelm@30060
   424
  txt_raw {*\end{minipage}\qquad\begin{minipage}[t]{0.4\textwidth}*}(*<*)next(*>*)
wenzelm@30060
   425
wenzelm@30060
   426
  have "A \<longrightarrow> B" and A sorry %noproof
wenzelm@30060
   427
  then have B ..
wenzelm@30060
   428
wenzelm@30060
   429
  txt_raw {*\end{minipage}\\[3ex]\begin{minipage}[t]{0.4\textwidth}*}(*<*)next(*>*)
wenzelm@30060
   430
wenzelm@30060
   431
  have A sorry %noproof
wenzelm@30060
   432
  then have "A \<or> B" ..
wenzelm@30060
   433
wenzelm@30060
   434
  have B sorry %noproof
wenzelm@30060
   435
  then have "A \<or> B" ..
wenzelm@30060
   436
wenzelm@30060
   437
  txt_raw {*\end{minipage}\qquad\begin{minipage}[t]{0.4\textwidth}*}(*<*)next(*>*)
wenzelm@30060
   438
wenzelm@30060
   439
  have "A \<or> B" sorry %noproof
wenzelm@30060
   440
  then have C
wenzelm@30060
   441
  proof
wenzelm@30060
   442
    assume A
wenzelm@30060
   443
    then show C sorry %noproof
wenzelm@30060
   444
  next
wenzelm@30060
   445
    assume B
wenzelm@30060
   446
    then show C sorry %noproof
wenzelm@30060
   447
  qed
wenzelm@30060
   448
wenzelm@30060
   449
  txt_raw {*\end{minipage}\\[3ex]\begin{minipage}[t]{0.4\textwidth}*}(*<*)next(*>*)
wenzelm@30060
   450
wenzelm@30060
   451
  have A and B sorry %noproof
wenzelm@30060
   452
  then have "A \<and> B" ..
wenzelm@30060
   453
wenzelm@30060
   454
  txt_raw {*\end{minipage}\qquad\begin{minipage}[t]{0.4\textwidth}*}(*<*)next(*>*)
wenzelm@30060
   455
wenzelm@30060
   456
  have "A \<and> B" sorry %noproof
wenzelm@30060
   457
  then obtain A and B ..
wenzelm@30060
   458
wenzelm@30060
   459
  txt_raw {*\end{minipage}\\[3ex]\begin{minipage}[t]{0.4\textwidth}*}(*<*)next(*>*)
wenzelm@30060
   460
wenzelm@30060
   461
  have "\<bottom>" sorry %noproof
wenzelm@30060
   462
  then have A ..
wenzelm@30060
   463
wenzelm@30060
   464
  txt_raw {*\end{minipage}\qquad\begin{minipage}[t]{0.4\textwidth}*}(*<*)next(*>*)
wenzelm@30060
   465
wenzelm@30060
   466
  have "\<top>" ..
wenzelm@30060
   467
wenzelm@30060
   468
  txt_raw {*\end{minipage}\\[3ex]\begin{minipage}[t]{0.4\textwidth}*}(*<*)next(*>*)
wenzelm@30060
   469
wenzelm@30060
   470
  have "\<not> A"
wenzelm@30060
   471
  proof
wenzelm@30060
   472
    assume A
wenzelm@30060
   473
    then show "\<bottom>" sorry %noproof
wenzelm@30060
   474
  qed
wenzelm@30060
   475
wenzelm@30060
   476
  txt_raw {*\end{minipage}\qquad\begin{minipage}[t]{0.4\textwidth}*}(*<*)next(*>*)
wenzelm@30060
   477
wenzelm@30060
   478
  have "\<not> A" and A sorry %noproof
wenzelm@30060
   479
  then have B ..
wenzelm@30060
   480
wenzelm@30060
   481
  txt_raw {*\end{minipage}\\[3ex]\begin{minipage}[t]{0.4\textwidth}*}(*<*)next(*>*)
wenzelm@30060
   482
wenzelm@30060
   483
  have "\<forall>x. B x"
wenzelm@30060
   484
  proof
wenzelm@30060
   485
    fix x
wenzelm@30060
   486
    show "B x" sorry %noproof
wenzelm@30060
   487
  qed
wenzelm@30060
   488
wenzelm@30060
   489
  txt_raw {*\end{minipage}\qquad\begin{minipage}[t]{0.4\textwidth}*}(*<*)next(*>*)
wenzelm@30060
   490
wenzelm@30060
   491
  have "\<forall>x. B x" sorry %noproof
wenzelm@30060
   492
  then have "B a" ..
wenzelm@30060
   493
wenzelm@30060
   494
  txt_raw {*\end{minipage}\\[3ex]\begin{minipage}[t]{0.4\textwidth}*}(*<*)next(*>*)
wenzelm@30060
   495
wenzelm@30060
   496
  have "\<exists>x. B x"
wenzelm@30060
   497
  proof
wenzelm@30060
   498
    show "B a" sorry %noproof
wenzelm@30060
   499
  qed
wenzelm@30060
   500
wenzelm@30060
   501
  txt_raw {*\end{minipage}\qquad\begin{minipage}[t]{0.4\textwidth}*}(*<*)next(*>*)
wenzelm@30060
   502
wenzelm@30060
   503
  have "\<exists>x. B x" sorry %noproof
wenzelm@30060
   504
  then obtain a where "B a" ..
wenzelm@30060
   505
wenzelm@30060
   506
  txt_raw {*\end{minipage}*}
wenzelm@30060
   507
wenzelm@30060
   508
(*<*)
wenzelm@30060
   509
qed
wenzelm@30060
   510
(*>*)
wenzelm@30060
   511
wenzelm@30060
   512
text {*
wenzelm@30060
   513
  \bigskip\noindent Of course, these proofs are merely examples.  As
wenzelm@30060
   514
  sketched in \secref{sec:framework-subproof}, there is a fair amount
wenzelm@30060
   515
  of flexibility in expressing Pure deductions in Isar.  Here the user
wenzelm@30060
   516
  is asked to express himself adequately, aiming at proof texts of
wenzelm@30060
   517
  literary quality.
wenzelm@30060
   518
*}
wenzelm@30060
   519
wenzelm@30056
   520
end %visible