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