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