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