src/HOL/ex/Higher_Order_Logic.thy
author haftmann
Wed Mar 12 19:38:14 2008 +0100 (2008-03-12)
changeset 26265 4b63b9e9b10d
parent 23822 bfb3b1e1d766
child 26957 e3f04fdd994d
permissions -rw-r--r--
separated Random.thy from Quickcheck.thy
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@23822
    36
axiomatization
wenzelm@23822
    37
  imp :: "o \<Rightarrow> o \<Rightarrow> o"    (infixr "\<longrightarrow>" 25) and
wenzelm@12360
    38
  All :: "('a \<Rightarrow> o) \<Rightarrow> o"    (binder "\<forall>" 10)
wenzelm@23822
    39
where
wenzelm@23822
    40
  impI [intro]: "(A \<Longrightarrow> B) \<Longrightarrow> A \<longrightarrow> B" and
wenzelm@23822
    41
  impE [dest, trans]: "A \<longrightarrow> B \<Longrightarrow> A \<Longrightarrow> B" and
wenzelm@23822
    42
  allI [intro]: "(\<And>x. P x) \<Longrightarrow> \<forall>x. P x" and
wenzelm@12360
    43
  allE [dest]: "\<forall>x. P x \<Longrightarrow> P a"
wenzelm@12360
    44
wenzelm@12360
    45
wenzelm@12360
    46
subsubsection {* Extensional equality *}
wenzelm@12360
    47
wenzelm@23822
    48
axiomatization
wenzelm@12360
    49
  equal :: "'a \<Rightarrow> 'a \<Rightarrow> o"   (infixl "=" 50)
wenzelm@23822
    50
where
wenzelm@23822
    51
  refl [intro]: "x = x" and
wenzelm@23822
    52
  subst: "x = y \<Longrightarrow> P x \<Longrightarrow> P y"
wenzelm@12360
    53
wenzelm@23822
    54
axiomatization where
wenzelm@23822
    55
  ext [intro]: "(\<And>x. f x = g x) \<Longrightarrow> f = g" and
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@23373
    61
  then show "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@21404
    83
  false :: o  ("\<bottom>") where
wenzelm@12360
    84
  "\<bottom> \<equiv> \<forall>A. A"
wenzelm@21404
    85
wenzelm@21404
    86
definition
wenzelm@21404
    87
  true :: o  ("\<top>") where
wenzelm@12360
    88
  "\<top> \<equiv> \<bottom> \<longrightarrow> \<bottom>"
wenzelm@21404
    89
wenzelm@21404
    90
definition
wenzelm@21404
    91
  not :: "o \<Rightarrow> o"  ("\<not> _" [40] 40) where
wenzelm@12360
    92
  "not \<equiv> \<lambda>A. A \<longrightarrow> \<bottom>"
wenzelm@21404
    93
wenzelm@21404
    94
definition
wenzelm@21404
    95
  conj :: "o \<Rightarrow> o \<Rightarrow> o"  (infixr "\<and>" 35) where
wenzelm@12360
    96
  "conj \<equiv> \<lambda>A B. \<forall>C. (A \<longrightarrow> B \<longrightarrow> C) \<longrightarrow> C"
wenzelm@21404
    97
wenzelm@21404
    98
definition
wenzelm@21404
    99
  disj :: "o \<Rightarrow> o \<Rightarrow> o"  (infixr "\<or>" 30) where
wenzelm@12360
   100
  "disj \<equiv> \<lambda>A B. \<forall>C. (A \<longrightarrow> C) \<longrightarrow> (B \<longrightarrow> C) \<longrightarrow> C"
wenzelm@21404
   101
wenzelm@21404
   102
definition
wenzelm@21404
   103
  Ex :: "('a \<Rightarrow> o) \<Rightarrow> o"  (binder "\<exists>" 10) where
wenzelm@23822
   104
  "\<exists>x. P x \<equiv> \<forall>C. (\<forall>x. P x \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   105
wenzelm@19380
   106
abbreviation
wenzelm@21404
   107
  not_equal :: "'a \<Rightarrow> 'a \<Rightarrow> o"  (infixl "\<noteq>" 50) where
wenzelm@19380
   108
  "x \<noteq> y \<equiv> \<not> (x = y)"
wenzelm@12360
   109
wenzelm@12360
   110
theorem falseE [elim]: "\<bottom> \<Longrightarrow> A"
wenzelm@12360
   111
proof (unfold false_def)
wenzelm@12360
   112
  assume "\<forall>A. A"
wenzelm@23373
   113
  then show A ..
wenzelm@12360
   114
qed
wenzelm@12360
   115
wenzelm@12360
   116
theorem trueI [intro]: \<top>
wenzelm@12360
   117
proof (unfold true_def)
wenzelm@12360
   118
  show "\<bottom> \<longrightarrow> \<bottom>" ..
wenzelm@12360
   119
qed
wenzelm@12360
   120
wenzelm@12360
   121
theorem notI [intro]: "(A \<Longrightarrow> \<bottom>) \<Longrightarrow> \<not> A"
wenzelm@12360
   122
proof (unfold not_def)
wenzelm@12360
   123
  assume "A \<Longrightarrow> \<bottom>"
wenzelm@23373
   124
  then show "A \<longrightarrow> \<bottom>" ..
wenzelm@12360
   125
qed
wenzelm@12360
   126
wenzelm@12360
   127
theorem notE [elim]: "\<not> A \<Longrightarrow> A \<Longrightarrow> B"
wenzelm@12360
   128
proof (unfold not_def)
wenzelm@12360
   129
  assume "A \<longrightarrow> \<bottom>"
wenzelm@12360
   130
  also assume A
wenzelm@12360
   131
  finally have \<bottom> ..
wenzelm@23373
   132
  then show B ..
wenzelm@12360
   133
qed
wenzelm@12360
   134
wenzelm@12360
   135
lemma notE': "A \<Longrightarrow> \<not> A \<Longrightarrow> B"
wenzelm@12360
   136
  by (rule notE)
wenzelm@12360
   137
wenzelm@12360
   138
lemmas contradiction = notE notE'  -- {* proof by contradiction in any order *}
wenzelm@12360
   139
wenzelm@12360
   140
theorem conjI [intro]: "A \<Longrightarrow> B \<Longrightarrow> A \<and> B"
wenzelm@12360
   141
proof (unfold conj_def)
wenzelm@12360
   142
  assume A and B
wenzelm@12360
   143
  show "\<forall>C. (A \<longrightarrow> B \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   144
  proof
wenzelm@12360
   145
    fix C show "(A \<longrightarrow> B \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   146
    proof
wenzelm@12360
   147
      assume "A \<longrightarrow> B \<longrightarrow> C"
wenzelm@23373
   148
      also note `A`
wenzelm@23373
   149
      also note `B`
wenzelm@12360
   150
      finally show C .
wenzelm@12360
   151
    qed
wenzelm@12360
   152
  qed
wenzelm@12360
   153
qed
wenzelm@12360
   154
wenzelm@12360
   155
theorem conjE [elim]: "A \<and> B \<Longrightarrow> (A \<Longrightarrow> B \<Longrightarrow> C) \<Longrightarrow> C"
wenzelm@12360
   156
proof (unfold conj_def)
wenzelm@12360
   157
  assume c: "\<forall>C. (A \<longrightarrow> B \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   158
  assume "A \<Longrightarrow> B \<Longrightarrow> C"
wenzelm@12360
   159
  moreover {
wenzelm@12360
   160
    from c have "(A \<longrightarrow> B \<longrightarrow> A) \<longrightarrow> A" ..
wenzelm@12360
   161
    also have "A \<longrightarrow> B \<longrightarrow> A"
wenzelm@12360
   162
    proof
wenzelm@12360
   163
      assume A
wenzelm@23373
   164
      then show "B \<longrightarrow> A" ..
wenzelm@12360
   165
    qed
wenzelm@12360
   166
    finally have A .
wenzelm@12360
   167
  } moreover {
wenzelm@12360
   168
    from c have "(A \<longrightarrow> B \<longrightarrow> B) \<longrightarrow> B" ..
wenzelm@12360
   169
    also have "A \<longrightarrow> B \<longrightarrow> B"
wenzelm@12360
   170
    proof
wenzelm@12360
   171
      show "B \<longrightarrow> B" ..
wenzelm@12360
   172
    qed
wenzelm@12360
   173
    finally have B .
wenzelm@12360
   174
  } ultimately show C .
wenzelm@12360
   175
qed
wenzelm@12360
   176
wenzelm@12360
   177
theorem disjI1 [intro]: "A \<Longrightarrow> A \<or> B"
wenzelm@12360
   178
proof (unfold disj_def)
wenzelm@12360
   179
  assume A
wenzelm@12360
   180
  show "\<forall>C. (A \<longrightarrow> C) \<longrightarrow> (B \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   181
  proof
wenzelm@12360
   182
    fix C show "(A \<longrightarrow> C) \<longrightarrow> (B \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   183
    proof
wenzelm@12360
   184
      assume "A \<longrightarrow> C"
wenzelm@23373
   185
      also note `A`
wenzelm@12360
   186
      finally have C .
wenzelm@23373
   187
      then show "(B \<longrightarrow> C) \<longrightarrow> C" ..
wenzelm@12360
   188
    qed
wenzelm@12360
   189
  qed
wenzelm@12360
   190
qed
wenzelm@12360
   191
wenzelm@12360
   192
theorem disjI2 [intro]: "B \<Longrightarrow> A \<or> B"
wenzelm@12360
   193
proof (unfold disj_def)
wenzelm@12360
   194
  assume B
wenzelm@12360
   195
  show "\<forall>C. (A \<longrightarrow> C) \<longrightarrow> (B \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   196
  proof
wenzelm@12360
   197
    fix C show "(A \<longrightarrow> C) \<longrightarrow> (B \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   198
    proof
wenzelm@12360
   199
      show "(B \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   200
      proof
wenzelm@12360
   201
        assume "B \<longrightarrow> C"
wenzelm@23373
   202
        also note `B`
wenzelm@12360
   203
        finally show C .
wenzelm@12360
   204
      qed
wenzelm@12360
   205
    qed
wenzelm@12360
   206
  qed
wenzelm@12360
   207
qed
wenzelm@12360
   208
wenzelm@12360
   209
theorem disjE [elim]: "A \<or> B \<Longrightarrow> (A \<Longrightarrow> C) \<Longrightarrow> (B \<Longrightarrow> C) \<Longrightarrow> C"
wenzelm@12360
   210
proof (unfold disj_def)
wenzelm@12360
   211
  assume c: "\<forall>C. (A \<longrightarrow> C) \<longrightarrow> (B \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   212
  assume r1: "A \<Longrightarrow> C" and r2: "B \<Longrightarrow> C"
wenzelm@12360
   213
  from c have "(A \<longrightarrow> C) \<longrightarrow> (B \<longrightarrow> C) \<longrightarrow> C" ..
wenzelm@12360
   214
  also have "A \<longrightarrow> C"
wenzelm@12360
   215
  proof
wenzelm@23373
   216
    assume A then show C by (rule r1)
wenzelm@12360
   217
  qed
wenzelm@12360
   218
  also have "B \<longrightarrow> C"
wenzelm@12360
   219
  proof
wenzelm@23373
   220
    assume B then show C by (rule r2)
wenzelm@12360
   221
  qed
wenzelm@12360
   222
  finally show C .
wenzelm@12360
   223
qed
wenzelm@12360
   224
wenzelm@12360
   225
theorem exI [intro]: "P a \<Longrightarrow> \<exists>x. P x"
wenzelm@12360
   226
proof (unfold Ex_def)
wenzelm@12360
   227
  assume "P a"
wenzelm@12360
   228
  show "\<forall>C. (\<forall>x. P x \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   229
  proof
wenzelm@12360
   230
    fix C show "(\<forall>x. P x \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   231
    proof
wenzelm@12360
   232
      assume "\<forall>x. P x \<longrightarrow> C"
wenzelm@23373
   233
      then have "P a \<longrightarrow> C" ..
wenzelm@23373
   234
      also note `P a`
wenzelm@12360
   235
      finally show C .
wenzelm@12360
   236
    qed
wenzelm@12360
   237
  qed
wenzelm@12360
   238
qed
wenzelm@12360
   239
wenzelm@12360
   240
theorem exE [elim]: "\<exists>x. P x \<Longrightarrow> (\<And>x. P x \<Longrightarrow> C) \<Longrightarrow> C"
wenzelm@12360
   241
proof (unfold Ex_def)
wenzelm@12360
   242
  assume c: "\<forall>C. (\<forall>x. P x \<longrightarrow> C) \<longrightarrow> C"
wenzelm@12360
   243
  assume r: "\<And>x. P x \<Longrightarrow> C"
wenzelm@12360
   244
  from c have "(\<forall>x. P x \<longrightarrow> C) \<longrightarrow> C" ..
wenzelm@12360
   245
  also have "\<forall>x. P x \<longrightarrow> C"
wenzelm@12360
   246
  proof
wenzelm@12360
   247
    fix x show "P x \<longrightarrow> C"
wenzelm@12360
   248
    proof
wenzelm@12360
   249
      assume "P x"
wenzelm@23373
   250
      then show C by (rule r)
wenzelm@12360
   251
    qed
wenzelm@12360
   252
  qed
wenzelm@12360
   253
  finally show C .
wenzelm@12360
   254
qed
wenzelm@12360
   255
wenzelm@12360
   256
wenzelm@12360
   257
subsection {* Classical logic *}
wenzelm@12360
   258
wenzelm@12360
   259
locale classical =
wenzelm@12360
   260
  assumes classical: "(\<not> A \<Longrightarrow> A) \<Longrightarrow> A"
wenzelm@12360
   261
wenzelm@12360
   262
theorem (in classical)
wenzelm@12360
   263
  Peirce's_Law: "((A \<longrightarrow> B) \<longrightarrow> A) \<longrightarrow> A"
wenzelm@12360
   264
proof
wenzelm@12360
   265
  assume a: "(A \<longrightarrow> B) \<longrightarrow> A"
wenzelm@12360
   266
  show A
wenzelm@12360
   267
  proof (rule classical)
wenzelm@12360
   268
    assume "\<not> A"
wenzelm@12360
   269
    have "A \<longrightarrow> B"
wenzelm@12360
   270
    proof
wenzelm@12360
   271
      assume A
wenzelm@23373
   272
      with `\<not> A` show B by (rule contradiction)
wenzelm@12360
   273
    qed
wenzelm@12360
   274
    with a show A ..
wenzelm@12360
   275
  qed
wenzelm@12360
   276
qed
wenzelm@12360
   277
wenzelm@12360
   278
theorem (in classical)
wenzelm@12360
   279
  double_negation: "\<not> \<not> A \<Longrightarrow> A"
wenzelm@12360
   280
proof -
wenzelm@12360
   281
  assume "\<not> \<not> A"
wenzelm@12360
   282
  show A
wenzelm@12360
   283
  proof (rule classical)
wenzelm@12360
   284
    assume "\<not> A"
wenzelm@23373
   285
    with `\<not> \<not> A` show ?thesis by (rule contradiction)
wenzelm@12360
   286
  qed
wenzelm@12360
   287
qed
wenzelm@12360
   288
wenzelm@12360
   289
theorem (in classical)
wenzelm@12360
   290
  tertium_non_datur: "A \<or> \<not> A"
wenzelm@12360
   291
proof (rule double_negation)
wenzelm@12360
   292
  show "\<not> \<not> (A \<or> \<not> A)"
wenzelm@12360
   293
  proof
wenzelm@12360
   294
    assume "\<not> (A \<or> \<not> A)"
wenzelm@12360
   295
    have "\<not> A"
wenzelm@12360
   296
    proof
wenzelm@23373
   297
      assume A then have "A \<or> \<not> A" ..
wenzelm@23373
   298
      with `\<not> (A \<or> \<not> A)` show \<bottom> by (rule contradiction)
wenzelm@12360
   299
    qed
wenzelm@23373
   300
    then have "A \<or> \<not> A" ..
wenzelm@23373
   301
    with `\<not> (A \<or> \<not> A)` show \<bottom> by (rule contradiction)
wenzelm@12360
   302
  qed
wenzelm@12360
   303
qed
wenzelm@12360
   304
wenzelm@12360
   305
theorem (in classical)
wenzelm@12360
   306
  classical_cases: "(A \<Longrightarrow> C) \<Longrightarrow> (\<not> A \<Longrightarrow> C) \<Longrightarrow> C"
wenzelm@12360
   307
proof -
wenzelm@12360
   308
  assume r1: "A \<Longrightarrow> C" and r2: "\<not> A \<Longrightarrow> C"
wenzelm@12360
   309
  from tertium_non_datur show C
wenzelm@12360
   310
  proof
wenzelm@12360
   311
    assume A
wenzelm@23373
   312
    then show ?thesis by (rule r1)
wenzelm@12360
   313
  next
wenzelm@12360
   314
    assume "\<not> A"
wenzelm@23373
   315
    then show ?thesis by (rule r2)
wenzelm@12360
   316
  qed
wenzelm@12360
   317
qed
wenzelm@12360
   318
wenzelm@12573
   319
lemma (in classical) "(\<not> A \<Longrightarrow> A) \<Longrightarrow> A"  (* FIXME *)
wenzelm@12573
   320
proof -
wenzelm@12573
   321
  assume r: "\<not> A \<Longrightarrow> A"
wenzelm@12573
   322
  show A
wenzelm@12573
   323
  proof (rule classical_cases)
wenzelm@23373
   324
    assume A then show A .
wenzelm@12573
   325
  next
wenzelm@23373
   326
    assume "\<not> A" then show A by (rule r)
wenzelm@12573
   327
  qed
wenzelm@12573
   328
qed
wenzelm@12573
   329
wenzelm@12360
   330
end