src/HOL/ex/Higher_Order_Logic.thy
author wenzelm
Wed Dec 05 20:58:00 2001 +0100 (2001-12-05)
changeset 12394 b20a37eb8338
parent 12360 9c156045c8f2
child 12573 6226b35c04ca
permissions -rw-r--r--
sym [sym];
wenzelm@12360
     1
(*  Title:      HOL/ex/Higher_Order_Logic.thy
wenzelm@12360
     2
    ID:         $Id$
wenzelm@12360
     3
    Author:     Gertrud Bauer and Markus Wenzel, TU Muenchen
wenzelm@12360
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
wenzelm@12360
     5
*)
wenzelm@12360
     6
wenzelm@12360
     7
header {* Foundations of HOL *}
wenzelm@12360
     8
wenzelm@12360
     9
theory Higher_Order_Logic = CPure:
wenzelm@12360
    10
wenzelm@12360
    11
text {*
wenzelm@12360
    12
  The following theory development demonstrates Higher-Order Logic
wenzelm@12360
    13
  itself, represented directly within the Pure framework of Isabelle.
wenzelm@12360
    14
  The ``HOL'' logic given here is essentially that of Gordon
wenzelm@12360
    15
  \cite{Gordon:1985:HOL}, although we prefer to present basic concepts
wenzelm@12360
    16
  in a slightly more conventional manner oriented towards plain
wenzelm@12360
    17
  Natural Deduction.
wenzelm@12360
    18
*}
wenzelm@12360
    19
wenzelm@12360
    20
wenzelm@12360
    21
subsection {* Pure Logic *}
wenzelm@12360
    22
wenzelm@12360
    23
classes type \<subseteq> logic
wenzelm@12360
    24
defaultsort type
wenzelm@12360
    25
wenzelm@12360
    26
typedecl o
wenzelm@12360
    27
arities
wenzelm@12360
    28
  o :: type
wenzelm@12360
    29
  fun :: (type, type) type
wenzelm@12360
    30
wenzelm@12360
    31
wenzelm@12360
    32
subsubsection {* Basic logical connectives *}
wenzelm@12360
    33
wenzelm@12360
    34
judgment
wenzelm@12360
    35
  Trueprop :: "o \<Rightarrow> prop"    ("_" 5)
wenzelm@12360
    36
wenzelm@12360
    37
consts
wenzelm@12360
    38
  imp :: "o \<Rightarrow> o \<Rightarrow> o"    (infixr "\<longrightarrow>" 25)
wenzelm@12360
    39
  All :: "('a \<Rightarrow> o) \<Rightarrow> o"    (binder "\<forall>" 10)
wenzelm@12360
    40
wenzelm@12360
    41
axioms
wenzelm@12360
    42
  impI [intro]: "(A \<Longrightarrow> B) \<Longrightarrow> A \<longrightarrow> B"
wenzelm@12360
    43
  impE [dest, trans]: "A \<longrightarrow> B \<Longrightarrow> A \<Longrightarrow> B"
wenzelm@12360
    44
  allI [intro]: "(\<And>x. P x) \<Longrightarrow> \<forall>x. P x"
wenzelm@12360
    45
  allE [dest]: "\<forall>x. P x \<Longrightarrow> P a"
wenzelm@12360
    46
wenzelm@12360
    47
wenzelm@12360
    48
subsubsection {* Extensional equality *}
wenzelm@12360
    49
wenzelm@12360
    50
consts
wenzelm@12360
    51
  equal :: "'a \<Rightarrow> 'a \<Rightarrow> o"   (infixl "=" 50)
wenzelm@12360
    52
wenzelm@12360
    53
axioms
wenzelm@12360
    54
  refl [intro]: "x = x"
wenzelm@12360
    55
  subst: "x = y \<Longrightarrow> P x \<Longrightarrow> P y"
wenzelm@12360
    56
  ext [intro]: "(\<And>x. f x = g x) \<Longrightarrow> f = g"
wenzelm@12360
    57
  iff [intro]: "(A \<Longrightarrow> B) \<Longrightarrow> (B \<Longrightarrow> A) \<Longrightarrow> A = B"
wenzelm@12360
    58
wenzelm@12394
    59
theorem sym [sym]: "x = y \<Longrightarrow> y = x"
wenzelm@12360
    60
proof -
wenzelm@12360
    61
  assume "x = y"
wenzelm@12360
    62
  thus "y = x" by (rule subst) (rule refl)
wenzelm@12360
    63
qed
wenzelm@12360
    64
wenzelm@12360
    65
lemma [trans]: "x = y \<Longrightarrow> P y \<Longrightarrow> P x"
wenzelm@12360
    66
  by (rule subst) (rule sym)
wenzelm@12360
    67
wenzelm@12360
    68
lemma [trans]: "P x \<Longrightarrow> x = y \<Longrightarrow> P y"
wenzelm@12360
    69
  by (rule subst)
wenzelm@12360
    70
wenzelm@12360
    71
theorem trans [trans]: "x = y \<Longrightarrow> y = z \<Longrightarrow> x = z"
wenzelm@12360
    72
  by (rule subst)
wenzelm@12360
    73
wenzelm@12360
    74
theorem iff1 [elim]: "A = B \<Longrightarrow> A \<Longrightarrow> B"
wenzelm@12360
    75
  by (rule subst)
wenzelm@12360
    76
wenzelm@12360
    77
theorem iff2 [elim]: "A = B \<Longrightarrow> B \<Longrightarrow> A"
wenzelm@12360
    78
  by (rule subst) (rule sym)
wenzelm@12360
    79
wenzelm@12360
    80
wenzelm@12360
    81
subsubsection {* Derived connectives *}
wenzelm@12360
    82
wenzelm@12360
    83
constdefs
wenzelm@12360
    84
  false :: o    ("\<bottom>")
wenzelm@12360
    85
  "\<bottom> \<equiv> \<forall>A. A"
wenzelm@12360
    86
  true :: o    ("\<top>")
wenzelm@12360
    87
  "\<top> \<equiv> \<bottom> \<longrightarrow> \<bottom>"
wenzelm@12360
    88
  not :: "o \<Rightarrow> o"     ("\<not> _" [40] 40)
wenzelm@12360
    89
  "not \<equiv> \<lambda>A. A \<longrightarrow> \<bottom>"
wenzelm@12360
    90
  conj :: "o \<Rightarrow> o \<Rightarrow> o"    (infixr "\<and>" 35)
wenzelm@12360
    91
  "conj \<equiv> \<lambda>A B. \<forall>C. (A \<longrightarrow> B \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
    92
  disj :: "o \<Rightarrow> o \<Rightarrow> o"    (infixr "\<or>" 30)
wenzelm@12360
    93
  "disj \<equiv> \<lambda>A B. \<forall>C. (A \<longrightarrow> C) \<longrightarrow> (B \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
    94
  Ex :: "('a \<Rightarrow> o) \<Rightarrow> o"    (binder "\<exists>" 10)
wenzelm@12360
    95
  "Ex \<equiv> \<lambda>P. \<forall>C. (\<forall>x. P x \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
    96
wenzelm@12360
    97
syntax
wenzelm@12360
    98
  "_not_equal" :: "'a \<Rightarrow> 'a \<Rightarrow> o"    (infixl "\<noteq>" 50)
wenzelm@12360
    99
translations
wenzelm@12360
   100
  "x \<noteq> y"  \<rightleftharpoons>  "\<not> (x = y)"
wenzelm@12360
   101
wenzelm@12360
   102
theorem falseE [elim]: "\<bottom> \<Longrightarrow> A"
wenzelm@12360
   103
proof (unfold false_def)
wenzelm@12360
   104
  assume "\<forall>A. A"
wenzelm@12360
   105
  thus A ..
wenzelm@12360
   106
qed
wenzelm@12360
   107
wenzelm@12360
   108
theorem trueI [intro]: \<top>
wenzelm@12360
   109
proof (unfold true_def)
wenzelm@12360
   110
  show "\<bottom> \<longrightarrow> \<bottom>" ..
wenzelm@12360
   111
qed
wenzelm@12360
   112
wenzelm@12360
   113
theorem notI [intro]: "(A \<Longrightarrow> \<bottom>) \<Longrightarrow> \<not> A"
wenzelm@12360
   114
proof (unfold not_def)
wenzelm@12360
   115
  assume "A \<Longrightarrow> \<bottom>"
wenzelm@12360
   116
  thus "A \<longrightarrow> \<bottom>" ..
wenzelm@12360
   117
qed
wenzelm@12360
   118
wenzelm@12360
   119
theorem notE [elim]: "\<not> A \<Longrightarrow> A \<Longrightarrow> B"
wenzelm@12360
   120
proof (unfold not_def)
wenzelm@12360
   121
  assume "A \<longrightarrow> \<bottom>"
wenzelm@12360
   122
  also assume A
wenzelm@12360
   123
  finally have \<bottom> ..
wenzelm@12360
   124
  thus B ..
wenzelm@12360
   125
qed
wenzelm@12360
   126
wenzelm@12360
   127
lemma notE': "A \<Longrightarrow> \<not> A \<Longrightarrow> B"
wenzelm@12360
   128
  by (rule notE)
wenzelm@12360
   129
wenzelm@12360
   130
lemmas contradiction = notE notE'  -- {* proof by contradiction in any order *}
wenzelm@12360
   131
wenzelm@12360
   132
theorem conjI [intro]: "A \<Longrightarrow> B \<Longrightarrow> A \<and> B"
wenzelm@12360
   133
proof (unfold conj_def)
wenzelm@12360
   134
  assume A and B
wenzelm@12360
   135
  show "\<forall>C. (A \<longrightarrow> B \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   136
  proof
wenzelm@12360
   137
    fix C show "(A \<longrightarrow> B \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   138
    proof
wenzelm@12360
   139
      assume "A \<longrightarrow> B \<longrightarrow> C"
wenzelm@12360
   140
      also have A .
wenzelm@12360
   141
      also have B .
wenzelm@12360
   142
      finally show C .
wenzelm@12360
   143
    qed
wenzelm@12360
   144
  qed
wenzelm@12360
   145
qed
wenzelm@12360
   146
wenzelm@12360
   147
theorem conjE [elim]: "A \<and> B \<Longrightarrow> (A \<Longrightarrow> B \<Longrightarrow> C) \<Longrightarrow> C"
wenzelm@12360
   148
proof (unfold conj_def)
wenzelm@12360
   149
  assume c: "\<forall>C. (A \<longrightarrow> B \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   150
  assume "A \<Longrightarrow> B \<Longrightarrow> C"
wenzelm@12360
   151
  moreover {
wenzelm@12360
   152
    from c have "(A \<longrightarrow> B \<longrightarrow> A) \<longrightarrow> A" ..
wenzelm@12360
   153
    also have "A \<longrightarrow> B \<longrightarrow> A"
wenzelm@12360
   154
    proof
wenzelm@12360
   155
      assume A
wenzelm@12360
   156
      thus "B \<longrightarrow> A" ..
wenzelm@12360
   157
    qed
wenzelm@12360
   158
    finally have A .
wenzelm@12360
   159
  } moreover {
wenzelm@12360
   160
    from c have "(A \<longrightarrow> B \<longrightarrow> B) \<longrightarrow> B" ..
wenzelm@12360
   161
    also have "A \<longrightarrow> B \<longrightarrow> B"
wenzelm@12360
   162
    proof
wenzelm@12360
   163
      show "B \<longrightarrow> B" ..
wenzelm@12360
   164
    qed
wenzelm@12360
   165
    finally have B .
wenzelm@12360
   166
  } ultimately show C .
wenzelm@12360
   167
qed
wenzelm@12360
   168
wenzelm@12360
   169
theorem disjI1 [intro]: "A \<Longrightarrow> A \<or> B"
wenzelm@12360
   170
proof (unfold disj_def)
wenzelm@12360
   171
  assume A
wenzelm@12360
   172
  show "\<forall>C. (A \<longrightarrow> C) \<longrightarrow> (B \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   173
  proof
wenzelm@12360
   174
    fix C show "(A \<longrightarrow> C) \<longrightarrow> (B \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   175
    proof
wenzelm@12360
   176
      assume "A \<longrightarrow> C"
wenzelm@12360
   177
      also have A .
wenzelm@12360
   178
      finally have C .
wenzelm@12360
   179
      thus "(B \<longrightarrow> C) \<longrightarrow> C" ..
wenzelm@12360
   180
    qed
wenzelm@12360
   181
  qed
wenzelm@12360
   182
qed
wenzelm@12360
   183
wenzelm@12360
   184
theorem disjI2 [intro]: "B \<Longrightarrow> A \<or> B"
wenzelm@12360
   185
proof (unfold disj_def)
wenzelm@12360
   186
  assume B
wenzelm@12360
   187
  show "\<forall>C. (A \<longrightarrow> C) \<longrightarrow> (B \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   188
  proof
wenzelm@12360
   189
    fix C show "(A \<longrightarrow> C) \<longrightarrow> (B \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   190
    proof
wenzelm@12360
   191
      show "(B \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   192
      proof
wenzelm@12360
   193
        assume "B \<longrightarrow> C"
wenzelm@12360
   194
        also have B .
wenzelm@12360
   195
        finally show C .
wenzelm@12360
   196
      qed
wenzelm@12360
   197
    qed
wenzelm@12360
   198
  qed
wenzelm@12360
   199
qed
wenzelm@12360
   200
wenzelm@12360
   201
theorem disjE [elim]: "A \<or> B \<Longrightarrow> (A \<Longrightarrow> C) \<Longrightarrow> (B \<Longrightarrow> C) \<Longrightarrow> C"
wenzelm@12360
   202
proof (unfold disj_def)
wenzelm@12360
   203
  assume c: "\<forall>C. (A \<longrightarrow> C) \<longrightarrow> (B \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   204
  assume r1: "A \<Longrightarrow> C" and r2: "B \<Longrightarrow> C"
wenzelm@12360
   205
  from c have "(A \<longrightarrow> C) \<longrightarrow> (B \<longrightarrow> C) \<longrightarrow> C" ..
wenzelm@12360
   206
  also have "A \<longrightarrow> C"
wenzelm@12360
   207
  proof
wenzelm@12360
   208
    assume A thus C by (rule r1)
wenzelm@12360
   209
  qed
wenzelm@12360
   210
  also have "B \<longrightarrow> C"
wenzelm@12360
   211
  proof
wenzelm@12360
   212
    assume B thus C by (rule r2)
wenzelm@12360
   213
  qed
wenzelm@12360
   214
  finally show C .
wenzelm@12360
   215
qed
wenzelm@12360
   216
wenzelm@12360
   217
theorem exI [intro]: "P a \<Longrightarrow> \<exists>x. P x"
wenzelm@12360
   218
proof (unfold Ex_def)
wenzelm@12360
   219
  assume "P a"
wenzelm@12360
   220
  show "\<forall>C. (\<forall>x. P x \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   221
  proof
wenzelm@12360
   222
    fix C show "(\<forall>x. P x \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   223
    proof
wenzelm@12360
   224
      assume "\<forall>x. P x \<longrightarrow> C"
wenzelm@12360
   225
      hence "P a \<longrightarrow> C" ..
wenzelm@12360
   226
      also have "P a" .
wenzelm@12360
   227
      finally show C .
wenzelm@12360
   228
    qed
wenzelm@12360
   229
  qed
wenzelm@12360
   230
qed
wenzelm@12360
   231
wenzelm@12360
   232
theorem exE [elim]: "\<exists>x. P x \<Longrightarrow> (\<And>x. P x \<Longrightarrow> C) \<Longrightarrow> C"
wenzelm@12360
   233
proof (unfold Ex_def)
wenzelm@12360
   234
  assume c: "\<forall>C. (\<forall>x. P x \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   235
  assume r: "\<And>x. P x \<Longrightarrow> C"
wenzelm@12360
   236
  from c have "(\<forall>x. P x \<longrightarrow> C) \<longrightarrow> C" ..
wenzelm@12360
   237
  also have "\<forall>x. P x \<longrightarrow> C"
wenzelm@12360
   238
  proof
wenzelm@12360
   239
    fix x show "P x \<longrightarrow> C"
wenzelm@12360
   240
    proof
wenzelm@12360
   241
      assume "P x"
wenzelm@12360
   242
      thus C by (rule r)
wenzelm@12360
   243
    qed
wenzelm@12360
   244
  qed
wenzelm@12360
   245
  finally show C .
wenzelm@12360
   246
qed
wenzelm@12360
   247
wenzelm@12360
   248
wenzelm@12360
   249
subsection {* Classical logic *}
wenzelm@12360
   250
wenzelm@12360
   251
locale classical =
wenzelm@12360
   252
  assumes classical: "(\<not> A \<Longrightarrow> A) \<Longrightarrow> A"
wenzelm@12360
   253
wenzelm@12360
   254
theorem (in classical)
wenzelm@12360
   255
  Peirce's_Law: "((A \<longrightarrow> B) \<longrightarrow> A) \<longrightarrow> A"
wenzelm@12360
   256
proof
wenzelm@12360
   257
  assume a: "(A \<longrightarrow> B) \<longrightarrow> A"
wenzelm@12360
   258
  show A
wenzelm@12360
   259
  proof (rule classical)
wenzelm@12360
   260
    assume "\<not> A"
wenzelm@12360
   261
    have "A \<longrightarrow> B"
wenzelm@12360
   262
    proof
wenzelm@12360
   263
      assume A
wenzelm@12360
   264
      thus B by (rule contradiction)
wenzelm@12360
   265
    qed
wenzelm@12360
   266
    with a show A ..
wenzelm@12360
   267
  qed
wenzelm@12360
   268
qed
wenzelm@12360
   269
wenzelm@12360
   270
theorem (in classical)
wenzelm@12360
   271
  double_negation: "\<not> \<not> A \<Longrightarrow> A"
wenzelm@12360
   272
proof -
wenzelm@12360
   273
  assume "\<not> \<not> A"
wenzelm@12360
   274
  show A
wenzelm@12360
   275
  proof (rule classical)
wenzelm@12360
   276
    assume "\<not> A"
wenzelm@12360
   277
    thus ?thesis by (rule contradiction)
wenzelm@12360
   278
  qed
wenzelm@12360
   279
qed
wenzelm@12360
   280
wenzelm@12360
   281
theorem (in classical)
wenzelm@12360
   282
  tertium_non_datur: "A \<or> \<not> A"
wenzelm@12360
   283
proof (rule double_negation)
wenzelm@12360
   284
  show "\<not> \<not> (A \<or> \<not> A)"
wenzelm@12360
   285
  proof
wenzelm@12360
   286
    assume "\<not> (A \<or> \<not> A)"
wenzelm@12360
   287
    have "\<not> A"
wenzelm@12360
   288
    proof
wenzelm@12360
   289
      assume A hence "A \<or> \<not> A" ..
wenzelm@12360
   290
      thus \<bottom> by (rule contradiction)
wenzelm@12360
   291
    qed
wenzelm@12360
   292
    hence "A \<or> \<not> A" ..
wenzelm@12360
   293
    thus \<bottom> by (rule contradiction)
wenzelm@12360
   294
  qed
wenzelm@12360
   295
qed
wenzelm@12360
   296
wenzelm@12360
   297
theorem (in classical)
wenzelm@12360
   298
  classical_cases: "(A \<Longrightarrow> C) \<Longrightarrow> (\<not> A \<Longrightarrow> C) \<Longrightarrow> C"
wenzelm@12360
   299
proof -
wenzelm@12360
   300
  assume r1: "A \<Longrightarrow> C" and r2: "\<not> A \<Longrightarrow> C"
wenzelm@12360
   301
  from tertium_non_datur show C
wenzelm@12360
   302
  proof
wenzelm@12360
   303
    assume A
wenzelm@12360
   304
    thus ?thesis by (rule r1)
wenzelm@12360
   305
  next
wenzelm@12360
   306
    assume "\<not> A"
wenzelm@12360
   307
    thus ?thesis by (rule r2)
wenzelm@12360
   308
  qed
wenzelm@12360
   309
qed
wenzelm@12360
   310
wenzelm@12360
   311
end