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