src/FOL/IFOL.thy
author wenzelm
Wed Feb 22 22:18:31 2006 +0100 (2006-02-22)
changeset 19120 353d349740de
parent 18861 38269ef5175a
child 19363 667b5ea637dd
permissions -rw-r--r--
not_equal: replaced syntax translation by abbreviation;
simplified Pure conjunction;
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@19120
    48
abbreviation (output)
wenzelm@19120
    49
  not_equal     :: "['a, 'a] => o"              (infixl "~=" 50)
wenzelm@19120
    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@19120
    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)
wenzelm@19120
    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
use "IFOL_lemmas.ML"
wenzelm@11734
   144
wenzelm@18481
   145
ML {*
wenzelm@18481
   146
structure ProjectRule = ProjectRuleFun
wenzelm@18481
   147
(struct
wenzelm@18481
   148
  val conjunct1 = thm "conjunct1";
wenzelm@18481
   149
  val conjunct2 = thm "conjunct2";
wenzelm@18481
   150
  val mp = thm "mp";
wenzelm@18481
   151
end)
wenzelm@18481
   152
*}
wenzelm@18481
   153
wenzelm@7355
   154
use "fologic.ML"
wenzelm@9886
   155
use "hypsubstdata.ML"
wenzelm@9886
   156
setup hypsubst_setup
wenzelm@7355
   157
use "intprover.ML"
wenzelm@7355
   158
wenzelm@4092
   159
wenzelm@12875
   160
subsection {* Intuitionistic Reasoning *}
wenzelm@12368
   161
wenzelm@12349
   162
lemma impE':
wenzelm@12937
   163
  assumes 1: "P --> Q"
wenzelm@12937
   164
    and 2: "Q ==> R"
wenzelm@12937
   165
    and 3: "P --> Q ==> P"
wenzelm@12937
   166
  shows R
wenzelm@12349
   167
proof -
wenzelm@12349
   168
  from 3 and 1 have P .
wenzelm@12368
   169
  with 1 have Q by (rule impE)
wenzelm@12349
   170
  with 2 show R .
wenzelm@12349
   171
qed
wenzelm@12349
   172
wenzelm@12349
   173
lemma allE':
wenzelm@12937
   174
  assumes 1: "ALL x. P(x)"
wenzelm@12937
   175
    and 2: "P(x) ==> ALL x. P(x) ==> Q"
wenzelm@12937
   176
  shows Q
wenzelm@12349
   177
proof -
wenzelm@12349
   178
  from 1 have "P(x)" by (rule spec)
wenzelm@12349
   179
  from this and 1 show Q by (rule 2)
wenzelm@12349
   180
qed
wenzelm@12349
   181
wenzelm@12937
   182
lemma notE':
wenzelm@12937
   183
  assumes 1: "~ P"
wenzelm@12937
   184
    and 2: "~ P ==> P"
wenzelm@12937
   185
  shows R
wenzelm@12349
   186
proof -
wenzelm@12349
   187
  from 2 and 1 have P .
wenzelm@12349
   188
  with 1 show R by (rule notE)
wenzelm@12349
   189
qed
wenzelm@12349
   190
wenzelm@12349
   191
lemmas [Pure.elim!] = disjE iffE FalseE conjE exE
wenzelm@12349
   192
  and [Pure.intro!] = iffI conjI impI TrueI notI allI refl
wenzelm@12349
   193
  and [Pure.elim 2] = allE notE' impE'
wenzelm@12349
   194
  and [Pure.intro] = exI disjI2 disjI1
wenzelm@12349
   195
wenzelm@18708
   196
setup {* ContextRules.addSWrapper (fn tac => hyp_subst_tac ORELSE' tac) *}
wenzelm@12349
   197
wenzelm@12349
   198
wenzelm@12368
   199
lemma iff_not_sym: "~ (Q <-> P) ==> ~ (P <-> Q)"
nipkow@17591
   200
  by iprover
wenzelm@12368
   201
wenzelm@12368
   202
lemmas [sym] = sym iff_sym not_sym iff_not_sym
wenzelm@12368
   203
  and [Pure.elim?] = iffD1 iffD2 impE
wenzelm@12368
   204
wenzelm@12368
   205
paulson@13435
   206
lemma eq_commute: "a=b <-> b=a"
paulson@13435
   207
apply (rule iffI) 
paulson@13435
   208
apply (erule sym)+
paulson@13435
   209
done
paulson@13435
   210
paulson@13435
   211
wenzelm@11677
   212
subsection {* Atomizing meta-level rules *}
wenzelm@11677
   213
wenzelm@11747
   214
lemma atomize_all [atomize]: "(!!x. P(x)) == Trueprop (ALL x. P(x))"
wenzelm@11976
   215
proof
wenzelm@11677
   216
  assume "!!x. P(x)"
wenzelm@12368
   217
  show "ALL x. P(x)" ..
wenzelm@11677
   218
next
wenzelm@11677
   219
  assume "ALL x. P(x)"
wenzelm@12368
   220
  thus "!!x. P(x)" ..
wenzelm@11677
   221
qed
wenzelm@11677
   222
wenzelm@11747
   223
lemma atomize_imp [atomize]: "(A ==> B) == Trueprop (A --> B)"
wenzelm@11976
   224
proof
wenzelm@12368
   225
  assume "A ==> B"
wenzelm@12368
   226
  thus "A --> B" ..
wenzelm@11677
   227
next
wenzelm@11677
   228
  assume "A --> B" and A
wenzelm@11677
   229
  thus B by (rule mp)
wenzelm@11677
   230
qed
wenzelm@11677
   231
wenzelm@11747
   232
lemma atomize_eq [atomize]: "(x == y) == Trueprop (x = y)"
wenzelm@11976
   233
proof
wenzelm@11677
   234
  assume "x == y"
wenzelm@11677
   235
  show "x = y" by (unfold prems) (rule refl)
wenzelm@11677
   236
next
wenzelm@11677
   237
  assume "x = y"
wenzelm@11677
   238
  thus "x == y" by (rule eq_reflection)
wenzelm@11677
   239
qed
wenzelm@11677
   240
wenzelm@18813
   241
lemma atomize_iff [atomize]: "(A == B) == Trueprop (A <-> B)"
wenzelm@18813
   242
proof
wenzelm@18813
   243
  assume "A == B"
wenzelm@18813
   244
  show "A <-> B" by (unfold prems) (rule iff_refl)
wenzelm@18813
   245
next
wenzelm@18813
   246
  assume "A <-> B"
wenzelm@18813
   247
  thus "A == B" by (rule iff_reflection)
wenzelm@18813
   248
qed
wenzelm@18813
   249
wenzelm@12875
   250
lemma atomize_conj [atomize]:
wenzelm@19120
   251
  includes meta_conjunction_syntax
wenzelm@19120
   252
  shows "(A && B) == Trueprop (A & B)"
wenzelm@11976
   253
proof
wenzelm@19120
   254
  assume conj: "A && B"
wenzelm@19120
   255
  show "A & B"
wenzelm@19120
   256
  proof (rule conjI)
wenzelm@19120
   257
    from conj show A by (rule conjunctionD1)
wenzelm@19120
   258
    from conj show B by (rule conjunctionD2)
wenzelm@19120
   259
  qed
wenzelm@11953
   260
next
wenzelm@19120
   261
  assume conj: "A & B"
wenzelm@19120
   262
  show "A && B"
wenzelm@19120
   263
  proof -
wenzelm@19120
   264
    from conj show A ..
wenzelm@19120
   265
    from conj show B ..
wenzelm@11953
   266
  qed
wenzelm@11953
   267
qed
wenzelm@11953
   268
wenzelm@12368
   269
lemmas [symmetric, rulify] = atomize_all atomize_imp
wenzelm@18861
   270
  and [symmetric, defn] = atomize_all atomize_imp atomize_eq atomize_iff
wenzelm@11771
   271
wenzelm@11848
   272
wenzelm@11848
   273
subsection {* Calculational rules *}
wenzelm@11848
   274
wenzelm@11848
   275
lemma forw_subst: "a = b ==> P(b) ==> P(a)"
wenzelm@11848
   276
  by (rule ssubst)
wenzelm@11848
   277
wenzelm@11848
   278
lemma back_subst: "P(a) ==> a = b ==> P(b)"
wenzelm@11848
   279
  by (rule subst)
wenzelm@11848
   280
wenzelm@11848
   281
text {*
wenzelm@11848
   282
  Note that this list of rules is in reverse order of priorities.
wenzelm@11848
   283
*}
wenzelm@11848
   284
wenzelm@12019
   285
lemmas basic_trans_rules [trans] =
wenzelm@11848
   286
  forw_subst
wenzelm@11848
   287
  back_subst
wenzelm@11848
   288
  rev_mp
wenzelm@11848
   289
  mp
wenzelm@11848
   290
  trans
wenzelm@11848
   291
paulson@13779
   292
subsection {* ``Let'' declarations *}
paulson@13779
   293
paulson@13779
   294
nonterminals letbinds letbind
paulson@13779
   295
paulson@13779
   296
constdefs
wenzelm@14854
   297
  Let :: "['a::{}, 'a => 'b] => ('b::{})"
paulson@13779
   298
    "Let(s, f) == f(s)"
paulson@13779
   299
paulson@13779
   300
syntax
paulson@13779
   301
  "_bind"       :: "[pttrn, 'a] => letbind"           ("(2_ =/ _)" 10)
paulson@13779
   302
  ""            :: "letbind => letbinds"              ("_")
paulson@13779
   303
  "_binds"      :: "[letbind, letbinds] => letbinds"  ("_;/ _")
paulson@13779
   304
  "_Let"        :: "[letbinds, 'a] => 'a"             ("(let (_)/ in (_))" 10)
paulson@13779
   305
paulson@13779
   306
translations
paulson@13779
   307
  "_Let(_binds(b, bs), e)"  == "_Let(b, _Let(bs, e))"
paulson@13779
   308
  "let x = a in e"          == "Let(a, %x. e)"
paulson@13779
   309
paulson@13779
   310
paulson@13779
   311
lemma LetI: 
paulson@13779
   312
    assumes prem: "(!!x. x=t ==> P(u(x)))"
paulson@13779
   313
    shows "P(let x=t in u(x))"
paulson@13779
   314
apply (unfold Let_def)
paulson@13779
   315
apply (rule refl [THEN prem])
paulson@13779
   316
done
paulson@13779
   317
paulson@13779
   318
ML
paulson@13779
   319
{*
paulson@13779
   320
val Let_def = thm "Let_def";
paulson@13779
   321
val LetI = thm "LetI";
paulson@13779
   322
*}
paulson@13779
   323
wenzelm@4854
   324
end