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