src/FOL/IFOL.thy
author kleing
Wed Apr 14 14:13:05 2004 +0200 (2004-04-14)
changeset 14565 c6dc17aab88a
parent 14236 c73d62ce9d1c
child 14854 61bdf2ae4dc5
permissions -rw-r--r--
use more symbols in HTML output
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@7355
    16
classes "term" < logic
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"
wenzelm@7355
    85
  subst:        "[| a=b;  P(a) |] ==> P(b)"
clasohm@0
    86
wenzelm@79
    87
  (* Propositional logic *)
clasohm@0
    88
wenzelm@7355
    89
  conjI:        "[| P;  Q |] ==> P&Q"
wenzelm@7355
    90
  conjunct1:    "P&Q ==> P"
wenzelm@7355
    91
  conjunct2:    "P&Q ==> Q"
clasohm@0
    92
wenzelm@7355
    93
  disjI1:       "P ==> P|Q"
wenzelm@7355
    94
  disjI2:       "Q ==> P|Q"
wenzelm@7355
    95
  disjE:        "[| P|Q;  P ==> R;  Q ==> R |] ==> R"
clasohm@0
    96
wenzelm@7355
    97
  impI:         "(P ==> Q) ==> P-->Q"
wenzelm@7355
    98
  mp:           "[| P-->Q;  P |] ==> Q"
clasohm@0
    99
wenzelm@7355
   100
  FalseE:       "False ==> P"
wenzelm@7355
   101
wenzelm@79
   102
  (* Quantifiers *)
clasohm@0
   103
wenzelm@7355
   104
  allI:         "(!!x. P(x)) ==> (ALL x. P(x))"
wenzelm@7355
   105
  spec:         "(ALL x. P(x)) ==> P(x)"
clasohm@0
   106
wenzelm@7355
   107
  exI:          "P(x) ==> (EX x. P(x))"
wenzelm@7355
   108
  exE:          "[| EX x. P(x);  !!x. P(x) ==> R |] ==> R"
clasohm@0
   109
clasohm@0
   110
  (* Reflection *)
clasohm@0
   111
wenzelm@7355
   112
  eq_reflection:  "(x=y)   ==> (x==y)"
wenzelm@7355
   113
  iff_reflection: "(P<->Q) ==> (P==Q)"
clasohm@0
   114
wenzelm@4092
   115
paulson@14236
   116
defs
paulson@14236
   117
  (* Definitions *)
paulson@14236
   118
paulson@14236
   119
  True_def:     "True  == False-->False"
paulson@14236
   120
  not_def:      "~P    == P-->False"
paulson@14236
   121
  iff_def:      "P<->Q == (P-->Q) & (Q-->P)"
paulson@14236
   122
paulson@14236
   123
  (* Unique existence *)
paulson@14236
   124
paulson@14236
   125
  ex1_def:      "Ex1(P) == EX x. P(x) & (ALL y. P(y) --> y=x)"
paulson@14236
   126
paulson@13779
   127
wenzelm@11677
   128
subsection {* Lemmas and proof tools *}
wenzelm@11677
   129
wenzelm@9886
   130
setup Simplifier.setup
wenzelm@9886
   131
use "IFOL_lemmas.ML"
wenzelm@11734
   132
wenzelm@7355
   133
use "fologic.ML"
wenzelm@9886
   134
use "hypsubstdata.ML"
wenzelm@9886
   135
setup hypsubst_setup
wenzelm@7355
   136
use "intprover.ML"
wenzelm@7355
   137
wenzelm@4092
   138
wenzelm@12875
   139
subsection {* Intuitionistic Reasoning *}
wenzelm@12368
   140
wenzelm@12349
   141
lemma impE':
wenzelm@12937
   142
  assumes 1: "P --> Q"
wenzelm@12937
   143
    and 2: "Q ==> R"
wenzelm@12937
   144
    and 3: "P --> Q ==> P"
wenzelm@12937
   145
  shows R
wenzelm@12349
   146
proof -
wenzelm@12349
   147
  from 3 and 1 have P .
wenzelm@12368
   148
  with 1 have Q by (rule impE)
wenzelm@12349
   149
  with 2 show R .
wenzelm@12349
   150
qed
wenzelm@12349
   151
wenzelm@12349
   152
lemma allE':
wenzelm@12937
   153
  assumes 1: "ALL x. P(x)"
wenzelm@12937
   154
    and 2: "P(x) ==> ALL x. P(x) ==> Q"
wenzelm@12937
   155
  shows Q
wenzelm@12349
   156
proof -
wenzelm@12349
   157
  from 1 have "P(x)" by (rule spec)
wenzelm@12349
   158
  from this and 1 show Q by (rule 2)
wenzelm@12349
   159
qed
wenzelm@12349
   160
wenzelm@12937
   161
lemma notE':
wenzelm@12937
   162
  assumes 1: "~ P"
wenzelm@12937
   163
    and 2: "~ P ==> P"
wenzelm@12937
   164
  shows R
wenzelm@12349
   165
proof -
wenzelm@12349
   166
  from 2 and 1 have P .
wenzelm@12349
   167
  with 1 show R by (rule notE)
wenzelm@12349
   168
qed
wenzelm@12349
   169
wenzelm@12349
   170
lemmas [Pure.elim!] = disjE iffE FalseE conjE exE
wenzelm@12349
   171
  and [Pure.intro!] = iffI conjI impI TrueI notI allI refl
wenzelm@12349
   172
  and [Pure.elim 2] = allE notE' impE'
wenzelm@12349
   173
  and [Pure.intro] = exI disjI2 disjI1
wenzelm@12349
   174
wenzelm@12349
   175
ML_setup {*
wenzelm@12352
   176
  Context.>> (ContextRules.addSWrapper (fn tac => hyp_subst_tac ORELSE' tac));
wenzelm@12349
   177
*}
wenzelm@12349
   178
wenzelm@12349
   179
wenzelm@12368
   180
lemma iff_not_sym: "~ (Q <-> P) ==> ~ (P <-> Q)"
wenzelm@12368
   181
  by rules
wenzelm@12368
   182
wenzelm@12368
   183
lemmas [sym] = sym iff_sym not_sym iff_not_sym
wenzelm@12368
   184
  and [Pure.elim?] = iffD1 iffD2 impE
wenzelm@12368
   185
wenzelm@12368
   186
paulson@13435
   187
lemma eq_commute: "a=b <-> b=a"
paulson@13435
   188
apply (rule iffI) 
paulson@13435
   189
apply (erule sym)+
paulson@13435
   190
done
paulson@13435
   191
paulson@13435
   192
wenzelm@11677
   193
subsection {* Atomizing meta-level rules *}
wenzelm@11677
   194
wenzelm@11747
   195
lemma atomize_all [atomize]: "(!!x. P(x)) == Trueprop (ALL x. P(x))"
wenzelm@11976
   196
proof
wenzelm@11677
   197
  assume "!!x. P(x)"
wenzelm@12368
   198
  show "ALL x. P(x)" ..
wenzelm@11677
   199
next
wenzelm@11677
   200
  assume "ALL x. P(x)"
wenzelm@12368
   201
  thus "!!x. P(x)" ..
wenzelm@11677
   202
qed
wenzelm@11677
   203
wenzelm@11747
   204
lemma atomize_imp [atomize]: "(A ==> B) == Trueprop (A --> B)"
wenzelm@11976
   205
proof
wenzelm@12368
   206
  assume "A ==> B"
wenzelm@12368
   207
  thus "A --> B" ..
wenzelm@11677
   208
next
wenzelm@11677
   209
  assume "A --> B" and A
wenzelm@11677
   210
  thus B by (rule mp)
wenzelm@11677
   211
qed
wenzelm@11677
   212
wenzelm@11747
   213
lemma atomize_eq [atomize]: "(x == y) == Trueprop (x = y)"
wenzelm@11976
   214
proof
wenzelm@11677
   215
  assume "x == y"
wenzelm@11677
   216
  show "x = y" by (unfold prems) (rule refl)
wenzelm@11677
   217
next
wenzelm@11677
   218
  assume "x = y"
wenzelm@11677
   219
  thus "x == y" by (rule eq_reflection)
wenzelm@11677
   220
qed
wenzelm@11677
   221
wenzelm@12875
   222
lemma atomize_conj [atomize]:
wenzelm@12875
   223
  "(!!C. (A ==> B ==> PROP C) ==> PROP C) == Trueprop (A & B)"
wenzelm@11976
   224
proof
wenzelm@11953
   225
  assume "!!C. (A ==> B ==> PROP C) ==> PROP C"
wenzelm@11953
   226
  show "A & B" by (rule conjI)
wenzelm@11953
   227
next
wenzelm@11953
   228
  fix C
wenzelm@11953
   229
  assume "A & B"
wenzelm@11953
   230
  assume "A ==> B ==> PROP C"
wenzelm@11953
   231
  thus "PROP C"
wenzelm@11953
   232
  proof this
wenzelm@11953
   233
    show A by (rule conjunct1)
wenzelm@11953
   234
    show B by (rule conjunct2)
wenzelm@11953
   235
  qed
wenzelm@11953
   236
qed
wenzelm@11953
   237
wenzelm@12368
   238
lemmas [symmetric, rulify] = atomize_all atomize_imp
wenzelm@11771
   239
wenzelm@11848
   240
wenzelm@11848
   241
subsection {* Calculational rules *}
wenzelm@11848
   242
wenzelm@11848
   243
lemma forw_subst: "a = b ==> P(b) ==> P(a)"
wenzelm@11848
   244
  by (rule ssubst)
wenzelm@11848
   245
wenzelm@11848
   246
lemma back_subst: "P(a) ==> a = b ==> P(b)"
wenzelm@11848
   247
  by (rule subst)
wenzelm@11848
   248
wenzelm@11848
   249
text {*
wenzelm@11848
   250
  Note that this list of rules is in reverse order of priorities.
wenzelm@11848
   251
*}
wenzelm@11848
   252
wenzelm@12019
   253
lemmas basic_trans_rules [trans] =
wenzelm@11848
   254
  forw_subst
wenzelm@11848
   255
  back_subst
wenzelm@11848
   256
  rev_mp
wenzelm@11848
   257
  mp
wenzelm@11848
   258
  trans
wenzelm@11848
   259
paulson@13779
   260
paulson@13779
   261
paulson@13779
   262
subsection {* ``Let'' declarations *}
paulson@13779
   263
paulson@13779
   264
nonterminals letbinds letbind
paulson@13779
   265
paulson@13779
   266
constdefs
paulson@13779
   267
  Let :: "['a::logic, 'a => 'b] => ('b::logic)"
paulson@13779
   268
    "Let(s, f) == f(s)"
paulson@13779
   269
paulson@13779
   270
syntax
paulson@13779
   271
  "_bind"       :: "[pttrn, 'a] => letbind"           ("(2_ =/ _)" 10)
paulson@13779
   272
  ""            :: "letbind => letbinds"              ("_")
paulson@13779
   273
  "_binds"      :: "[letbind, letbinds] => letbinds"  ("_;/ _")
paulson@13779
   274
  "_Let"        :: "[letbinds, 'a] => 'a"             ("(let (_)/ in (_))" 10)
paulson@13779
   275
paulson@13779
   276
translations
paulson@13779
   277
  "_Let(_binds(b, bs), e)"  == "_Let(b, _Let(bs, e))"
paulson@13779
   278
  "let x = a in e"          == "Let(a, %x. e)"
paulson@13779
   279
paulson@13779
   280
paulson@13779
   281
lemma LetI: 
paulson@13779
   282
    assumes prem: "(!!x. x=t ==> P(u(x)))"
paulson@13779
   283
    shows "P(let x=t in u(x))"
paulson@13779
   284
apply (unfold Let_def)
paulson@13779
   285
apply (rule refl [THEN prem])
paulson@13779
   286
done
paulson@13779
   287
paulson@13779
   288
ML
paulson@13779
   289
{*
paulson@13779
   290
val Let_def = thm "Let_def";
paulson@13779
   291
val LetI = thm "LetI";
paulson@13779
   292
*}
paulson@13779
   293
wenzelm@4854
   294
end