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