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