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