src/FOL/IFOL.thy
author haftmann
Fri Jun 17 16:12:49 2005 +0200 (2005-06-17)
changeset 16417 9bc16273c2d4
parent 16121 a80aa66d2271
child 17276 3bb24e8b2cb2
permissions -rw-r--r--
migrated theory headers to new format
clasohm@1268
     1
(*  Title:      FOL/IFOL.thy
lcp@35
     2
    ID:         $Id$
wenzelm@11677
     3
    Author:     Lawrence C Paulson and Markus Wenzel
wenzelm@11677
     4
*)
lcp@35
     5
wenzelm@11677
     6
header {* Intuitionistic first-order logic *}
lcp@35
     7
paulson@15481
     8
theory IFOL
paulson@15481
     9
imports Pure
haftmann@16417
    10
uses ("IFOL_lemmas.ML") ("fologic.ML") ("hypsubstdata.ML") ("intprover.ML")
paulson@15481
    11
begin
wenzelm@7355
    12
clasohm@0
    13
wenzelm@11677
    14
subsection {* Syntax and axiomatic basis *}
wenzelm@11677
    15
wenzelm@3906
    16
global
wenzelm@3906
    17
wenzelm@14854
    18
classes "term"
wenzelm@7355
    19
defaultsort "term"
clasohm@0
    20
wenzelm@7355
    21
typedecl o
wenzelm@79
    22
wenzelm@11747
    23
judgment
wenzelm@11747
    24
  Trueprop      :: "o => prop"                  ("(_)" 5)
clasohm@0
    25
wenzelm@11747
    26
consts
wenzelm@7355
    27
  True          :: o
wenzelm@7355
    28
  False         :: o
wenzelm@79
    29
wenzelm@79
    30
  (* Connectives *)
wenzelm@79
    31
wenzelm@7355
    32
  "="           :: "['a, 'a] => o"              (infixl 50)
lcp@35
    33
wenzelm@7355
    34
  Not           :: "o => o"                     ("~ _" [40] 40)
wenzelm@7355
    35
  &             :: "[o, o] => o"                (infixr 35)
wenzelm@7355
    36
  "|"           :: "[o, o] => o"                (infixr 30)
wenzelm@7355
    37
  -->           :: "[o, o] => o"                (infixr 25)
wenzelm@7355
    38
  <->           :: "[o, o] => o"                (infixr 25)
wenzelm@79
    39
wenzelm@79
    40
  (* Quantifiers *)
wenzelm@79
    41
wenzelm@7355
    42
  All           :: "('a => o) => o"             (binder "ALL " 10)
wenzelm@7355
    43
  Ex            :: "('a => o) => o"             (binder "EX " 10)
wenzelm@7355
    44
  Ex1           :: "('a => o) => o"             (binder "EX! " 10)
wenzelm@79
    45
clasohm@0
    46
lcp@928
    47
syntax
wenzelm@12662
    48
  "_not_equal"  :: "['a, 'a] => o"              (infixl "~=" 50)
lcp@35
    49
translations
wenzelm@79
    50
  "x ~= y"      == "~ (x = y)"
wenzelm@79
    51
wenzelm@12114
    52
syntax (xsymbols)
wenzelm@11677
    53
  Not           :: "o => o"                     ("\<not> _" [40] 40)
wenzelm@11677
    54
  "op &"        :: "[o, o] => o"                (infixr "\<and>" 35)
wenzelm@11677
    55
  "op |"        :: "[o, o] => o"                (infixr "\<or>" 30)
wenzelm@11677
    56
  "ALL "        :: "[idts, o] => o"             ("(3\<forall>_./ _)" [0, 10] 10)
wenzelm@11677
    57
  "EX "         :: "[idts, o] => o"             ("(3\<exists>_./ _)" [0, 10] 10)
wenzelm@11677
    58
  "EX! "        :: "[idts, o] => o"             ("(3\<exists>!_./ _)" [0, 10] 10)
wenzelm@12662
    59
  "_not_equal"  :: "['a, 'a] => o"              (infixl "\<noteq>" 50)
wenzelm@11677
    60
  "op -->"      :: "[o, o] => o"                (infixr "\<longrightarrow>" 25)
wenzelm@11677
    61
  "op <->"      :: "[o, o] => o"                (infixr "\<longleftrightarrow>" 25)
lcp@35
    62
wenzelm@6340
    63
syntax (HTML output)
wenzelm@11677
    64
  Not           :: "o => o"                     ("\<not> _" [40] 40)
kleing@14565
    65
  "op &"        :: "[o, o] => o"                (infixr "\<and>" 35)
kleing@14565
    66
  "op |"        :: "[o, o] => o"                (infixr "\<or>" 30)
kleing@14565
    67
  "ALL "        :: "[idts, o] => o"             ("(3\<forall>_./ _)" [0, 10] 10)
kleing@14565
    68
  "EX "         :: "[idts, o] => o"             ("(3\<exists>_./ _)" [0, 10] 10)
kleing@14565
    69
  "EX! "        :: "[idts, o] => o"             ("(3\<exists>!_./ _)" [0, 10] 10)
kleing@14565
    70
  "_not_equal"  :: "['a, 'a] => o"              (infixl "\<noteq>" 50)
wenzelm@6340
    71
wenzelm@6340
    72
wenzelm@3932
    73
local
wenzelm@3906
    74
paulson@14236
    75
finalconsts
paulson@14236
    76
  False All Ex
paulson@14236
    77
  "op ="
paulson@14236
    78
  "op &"
paulson@14236
    79
  "op |"
paulson@14236
    80
  "op -->"
paulson@14236
    81
wenzelm@7355
    82
axioms
clasohm@0
    83
wenzelm@79
    84
  (* Equality *)
clasohm@0
    85
wenzelm@7355
    86
  refl:         "a=a"
clasohm@0
    87
wenzelm@79
    88
  (* Propositional logic *)
clasohm@0
    89
wenzelm@7355
    90
  conjI:        "[| P;  Q |] ==> P&Q"
wenzelm@7355
    91
  conjunct1:    "P&Q ==> P"
wenzelm@7355
    92
  conjunct2:    "P&Q ==> Q"
clasohm@0
    93
wenzelm@7355
    94
  disjI1:       "P ==> P|Q"
wenzelm@7355
    95
  disjI2:       "Q ==> P|Q"
wenzelm@7355
    96
  disjE:        "[| P|Q;  P ==> R;  Q ==> R |] ==> R"
clasohm@0
    97
wenzelm@7355
    98
  impI:         "(P ==> Q) ==> P-->Q"
wenzelm@7355
    99
  mp:           "[| P-->Q;  P |] ==> Q"
clasohm@0
   100
wenzelm@7355
   101
  FalseE:       "False ==> P"
wenzelm@7355
   102
wenzelm@79
   103
  (* Quantifiers *)
clasohm@0
   104
wenzelm@7355
   105
  allI:         "(!!x. P(x)) ==> (ALL x. P(x))"
wenzelm@7355
   106
  spec:         "(ALL x. P(x)) ==> P(x)"
clasohm@0
   107
wenzelm@7355
   108
  exI:          "P(x) ==> (EX x. P(x))"
wenzelm@7355
   109
  exE:          "[| EX x. P(x);  !!x. P(x) ==> R |] ==> R"
clasohm@0
   110
clasohm@0
   111
  (* Reflection *)
clasohm@0
   112
wenzelm@7355
   113
  eq_reflection:  "(x=y)   ==> (x==y)"
wenzelm@7355
   114
  iff_reflection: "(P<->Q) ==> (P==Q)"
clasohm@0
   115
wenzelm@4092
   116
paulson@15377
   117
text{*Thanks to Stephan Merz*}
paulson@15377
   118
theorem subst:
paulson@15377
   119
  assumes eq: "a = b" and p: "P(a)"
paulson@15377
   120
  shows "P(b)"
paulson@15377
   121
proof -
paulson@15377
   122
  from eq have meta: "a \<equiv> b"
paulson@15377
   123
    by (rule eq_reflection)
paulson@15377
   124
  from p show ?thesis
paulson@15377
   125
    by (unfold meta)
paulson@15377
   126
qed
paulson@15377
   127
paulson@15377
   128
paulson@14236
   129
defs
paulson@14236
   130
  (* Definitions *)
paulson@14236
   131
paulson@14236
   132
  True_def:     "True  == False-->False"
paulson@14236
   133
  not_def:      "~P    == P-->False"
paulson@14236
   134
  iff_def:      "P<->Q == (P-->Q) & (Q-->P)"
paulson@14236
   135
paulson@14236
   136
  (* Unique existence *)
paulson@14236
   137
paulson@14236
   138
  ex1_def:      "Ex1(P) == EX x. P(x) & (ALL y. P(y) --> y=x)"
paulson@14236
   139
paulson@13779
   140
wenzelm@11677
   141
subsection {* Lemmas and proof tools *}
wenzelm@11677
   142
wenzelm@9886
   143
use "IFOL_lemmas.ML"
wenzelm@11734
   144
wenzelm@7355
   145
use "fologic.ML"
wenzelm@9886
   146
use "hypsubstdata.ML"
wenzelm@9886
   147
setup hypsubst_setup
wenzelm@7355
   148
use "intprover.ML"
wenzelm@7355
   149
wenzelm@4092
   150
wenzelm@12875
   151
subsection {* Intuitionistic Reasoning *}
wenzelm@12368
   152
wenzelm@12349
   153
lemma impE':
wenzelm@12937
   154
  assumes 1: "P --> Q"
wenzelm@12937
   155
    and 2: "Q ==> R"
wenzelm@12937
   156
    and 3: "P --> Q ==> P"
wenzelm@12937
   157
  shows R
wenzelm@12349
   158
proof -
wenzelm@12349
   159
  from 3 and 1 have P .
wenzelm@12368
   160
  with 1 have Q by (rule impE)
wenzelm@12349
   161
  with 2 show R .
wenzelm@12349
   162
qed
wenzelm@12349
   163
wenzelm@12349
   164
lemma allE':
wenzelm@12937
   165
  assumes 1: "ALL x. P(x)"
wenzelm@12937
   166
    and 2: "P(x) ==> ALL x. P(x) ==> Q"
wenzelm@12937
   167
  shows Q
wenzelm@12349
   168
proof -
wenzelm@12349
   169
  from 1 have "P(x)" by (rule spec)
wenzelm@12349
   170
  from this and 1 show Q by (rule 2)
wenzelm@12349
   171
qed
wenzelm@12349
   172
wenzelm@12937
   173
lemma notE':
wenzelm@12937
   174
  assumes 1: "~ P"
wenzelm@12937
   175
    and 2: "~ P ==> P"
wenzelm@12937
   176
  shows R
wenzelm@12349
   177
proof -
wenzelm@12349
   178
  from 2 and 1 have P .
wenzelm@12349
   179
  with 1 show R by (rule notE)
wenzelm@12349
   180
qed
wenzelm@12349
   181
wenzelm@12349
   182
lemmas [Pure.elim!] = disjE iffE FalseE conjE exE
wenzelm@12349
   183
  and [Pure.intro!] = iffI conjI impI TrueI notI allI refl
wenzelm@12349
   184
  and [Pure.elim 2] = allE notE' impE'
wenzelm@12349
   185
  and [Pure.intro] = exI disjI2 disjI1
wenzelm@12349
   186
wenzelm@16121
   187
setup {*
wenzelm@16121
   188
  [ContextRules.addSWrapper (fn tac => hyp_subst_tac ORELSE' tac)]
wenzelm@12349
   189
*}
wenzelm@12349
   190
wenzelm@12349
   191
wenzelm@12368
   192
lemma iff_not_sym: "~ (Q <-> P) ==> ~ (P <-> Q)"
wenzelm@12368
   193
  by rules
wenzelm@12368
   194
wenzelm@12368
   195
lemmas [sym] = sym iff_sym not_sym iff_not_sym
wenzelm@12368
   196
  and [Pure.elim?] = iffD1 iffD2 impE
wenzelm@12368
   197
wenzelm@12368
   198
paulson@13435
   199
lemma eq_commute: "a=b <-> b=a"
paulson@13435
   200
apply (rule iffI) 
paulson@13435
   201
apply (erule sym)+
paulson@13435
   202
done
paulson@13435
   203
paulson@13435
   204
wenzelm@11677
   205
subsection {* Atomizing meta-level rules *}
wenzelm@11677
   206
wenzelm@11747
   207
lemma atomize_all [atomize]: "(!!x. P(x)) == Trueprop (ALL x. P(x))"
wenzelm@11976
   208
proof
wenzelm@11677
   209
  assume "!!x. P(x)"
wenzelm@12368
   210
  show "ALL x. P(x)" ..
wenzelm@11677
   211
next
wenzelm@11677
   212
  assume "ALL x. P(x)"
wenzelm@12368
   213
  thus "!!x. P(x)" ..
wenzelm@11677
   214
qed
wenzelm@11677
   215
wenzelm@11747
   216
lemma atomize_imp [atomize]: "(A ==> B) == Trueprop (A --> B)"
wenzelm@11976
   217
proof
wenzelm@12368
   218
  assume "A ==> B"
wenzelm@12368
   219
  thus "A --> B" ..
wenzelm@11677
   220
next
wenzelm@11677
   221
  assume "A --> B" and A
wenzelm@11677
   222
  thus B by (rule mp)
wenzelm@11677
   223
qed
wenzelm@11677
   224
wenzelm@11747
   225
lemma atomize_eq [atomize]: "(x == y) == Trueprop (x = y)"
wenzelm@11976
   226
proof
wenzelm@11677
   227
  assume "x == y"
wenzelm@11677
   228
  show "x = y" by (unfold prems) (rule refl)
wenzelm@11677
   229
next
wenzelm@11677
   230
  assume "x = y"
wenzelm@11677
   231
  thus "x == y" by (rule eq_reflection)
wenzelm@11677
   232
qed
wenzelm@11677
   233
wenzelm@12875
   234
lemma atomize_conj [atomize]:
wenzelm@12875
   235
  "(!!C. (A ==> B ==> PROP C) ==> PROP C) == Trueprop (A & B)"
wenzelm@11976
   236
proof
wenzelm@11953
   237
  assume "!!C. (A ==> B ==> PROP C) ==> PROP C"
wenzelm@11953
   238
  show "A & B" by (rule conjI)
wenzelm@11953
   239
next
wenzelm@11953
   240
  fix C
wenzelm@11953
   241
  assume "A & B"
wenzelm@11953
   242
  assume "A ==> B ==> PROP C"
wenzelm@11953
   243
  thus "PROP C"
wenzelm@11953
   244
  proof this
wenzelm@11953
   245
    show A by (rule conjunct1)
wenzelm@11953
   246
    show B by (rule conjunct2)
wenzelm@11953
   247
  qed
wenzelm@11953
   248
qed
wenzelm@11953
   249
wenzelm@12368
   250
lemmas [symmetric, rulify] = atomize_all atomize_imp
wenzelm@11771
   251
wenzelm@11848
   252
wenzelm@11848
   253
subsection {* Calculational rules *}
wenzelm@11848
   254
wenzelm@11848
   255
lemma forw_subst: "a = b ==> P(b) ==> P(a)"
wenzelm@11848
   256
  by (rule ssubst)
wenzelm@11848
   257
wenzelm@11848
   258
lemma back_subst: "P(a) ==> a = b ==> P(b)"
wenzelm@11848
   259
  by (rule subst)
wenzelm@11848
   260
wenzelm@11848
   261
text {*
wenzelm@11848
   262
  Note that this list of rules is in reverse order of priorities.
wenzelm@11848
   263
*}
wenzelm@11848
   264
wenzelm@12019
   265
lemmas basic_trans_rules [trans] =
wenzelm@11848
   266
  forw_subst
wenzelm@11848
   267
  back_subst
wenzelm@11848
   268
  rev_mp
wenzelm@11848
   269
  mp
wenzelm@11848
   270
  trans
wenzelm@11848
   271
paulson@13779
   272
subsection {* ``Let'' declarations *}
paulson@13779
   273
paulson@13779
   274
nonterminals letbinds letbind
paulson@13779
   275
paulson@13779
   276
constdefs
wenzelm@14854
   277
  Let :: "['a::{}, 'a => 'b] => ('b::{})"
paulson@13779
   278
    "Let(s, f) == f(s)"
paulson@13779
   279
paulson@13779
   280
syntax
paulson@13779
   281
  "_bind"       :: "[pttrn, 'a] => letbind"           ("(2_ =/ _)" 10)
paulson@13779
   282
  ""            :: "letbind => letbinds"              ("_")
paulson@13779
   283
  "_binds"      :: "[letbind, letbinds] => letbinds"  ("_;/ _")
paulson@13779
   284
  "_Let"        :: "[letbinds, 'a] => 'a"             ("(let (_)/ in (_))" 10)
paulson@13779
   285
paulson@13779
   286
translations
paulson@13779
   287
  "_Let(_binds(b, bs), e)"  == "_Let(b, _Let(bs, e))"
paulson@13779
   288
  "let x = a in e"          == "Let(a, %x. e)"
paulson@13779
   289
paulson@13779
   290
paulson@13779
   291
lemma LetI: 
paulson@13779
   292
    assumes prem: "(!!x. x=t ==> P(u(x)))"
paulson@13779
   293
    shows "P(let x=t in u(x))"
paulson@13779
   294
apply (unfold Let_def)
paulson@13779
   295
apply (rule refl [THEN prem])
paulson@13779
   296
done
paulson@13779
   297
paulson@13779
   298
ML
paulson@13779
   299
{*
paulson@13779
   300
val Let_def = thm "Let_def";
paulson@13779
   301
val LetI = thm "LetI";
paulson@13779
   302
*}
paulson@13779
   303
wenzelm@4854
   304
end