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