src/HOL/HOL.thy
author schirmer
Sat Dec 18 17:14:33 2004 +0100 (2004-12-18)
changeset 15423 761a4f8e6ad6
parent 15411 1d195de59497
child 15481 fc075ae929e4
permissions -rw-r--r--
added simproc for Let
clasohm@923
     1
(*  Title:      HOL/HOL.thy
clasohm@923
     2
    ID:         $Id$
wenzelm@11750
     3
    Author:     Tobias Nipkow, Markus Wenzel, and Larry Paulson
wenzelm@11750
     4
*)
clasohm@923
     5
wenzelm@11750
     6
header {* The basis of Higher-Order Logic *}
clasohm@923
     7
nipkow@15131
     8
theory HOL
nipkow@15140
     9
imports CPure
paulson@15411
    10
files ("cladata.ML") ("blastdata.ML") ("simpdata.ML") ("antisym_setup.ML")
nipkow@15131
    11
begin
wenzelm@2260
    12
wenzelm@11750
    13
subsection {* Primitive logic *}
wenzelm@11750
    14
wenzelm@11750
    15
subsubsection {* Core syntax *}
wenzelm@2260
    16
wenzelm@14854
    17
classes type
wenzelm@12338
    18
defaultsort type
wenzelm@3947
    19
wenzelm@12338
    20
global
clasohm@923
    21
wenzelm@7357
    22
typedecl bool
clasohm@923
    23
clasohm@923
    24
arities
wenzelm@12338
    25
  bool :: type
wenzelm@12338
    26
  fun :: (type, type) type
clasohm@923
    27
wenzelm@11750
    28
judgment
wenzelm@11750
    29
  Trueprop      :: "bool => prop"                   ("(_)" 5)
clasohm@923
    30
wenzelm@11750
    31
consts
wenzelm@7357
    32
  Not           :: "bool => bool"                   ("~ _" [40] 40)
wenzelm@7357
    33
  True          :: bool
wenzelm@7357
    34
  False         :: bool
wenzelm@7357
    35
  If            :: "[bool, 'a, 'a] => 'a"           ("(if (_)/ then (_)/ else (_))" 10)
wenzelm@3947
    36
  arbitrary     :: 'a
clasohm@923
    37
wenzelm@11432
    38
  The           :: "('a => bool) => 'a"
wenzelm@7357
    39
  All           :: "('a => bool) => bool"           (binder "ALL " 10)
wenzelm@7357
    40
  Ex            :: "('a => bool) => bool"           (binder "EX " 10)
wenzelm@7357
    41
  Ex1           :: "('a => bool) => bool"           (binder "EX! " 10)
wenzelm@7357
    42
  Let           :: "['a, 'a => 'b] => 'b"
clasohm@923
    43
wenzelm@7357
    44
  "="           :: "['a, 'a] => bool"               (infixl 50)
wenzelm@7357
    45
  &             :: "[bool, bool] => bool"           (infixr 35)
wenzelm@7357
    46
  "|"           :: "[bool, bool] => bool"           (infixr 30)
wenzelm@7357
    47
  -->           :: "[bool, bool] => bool"           (infixr 25)
clasohm@923
    48
wenzelm@10432
    49
local
wenzelm@10432
    50
wenzelm@2260
    51
wenzelm@11750
    52
subsubsection {* Additional concrete syntax *}
wenzelm@2260
    53
wenzelm@4868
    54
nonterminals
clasohm@923
    55
  letbinds  letbind
clasohm@923
    56
  case_syn  cases_syn
clasohm@923
    57
clasohm@923
    58
syntax
wenzelm@12650
    59
  "_not_equal"  :: "['a, 'a] => bool"                    (infixl "~=" 50)
wenzelm@11432
    60
  "_The"        :: "[pttrn, bool] => 'a"                 ("(3THE _./ _)" [0, 10] 10)
clasohm@923
    61
wenzelm@7357
    62
  "_bind"       :: "[pttrn, 'a] => letbind"              ("(2_ =/ _)" 10)
wenzelm@7357
    63
  ""            :: "letbind => letbinds"                 ("_")
wenzelm@7357
    64
  "_binds"      :: "[letbind, letbinds] => letbinds"     ("_;/ _")
wenzelm@7357
    65
  "_Let"        :: "[letbinds, 'a] => 'a"                ("(let (_)/ in (_))" 10)
clasohm@923
    66
wenzelm@9060
    67
  "_case_syntax":: "['a, cases_syn] => 'b"               ("(case _ of/ _)" 10)
wenzelm@9060
    68
  "_case1"      :: "['a, 'b] => case_syn"                ("(2_ =>/ _)" 10)
wenzelm@7357
    69
  ""            :: "case_syn => cases_syn"               ("_")
wenzelm@9060
    70
  "_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ | _")
clasohm@923
    71
clasohm@923
    72
translations
wenzelm@7238
    73
  "x ~= y"                == "~ (x = y)"
nipkow@13764
    74
  "THE x. P"              == "The (%x. P)"
clasohm@923
    75
  "_Let (_binds b bs) e"  == "_Let b (_Let bs e)"
nipkow@1114
    76
  "let x = a in e"        == "Let a (%x. e)"
clasohm@923
    77
nipkow@13763
    78
print_translation {*
nipkow@13763
    79
(* To avoid eta-contraction of body: *)
nipkow@13763
    80
[("The", fn [Abs abs] =>
nipkow@13763
    81
     let val (x,t) = atomic_abs_tr' abs
nipkow@13763
    82
     in Syntax.const "_The" $ x $ t end)]
nipkow@13763
    83
*}
nipkow@13763
    84
wenzelm@12633
    85
syntax (output)
wenzelm@11687
    86
  "="           :: "['a, 'a] => bool"                    (infix 50)
wenzelm@12650
    87
  "_not_equal"  :: "['a, 'a] => bool"                    (infix "~=" 50)
wenzelm@2260
    88
wenzelm@12114
    89
syntax (xsymbols)
wenzelm@11687
    90
  Not           :: "bool => bool"                        ("\<not> _" [40] 40)
wenzelm@11687
    91
  "op &"        :: "[bool, bool] => bool"                (infixr "\<and>" 35)
wenzelm@11687
    92
  "op |"        :: "[bool, bool] => bool"                (infixr "\<or>" 30)
wenzelm@12114
    93
  "op -->"      :: "[bool, bool] => bool"                (infixr "\<longrightarrow>" 25)
wenzelm@12650
    94
  "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
wenzelm@11687
    95
  "ALL "        :: "[idts, bool] => bool"                ("(3\<forall>_./ _)" [0, 10] 10)
wenzelm@11687
    96
  "EX "         :: "[idts, bool] => bool"                ("(3\<exists>_./ _)" [0, 10] 10)
wenzelm@11687
    97
  "EX! "        :: "[idts, bool] => bool"                ("(3\<exists>!_./ _)" [0, 10] 10)
wenzelm@11687
    98
  "_case1"      :: "['a, 'b] => case_syn"                ("(2_ \<Rightarrow>/ _)" 10)
schirmer@14361
    99
(*"_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ \<orelse> _")*)
wenzelm@2372
   100
wenzelm@12114
   101
syntax (xsymbols output)
wenzelm@12650
   102
  "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
wenzelm@3820
   103
wenzelm@6340
   104
syntax (HTML output)
kleing@14565
   105
  "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
wenzelm@11687
   106
  Not           :: "bool => bool"                        ("\<not> _" [40] 40)
kleing@14565
   107
  "op &"        :: "[bool, bool] => bool"                (infixr "\<and>" 35)
kleing@14565
   108
  "op |"        :: "[bool, bool] => bool"                (infixr "\<or>" 30)
kleing@14565
   109
  "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
kleing@14565
   110
  "ALL "        :: "[idts, bool] => bool"                ("(3\<forall>_./ _)" [0, 10] 10)
kleing@14565
   111
  "EX "         :: "[idts, bool] => bool"                ("(3\<exists>_./ _)" [0, 10] 10)
kleing@14565
   112
  "EX! "        :: "[idts, bool] => bool"                ("(3\<exists>!_./ _)" [0, 10] 10)
wenzelm@6340
   113
wenzelm@7238
   114
syntax (HOL)
wenzelm@7357
   115
  "ALL "        :: "[idts, bool] => bool"                ("(3! _./ _)" [0, 10] 10)
wenzelm@7357
   116
  "EX "         :: "[idts, bool] => bool"                ("(3? _./ _)" [0, 10] 10)
wenzelm@7357
   117
  "EX! "        :: "[idts, bool] => bool"                ("(3?! _./ _)" [0, 10] 10)
wenzelm@7238
   118
wenzelm@7238
   119
wenzelm@11750
   120
subsubsection {* Axioms and basic definitions *}
wenzelm@2260
   121
wenzelm@7357
   122
axioms
paulson@15380
   123
  eq_reflection:  "(x=y) ==> (x==y)"
clasohm@923
   124
paulson@15380
   125
  refl:           "t = (t::'a)"
paulson@6289
   126
paulson@15380
   127
  ext:            "(!!x::'a. (f x ::'b) = g x) ==> (%x. f x) = (%x. g x)"
paulson@15380
   128
    -- {*Extensionality is built into the meta-logic, and this rule expresses
paulson@15380
   129
         a related property.  It is an eta-expanded version of the traditional
paulson@15380
   130
         rule, and similar to the ABS rule of HOL*}
paulson@6289
   131
wenzelm@11432
   132
  the_eq_trivial: "(THE x. x = a) = (a::'a)"
clasohm@923
   133
paulson@15380
   134
  impI:           "(P ==> Q) ==> P-->Q"
paulson@15380
   135
  mp:             "[| P-->Q;  P |] ==> Q"
paulson@15380
   136
paulson@15380
   137
paulson@15380
   138
text{*Thanks to Stephan Merz*}
paulson@15380
   139
theorem subst:
paulson@15380
   140
  assumes eq: "s = t" and p: "P(s)"
paulson@15380
   141
  shows "P(t::'a)"
paulson@15380
   142
proof -
paulson@15380
   143
  from eq have meta: "s \<equiv> t"
paulson@15380
   144
    by (rule eq_reflection)
paulson@15380
   145
  from p show ?thesis
paulson@15380
   146
    by (unfold meta)
paulson@15380
   147
qed
clasohm@923
   148
clasohm@923
   149
defs
wenzelm@7357
   150
  True_def:     "True      == ((%x::bool. x) = (%x. x))"
wenzelm@7357
   151
  All_def:      "All(P)    == (P = (%x. True))"
paulson@11451
   152
  Ex_def:       "Ex(P)     == !Q. (!x. P x --> Q) --> Q"
wenzelm@7357
   153
  False_def:    "False     == (!P. P)"
wenzelm@7357
   154
  not_def:      "~ P       == P-->False"
wenzelm@7357
   155
  and_def:      "P & Q     == !R. (P-->Q-->R) --> R"
wenzelm@7357
   156
  or_def:       "P | Q     == !R. (P-->R) --> (Q-->R) --> R"
wenzelm@7357
   157
  Ex1_def:      "Ex1(P)    == ? x. P(x) & (! y. P(y) --> y=x)"
clasohm@923
   158
wenzelm@7357
   159
axioms
wenzelm@7357
   160
  iff:          "(P-->Q) --> (Q-->P) --> (P=Q)"
wenzelm@7357
   161
  True_or_False:  "(P=True) | (P=False)"
clasohm@923
   162
clasohm@923
   163
defs
wenzelm@7357
   164
  Let_def:      "Let s f == f(s)"
paulson@11451
   165
  if_def:       "If P x y == THE z::'a. (P=True --> z=x) & (P=False --> z=y)"
wenzelm@5069
   166
skalberg@14223
   167
finalconsts
skalberg@14223
   168
  "op ="
skalberg@14223
   169
  "op -->"
skalberg@14223
   170
  The
skalberg@14223
   171
  arbitrary
nipkow@3320
   172
wenzelm@11750
   173
subsubsection {* Generic algebraic operations *}
wenzelm@4868
   174
wenzelm@12338
   175
axclass zero < type
wenzelm@12338
   176
axclass one < type
wenzelm@12338
   177
axclass plus < type
wenzelm@12338
   178
axclass minus < type
wenzelm@12338
   179
axclass times < type
wenzelm@12338
   180
axclass inverse < type
wenzelm@11750
   181
wenzelm@11750
   182
global
wenzelm@11750
   183
wenzelm@11750
   184
consts
wenzelm@11750
   185
  "0"           :: "'a::zero"                       ("0")
wenzelm@11750
   186
  "1"           :: "'a::one"                        ("1")
wenzelm@11750
   187
  "+"           :: "['a::plus, 'a]  => 'a"          (infixl 65)
wenzelm@11750
   188
  -             :: "['a::minus, 'a] => 'a"          (infixl 65)
wenzelm@11750
   189
  uminus        :: "['a::minus] => 'a"              ("- _" [81] 80)
wenzelm@11750
   190
  *             :: "['a::times, 'a] => 'a"          (infixl 70)
wenzelm@11750
   191
wenzelm@13456
   192
syntax
wenzelm@13456
   193
  "_index1"  :: index    ("\<^sub>1")
wenzelm@13456
   194
translations
wenzelm@14690
   195
  (index) "\<^sub>1" => (index) "\<^bsub>\<struct>\<^esub>"
wenzelm@13456
   196
wenzelm@11750
   197
local
wenzelm@11750
   198
wenzelm@11750
   199
typed_print_translation {*
wenzelm@11750
   200
  let
wenzelm@11750
   201
    fun tr' c = (c, fn show_sorts => fn T => fn ts =>
wenzelm@11750
   202
      if T = dummyT orelse not (! show_types) andalso can Term.dest_Type T then raise Match
wenzelm@11750
   203
      else Syntax.const Syntax.constrainC $ Syntax.const c $ Syntax.term_of_typ show_sorts T);
wenzelm@11750
   204
  in [tr' "0", tr' "1"] end;
wenzelm@11750
   205
*} -- {* show types that are presumably too general *}
wenzelm@11750
   206
wenzelm@11750
   207
wenzelm@11750
   208
consts
wenzelm@11750
   209
  abs           :: "'a::minus => 'a"
wenzelm@11750
   210
  inverse       :: "'a::inverse => 'a"
wenzelm@11750
   211
  divide        :: "['a::inverse, 'a] => 'a"        (infixl "'/" 70)
wenzelm@11750
   212
wenzelm@11750
   213
syntax (xsymbols)
wenzelm@11750
   214
  abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
wenzelm@11750
   215
syntax (HTML output)
wenzelm@11750
   216
  abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
wenzelm@11750
   217
wenzelm@11750
   218
paulson@15411
   219
subsection {*Equality*}
paulson@15411
   220
paulson@15411
   221
lemma sym: "s=t ==> t=s"
paulson@15411
   222
apply (erule subst)
paulson@15411
   223
apply (rule refl)
paulson@15411
   224
done
paulson@15411
   225
paulson@15411
   226
(*calling "standard" reduces maxidx to 0*)
paulson@15411
   227
lemmas ssubst = sym [THEN subst, standard]
paulson@15411
   228
paulson@15411
   229
lemma trans: "[| r=s; s=t |] ==> r=t"
paulson@15411
   230
apply (erule subst , assumption)
paulson@15411
   231
done
paulson@15411
   232
paulson@15411
   233
lemma def_imp_eq:  assumes meq: "A == B" shows "A = B"
paulson@15411
   234
apply (unfold meq)
paulson@15411
   235
apply (rule refl)
paulson@15411
   236
done
paulson@15411
   237
paulson@15411
   238
(*Useful with eresolve_tac for proving equalties from known equalities.
paulson@15411
   239
        a = b
paulson@15411
   240
        |   |
paulson@15411
   241
        c = d   *)
paulson@15411
   242
lemma box_equals: "[| a=b;  a=c;  b=d |] ==> c=d"
paulson@15411
   243
apply (rule trans)
paulson@15411
   244
apply (rule trans)
paulson@15411
   245
apply (rule sym)
paulson@15411
   246
apply assumption+
paulson@15411
   247
done
paulson@15411
   248
paulson@15411
   249
paulson@15411
   250
subsection {*Congruence rules for application*}
paulson@15411
   251
paulson@15411
   252
(*similar to AP_THM in Gordon's HOL*)
paulson@15411
   253
lemma fun_cong: "(f::'a=>'b) = g ==> f(x)=g(x)"
paulson@15411
   254
apply (erule subst)
paulson@15411
   255
apply (rule refl)
paulson@15411
   256
done
paulson@15411
   257
paulson@15411
   258
(*similar to AP_TERM in Gordon's HOL and FOL's subst_context*)
paulson@15411
   259
lemma arg_cong: "x=y ==> f(x)=f(y)"
paulson@15411
   260
apply (erule subst)
paulson@15411
   261
apply (rule refl)
paulson@15411
   262
done
paulson@15411
   263
paulson@15411
   264
lemma cong: "[| f = g; (x::'a) = y |] ==> f(x) = g(y)"
paulson@15411
   265
apply (erule subst)+
paulson@15411
   266
apply (rule refl)
paulson@15411
   267
done
paulson@15411
   268
paulson@15411
   269
paulson@15411
   270
subsection {*Equality of booleans -- iff*}
paulson@15411
   271
paulson@15411
   272
lemma iffI: assumes prems: "P ==> Q" "Q ==> P" shows "P=Q"
paulson@15411
   273
apply (rules intro: iff [THEN mp, THEN mp] impI prems)
paulson@15411
   274
done
paulson@15411
   275
paulson@15411
   276
lemma iffD2: "[| P=Q; Q |] ==> P"
paulson@15411
   277
apply (erule ssubst)
paulson@15411
   278
apply assumption
paulson@15411
   279
done
paulson@15411
   280
paulson@15411
   281
lemma rev_iffD2: "[| Q; P=Q |] ==> P"
paulson@15411
   282
apply (erule iffD2)
paulson@15411
   283
apply assumption
paulson@15411
   284
done
paulson@15411
   285
paulson@15411
   286
lemmas iffD1 = sym [THEN iffD2, standard]
paulson@15411
   287
lemmas rev_iffD1 = sym [THEN [2] rev_iffD2, standard]
paulson@15411
   288
paulson@15411
   289
lemma iffE:
paulson@15411
   290
  assumes major: "P=Q"
paulson@15411
   291
      and minor: "[| P --> Q; Q --> P |] ==> R"
paulson@15411
   292
  shows "R"
paulson@15411
   293
by (rules intro: minor impI major [THEN iffD2] major [THEN iffD1])
paulson@15411
   294
paulson@15411
   295
paulson@15411
   296
subsection {*True*}
paulson@15411
   297
paulson@15411
   298
lemma TrueI: "True"
paulson@15411
   299
apply (unfold True_def)
paulson@15411
   300
apply (rule refl)
paulson@15411
   301
done
paulson@15411
   302
paulson@15411
   303
lemma eqTrueI: "P ==> P=True"
paulson@15411
   304
by (rules intro: iffI TrueI)
paulson@15411
   305
paulson@15411
   306
lemma eqTrueE: "P=True ==> P"
paulson@15411
   307
apply (erule iffD2)
paulson@15411
   308
apply (rule TrueI)
paulson@15411
   309
done
paulson@15411
   310
paulson@15411
   311
paulson@15411
   312
subsection {*Universal quantifier*}
paulson@15411
   313
paulson@15411
   314
lemma allI: assumes p: "!!x::'a. P(x)" shows "ALL x. P(x)"
paulson@15411
   315
apply (unfold All_def)
paulson@15411
   316
apply (rules intro: ext eqTrueI p)
paulson@15411
   317
done
paulson@15411
   318
paulson@15411
   319
lemma spec: "ALL x::'a. P(x) ==> P(x)"
paulson@15411
   320
apply (unfold All_def)
paulson@15411
   321
apply (rule eqTrueE)
paulson@15411
   322
apply (erule fun_cong)
paulson@15411
   323
done
paulson@15411
   324
paulson@15411
   325
lemma allE:
paulson@15411
   326
  assumes major: "ALL x. P(x)"
paulson@15411
   327
      and minor: "P(x) ==> R"
paulson@15411
   328
  shows "R"
paulson@15411
   329
by (rules intro: minor major [THEN spec])
paulson@15411
   330
paulson@15411
   331
lemma all_dupE:
paulson@15411
   332
  assumes major: "ALL x. P(x)"
paulson@15411
   333
      and minor: "[| P(x); ALL x. P(x) |] ==> R"
paulson@15411
   334
  shows "R"
paulson@15411
   335
by (rules intro: minor major major [THEN spec])
paulson@15411
   336
paulson@15411
   337
paulson@15411
   338
subsection {*False*}
paulson@15411
   339
(*Depends upon spec; it is impossible to do propositional logic before quantifiers!*)
paulson@15411
   340
paulson@15411
   341
lemma FalseE: "False ==> P"
paulson@15411
   342
apply (unfold False_def)
paulson@15411
   343
apply (erule spec)
paulson@15411
   344
done
paulson@15411
   345
paulson@15411
   346
lemma False_neq_True: "False=True ==> P"
paulson@15411
   347
by (erule eqTrueE [THEN FalseE])
paulson@15411
   348
paulson@15411
   349
paulson@15411
   350
subsection {*Negation*}
paulson@15411
   351
paulson@15411
   352
lemma notI:
paulson@15411
   353
  assumes p: "P ==> False"
paulson@15411
   354
  shows "~P"
paulson@15411
   355
apply (unfold not_def)
paulson@15411
   356
apply (rules intro: impI p)
paulson@15411
   357
done
paulson@15411
   358
paulson@15411
   359
lemma False_not_True: "False ~= True"
paulson@15411
   360
apply (rule notI)
paulson@15411
   361
apply (erule False_neq_True)
paulson@15411
   362
done
paulson@15411
   363
paulson@15411
   364
lemma True_not_False: "True ~= False"
paulson@15411
   365
apply (rule notI)
paulson@15411
   366
apply (drule sym)
paulson@15411
   367
apply (erule False_neq_True)
paulson@15411
   368
done
paulson@15411
   369
paulson@15411
   370
lemma notE: "[| ~P;  P |] ==> R"
paulson@15411
   371
apply (unfold not_def)
paulson@15411
   372
apply (erule mp [THEN FalseE])
paulson@15411
   373
apply assumption
paulson@15411
   374
done
paulson@15411
   375
paulson@15411
   376
(* Alternative ~ introduction rule: [| P ==> ~ Pa; P ==> Pa |] ==> ~ P *)
paulson@15411
   377
lemmas notI2 = notE [THEN notI, standard]
paulson@15411
   378
paulson@15411
   379
paulson@15411
   380
subsection {*Implication*}
paulson@15411
   381
paulson@15411
   382
lemma impE:
paulson@15411
   383
  assumes "P-->Q" "P" "Q ==> R"
paulson@15411
   384
  shows "R"
paulson@15411
   385
by (rules intro: prems mp)
paulson@15411
   386
paulson@15411
   387
(* Reduces Q to P-->Q, allowing substitution in P. *)
paulson@15411
   388
lemma rev_mp: "[| P;  P --> Q |] ==> Q"
paulson@15411
   389
by (rules intro: mp)
paulson@15411
   390
paulson@15411
   391
lemma contrapos_nn:
paulson@15411
   392
  assumes major: "~Q"
paulson@15411
   393
      and minor: "P==>Q"
paulson@15411
   394
  shows "~P"
paulson@15411
   395
by (rules intro: notI minor major [THEN notE])
paulson@15411
   396
paulson@15411
   397
(*not used at all, but we already have the other 3 combinations *)
paulson@15411
   398
lemma contrapos_pn:
paulson@15411
   399
  assumes major: "Q"
paulson@15411
   400
      and minor: "P ==> ~Q"
paulson@15411
   401
  shows "~P"
paulson@15411
   402
by (rules intro: notI minor major notE)
paulson@15411
   403
paulson@15411
   404
lemma not_sym: "t ~= s ==> s ~= t"
paulson@15411
   405
apply (erule contrapos_nn)
paulson@15411
   406
apply (erule sym)
paulson@15411
   407
done
paulson@15411
   408
paulson@15411
   409
(*still used in HOLCF*)
paulson@15411
   410
lemma rev_contrapos:
paulson@15411
   411
  assumes pq: "P ==> Q"
paulson@15411
   412
      and nq: "~Q"
paulson@15411
   413
  shows "~P"
paulson@15411
   414
apply (rule nq [THEN contrapos_nn])
paulson@15411
   415
apply (erule pq)
paulson@15411
   416
done
paulson@15411
   417
paulson@15411
   418
subsection {*Existential quantifier*}
paulson@15411
   419
paulson@15411
   420
lemma exI: "P x ==> EX x::'a. P x"
paulson@15411
   421
apply (unfold Ex_def)
paulson@15411
   422
apply (rules intro: allI allE impI mp)
paulson@15411
   423
done
paulson@15411
   424
paulson@15411
   425
lemma exE:
paulson@15411
   426
  assumes major: "EX x::'a. P(x)"
paulson@15411
   427
      and minor: "!!x. P(x) ==> Q"
paulson@15411
   428
  shows "Q"
paulson@15411
   429
apply (rule major [unfolded Ex_def, THEN spec, THEN mp])
paulson@15411
   430
apply (rules intro: impI [THEN allI] minor)
paulson@15411
   431
done
paulson@15411
   432
paulson@15411
   433
paulson@15411
   434
subsection {*Conjunction*}
paulson@15411
   435
paulson@15411
   436
lemma conjI: "[| P; Q |] ==> P&Q"
paulson@15411
   437
apply (unfold and_def)
paulson@15411
   438
apply (rules intro: impI [THEN allI] mp)
paulson@15411
   439
done
paulson@15411
   440
paulson@15411
   441
lemma conjunct1: "[| P & Q |] ==> P"
paulson@15411
   442
apply (unfold and_def)
paulson@15411
   443
apply (rules intro: impI dest: spec mp)
paulson@15411
   444
done
paulson@15411
   445
paulson@15411
   446
lemma conjunct2: "[| P & Q |] ==> Q"
paulson@15411
   447
apply (unfold and_def)
paulson@15411
   448
apply (rules intro: impI dest: spec mp)
paulson@15411
   449
done
paulson@15411
   450
paulson@15411
   451
lemma conjE:
paulson@15411
   452
  assumes major: "P&Q"
paulson@15411
   453
      and minor: "[| P; Q |] ==> R"
paulson@15411
   454
  shows "R"
paulson@15411
   455
apply (rule minor)
paulson@15411
   456
apply (rule major [THEN conjunct1])
paulson@15411
   457
apply (rule major [THEN conjunct2])
paulson@15411
   458
done
paulson@15411
   459
paulson@15411
   460
lemma context_conjI:
paulson@15411
   461
  assumes prems: "P" "P ==> Q" shows "P & Q"
paulson@15411
   462
by (rules intro: conjI prems)
paulson@15411
   463
paulson@15411
   464
paulson@15411
   465
subsection {*Disjunction*}
paulson@15411
   466
paulson@15411
   467
lemma disjI1: "P ==> P|Q"
paulson@15411
   468
apply (unfold or_def)
paulson@15411
   469
apply (rules intro: allI impI mp)
paulson@15411
   470
done
paulson@15411
   471
paulson@15411
   472
lemma disjI2: "Q ==> P|Q"
paulson@15411
   473
apply (unfold or_def)
paulson@15411
   474
apply (rules intro: allI impI mp)
paulson@15411
   475
done
paulson@15411
   476
paulson@15411
   477
lemma disjE:
paulson@15411
   478
  assumes major: "P|Q"
paulson@15411
   479
      and minorP: "P ==> R"
paulson@15411
   480
      and minorQ: "Q ==> R"
paulson@15411
   481
  shows "R"
paulson@15411
   482
by (rules intro: minorP minorQ impI
paulson@15411
   483
                 major [unfolded or_def, THEN spec, THEN mp, THEN mp])
paulson@15411
   484
paulson@15411
   485
paulson@15411
   486
subsection {*Classical logic*}
paulson@15411
   487
paulson@15411
   488
paulson@15411
   489
lemma classical:
paulson@15411
   490
  assumes prem: "~P ==> P"
paulson@15411
   491
  shows "P"
paulson@15411
   492
apply (rule True_or_False [THEN disjE, THEN eqTrueE])
paulson@15411
   493
apply assumption
paulson@15411
   494
apply (rule notI [THEN prem, THEN eqTrueI])
paulson@15411
   495
apply (erule subst)
paulson@15411
   496
apply assumption
paulson@15411
   497
done
paulson@15411
   498
paulson@15411
   499
lemmas ccontr = FalseE [THEN classical, standard]
paulson@15411
   500
paulson@15411
   501
(*notE with premises exchanged; it discharges ~R so that it can be used to
paulson@15411
   502
  make elimination rules*)
paulson@15411
   503
lemma rev_notE:
paulson@15411
   504
  assumes premp: "P"
paulson@15411
   505
      and premnot: "~R ==> ~P"
paulson@15411
   506
  shows "R"
paulson@15411
   507
apply (rule ccontr)
paulson@15411
   508
apply (erule notE [OF premnot premp])
paulson@15411
   509
done
paulson@15411
   510
paulson@15411
   511
(*Double negation law*)
paulson@15411
   512
lemma notnotD: "~~P ==> P"
paulson@15411
   513
apply (rule classical)
paulson@15411
   514
apply (erule notE)
paulson@15411
   515
apply assumption
paulson@15411
   516
done
paulson@15411
   517
paulson@15411
   518
lemma contrapos_pp:
paulson@15411
   519
  assumes p1: "Q"
paulson@15411
   520
      and p2: "~P ==> ~Q"
paulson@15411
   521
  shows "P"
paulson@15411
   522
by (rules intro: classical p1 p2 notE)
paulson@15411
   523
paulson@15411
   524
paulson@15411
   525
subsection {*Unique existence*}
paulson@15411
   526
paulson@15411
   527
lemma ex1I:
paulson@15411
   528
  assumes prems: "P a" "!!x. P(x) ==> x=a"
paulson@15411
   529
  shows "EX! x. P(x)"
paulson@15411
   530
by (unfold Ex1_def, rules intro: prems exI conjI allI impI)
paulson@15411
   531
paulson@15411
   532
text{*Sometimes easier to use: the premises have no shared variables.  Safe!*}
paulson@15411
   533
lemma ex_ex1I:
paulson@15411
   534
  assumes ex_prem: "EX x. P(x)"
paulson@15411
   535
      and eq: "!!x y. [| P(x); P(y) |] ==> x=y"
paulson@15411
   536
  shows "EX! x. P(x)"
paulson@15411
   537
by (rules intro: ex_prem [THEN exE] ex1I eq)
paulson@15411
   538
paulson@15411
   539
lemma ex1E:
paulson@15411
   540
  assumes major: "EX! x. P(x)"
paulson@15411
   541
      and minor: "!!x. [| P(x);  ALL y. P(y) --> y=x |] ==> R"
paulson@15411
   542
  shows "R"
paulson@15411
   543
apply (rule major [unfolded Ex1_def, THEN exE])
paulson@15411
   544
apply (erule conjE)
paulson@15411
   545
apply (rules intro: minor)
paulson@15411
   546
done
paulson@15411
   547
paulson@15411
   548
lemma ex1_implies_ex: "EX! x. P x ==> EX x. P x"
paulson@15411
   549
apply (erule ex1E)
paulson@15411
   550
apply (rule exI)
paulson@15411
   551
apply assumption
paulson@15411
   552
done
paulson@15411
   553
paulson@15411
   554
paulson@15411
   555
subsection {*THE: definite description operator*}
paulson@15411
   556
paulson@15411
   557
lemma the_equality:
paulson@15411
   558
  assumes prema: "P a"
paulson@15411
   559
      and premx: "!!x. P x ==> x=a"
paulson@15411
   560
  shows "(THE x. P x) = a"
paulson@15411
   561
apply (rule trans [OF _ the_eq_trivial])
paulson@15411
   562
apply (rule_tac f = "The" in arg_cong)
paulson@15411
   563
apply (rule ext)
paulson@15411
   564
apply (rule iffI)
paulson@15411
   565
 apply (erule premx)
paulson@15411
   566
apply (erule ssubst, rule prema)
paulson@15411
   567
done
paulson@15411
   568
paulson@15411
   569
lemma theI:
paulson@15411
   570
  assumes "P a" and "!!x. P x ==> x=a"
paulson@15411
   571
  shows "P (THE x. P x)"
paulson@15411
   572
by (rules intro: prems the_equality [THEN ssubst])
paulson@15411
   573
paulson@15411
   574
lemma theI': "EX! x. P x ==> P (THE x. P x)"
paulson@15411
   575
apply (erule ex1E)
paulson@15411
   576
apply (erule theI)
paulson@15411
   577
apply (erule allE)
paulson@15411
   578
apply (erule mp)
paulson@15411
   579
apply assumption
paulson@15411
   580
done
paulson@15411
   581
paulson@15411
   582
(*Easier to apply than theI: only one occurrence of P*)
paulson@15411
   583
lemma theI2:
paulson@15411
   584
  assumes "P a" "!!x. P x ==> x=a" "!!x. P x ==> Q x"
paulson@15411
   585
  shows "Q (THE x. P x)"
paulson@15411
   586
by (rules intro: prems theI)
paulson@15411
   587
paulson@15411
   588
lemma the1_equality: "[| EX!x. P x; P a |] ==> (THE x. P x) = a"
paulson@15411
   589
apply (rule the_equality)
paulson@15411
   590
apply  assumption
paulson@15411
   591
apply (erule ex1E)
paulson@15411
   592
apply (erule all_dupE)
paulson@15411
   593
apply (drule mp)
paulson@15411
   594
apply  assumption
paulson@15411
   595
apply (erule ssubst)
paulson@15411
   596
apply (erule allE)
paulson@15411
   597
apply (erule mp)
paulson@15411
   598
apply assumption
paulson@15411
   599
done
paulson@15411
   600
paulson@15411
   601
lemma the_sym_eq_trivial: "(THE y. x=y) = x"
paulson@15411
   602
apply (rule the_equality)
paulson@15411
   603
apply (rule refl)
paulson@15411
   604
apply (erule sym)
paulson@15411
   605
done
paulson@15411
   606
paulson@15411
   607
paulson@15411
   608
subsection {*Classical intro rules for disjunction and existential quantifiers*}
paulson@15411
   609
paulson@15411
   610
lemma disjCI:
paulson@15411
   611
  assumes "~Q ==> P" shows "P|Q"
paulson@15411
   612
apply (rule classical)
paulson@15411
   613
apply (rules intro: prems disjI1 disjI2 notI elim: notE)
paulson@15411
   614
done
paulson@15411
   615
paulson@15411
   616
lemma excluded_middle: "~P | P"
paulson@15411
   617
by (rules intro: disjCI)
paulson@15411
   618
paulson@15411
   619
text{*case distinction as a natural deduction rule. Note that @{term "~P"}
paulson@15411
   620
   is the second case, not the first.*}
paulson@15411
   621
lemma case_split_thm:
paulson@15411
   622
  assumes prem1: "P ==> Q"
paulson@15411
   623
      and prem2: "~P ==> Q"
paulson@15411
   624
  shows "Q"
paulson@15411
   625
apply (rule excluded_middle [THEN disjE])
paulson@15411
   626
apply (erule prem2)
paulson@15411
   627
apply (erule prem1)
paulson@15411
   628
done
paulson@15411
   629
paulson@15411
   630
(*Classical implies (-->) elimination. *)
paulson@15411
   631
lemma impCE:
paulson@15411
   632
  assumes major: "P-->Q"
paulson@15411
   633
      and minor: "~P ==> R" "Q ==> R"
paulson@15411
   634
  shows "R"
paulson@15411
   635
apply (rule excluded_middle [of P, THEN disjE])
paulson@15411
   636
apply (rules intro: minor major [THEN mp])+
paulson@15411
   637
done
paulson@15411
   638
paulson@15411
   639
(*This version of --> elimination works on Q before P.  It works best for
paulson@15411
   640
  those cases in which P holds "almost everywhere".  Can't install as
paulson@15411
   641
  default: would break old proofs.*)
paulson@15411
   642
lemma impCE':
paulson@15411
   643
  assumes major: "P-->Q"
paulson@15411
   644
      and minor: "Q ==> R" "~P ==> R"
paulson@15411
   645
  shows "R"
paulson@15411
   646
apply (rule excluded_middle [of P, THEN disjE])
paulson@15411
   647
apply (rules intro: minor major [THEN mp])+
paulson@15411
   648
done
paulson@15411
   649
paulson@15411
   650
(*Classical <-> elimination. *)
paulson@15411
   651
lemma iffCE:
paulson@15411
   652
  assumes major: "P=Q"
paulson@15411
   653
      and minor: "[| P; Q |] ==> R"  "[| ~P; ~Q |] ==> R"
paulson@15411
   654
  shows "R"
paulson@15411
   655
apply (rule major [THEN iffE])
paulson@15411
   656
apply (rules intro: minor elim: impCE notE)
paulson@15411
   657
done
paulson@15411
   658
paulson@15411
   659
lemma exCI:
paulson@15411
   660
  assumes "ALL x. ~P(x) ==> P(a)"
paulson@15411
   661
  shows "EX x. P(x)"
paulson@15411
   662
apply (rule ccontr)
paulson@15411
   663
apply (rules intro: prems exI allI notI notE [of "\<exists>x. P x"])
paulson@15411
   664
done
paulson@15411
   665
paulson@15411
   666
paulson@15411
   667
wenzelm@11750
   668
subsection {* Theory and package setup *}
wenzelm@11750
   669
paulson@15411
   670
ML
paulson@15411
   671
{*
paulson@15411
   672
val plusI = thm "plusI"
paulson@15411
   673
val minusI = thm "minusI"
paulson@15411
   674
val timesI = thm "timesI"
paulson@15411
   675
val eq_reflection = thm "eq_reflection"
paulson@15411
   676
val refl = thm "refl"
paulson@15411
   677
val subst = thm "subst"
paulson@15411
   678
val ext = thm "ext"
paulson@15411
   679
val impI = thm "impI"
paulson@15411
   680
val mp = thm "mp"
paulson@15411
   681
val True_def = thm "True_def"
paulson@15411
   682
val All_def = thm "All_def"
paulson@15411
   683
val Ex_def = thm "Ex_def"
paulson@15411
   684
val False_def = thm "False_def"
paulson@15411
   685
val not_def = thm "not_def"
paulson@15411
   686
val and_def = thm "and_def"
paulson@15411
   687
val or_def = thm "or_def"
paulson@15411
   688
val Ex1_def = thm "Ex1_def"
paulson@15411
   689
val iff = thm "iff"
paulson@15411
   690
val True_or_False = thm "True_or_False"
paulson@15411
   691
val Let_def = thm "Let_def"
paulson@15411
   692
val if_def = thm "if_def"
paulson@15411
   693
val sym = thm "sym"
paulson@15411
   694
val ssubst = thm "ssubst"
paulson@15411
   695
val trans = thm "trans"
paulson@15411
   696
val def_imp_eq = thm "def_imp_eq"
paulson@15411
   697
val box_equals = thm "box_equals"
paulson@15411
   698
val fun_cong = thm "fun_cong"
paulson@15411
   699
val arg_cong = thm "arg_cong"
paulson@15411
   700
val cong = thm "cong"
paulson@15411
   701
val iffI = thm "iffI"
paulson@15411
   702
val iffD2 = thm "iffD2"
paulson@15411
   703
val rev_iffD2 = thm "rev_iffD2"
paulson@15411
   704
val iffD1 = thm "iffD1"
paulson@15411
   705
val rev_iffD1 = thm "rev_iffD1"
paulson@15411
   706
val iffE = thm "iffE"
paulson@15411
   707
val TrueI = thm "TrueI"
paulson@15411
   708
val eqTrueI = thm "eqTrueI"
paulson@15411
   709
val eqTrueE = thm "eqTrueE"
paulson@15411
   710
val allI = thm "allI"
paulson@15411
   711
val spec = thm "spec"
paulson@15411
   712
val allE = thm "allE"
paulson@15411
   713
val all_dupE = thm "all_dupE"
paulson@15411
   714
val FalseE = thm "FalseE"
paulson@15411
   715
val False_neq_True = thm "False_neq_True"
paulson@15411
   716
val notI = thm "notI"
paulson@15411
   717
val False_not_True = thm "False_not_True"
paulson@15411
   718
val True_not_False = thm "True_not_False"
paulson@15411
   719
val notE = thm "notE"
paulson@15411
   720
val notI2 = thm "notI2"
paulson@15411
   721
val impE = thm "impE"
paulson@15411
   722
val rev_mp = thm "rev_mp"
paulson@15411
   723
val contrapos_nn = thm "contrapos_nn"
paulson@15411
   724
val contrapos_pn = thm "contrapos_pn"
paulson@15411
   725
val not_sym = thm "not_sym"
paulson@15411
   726
val rev_contrapos = thm "rev_contrapos"
paulson@15411
   727
val exI = thm "exI"
paulson@15411
   728
val exE = thm "exE"
paulson@15411
   729
val conjI = thm "conjI"
paulson@15411
   730
val conjunct1 = thm "conjunct1"
paulson@15411
   731
val conjunct2 = thm "conjunct2"
paulson@15411
   732
val conjE = thm "conjE"
paulson@15411
   733
val context_conjI = thm "context_conjI"
paulson@15411
   734
val disjI1 = thm "disjI1"
paulson@15411
   735
val disjI2 = thm "disjI2"
paulson@15411
   736
val disjE = thm "disjE"
paulson@15411
   737
val classical = thm "classical"
paulson@15411
   738
val ccontr = thm "ccontr"
paulson@15411
   739
val rev_notE = thm "rev_notE"
paulson@15411
   740
val notnotD = thm "notnotD"
paulson@15411
   741
val contrapos_pp = thm "contrapos_pp"
paulson@15411
   742
val ex1I = thm "ex1I"
paulson@15411
   743
val ex_ex1I = thm "ex_ex1I"
paulson@15411
   744
val ex1E = thm "ex1E"
paulson@15411
   745
val ex1_implies_ex = thm "ex1_implies_ex"
paulson@15411
   746
val the_equality = thm "the_equality"
paulson@15411
   747
val theI = thm "theI"
paulson@15411
   748
val theI' = thm "theI'"
paulson@15411
   749
val theI2 = thm "theI2"
paulson@15411
   750
val the1_equality = thm "the1_equality"
paulson@15411
   751
val the_sym_eq_trivial = thm "the_sym_eq_trivial"
paulson@15411
   752
val disjCI = thm "disjCI"
paulson@15411
   753
val excluded_middle = thm "excluded_middle"
paulson@15411
   754
val case_split_thm = thm "case_split_thm"
paulson@15411
   755
val impCE = thm "impCE"
paulson@15411
   756
val impCE = thm "impCE"
paulson@15411
   757
val iffCE = thm "iffCE"
paulson@15411
   758
val exCI = thm "exCI"
wenzelm@4868
   759
paulson@15411
   760
(* combination of (spec RS spec RS ...(j times) ... spec RS mp) *)
paulson@15411
   761
local
paulson@15411
   762
  fun wrong_prem (Const ("All", _) $ (Abs (_, _, t))) = wrong_prem t
paulson@15411
   763
  |   wrong_prem (Bound _) = true
paulson@15411
   764
  |   wrong_prem _ = false
paulson@15411
   765
  val filter_right = filter (fn t => not (wrong_prem (HOLogic.dest_Trueprop (hd (Thm.prems_of t)))))
paulson@15411
   766
in
paulson@15411
   767
  fun smp i = funpow i (fn m => filter_right ([spec] RL m)) ([mp])
paulson@15411
   768
  fun smp_tac j = EVERY'[dresolve_tac (smp j), atac]
paulson@15411
   769
end
paulson@15411
   770
paulson@15411
   771
paulson@15411
   772
fun strip_tac i = REPEAT(resolve_tac [impI,allI] i)
paulson@15411
   773
paulson@15411
   774
(*Obsolete form of disjunctive case analysis*)
paulson@15411
   775
fun excluded_middle_tac sP =
paulson@15411
   776
    res_inst_tac [("Q",sP)] (excluded_middle RS disjE)
paulson@15411
   777
paulson@15411
   778
fun case_tac a = res_inst_tac [("P",a)] case_split_thm
paulson@15411
   779
*}
paulson@15411
   780
wenzelm@11687
   781
theorems case_split = case_split_thm [case_names True False]
wenzelm@9869
   782
wenzelm@12386
   783
wenzelm@12386
   784
subsubsection {* Intuitionistic Reasoning *}
wenzelm@12386
   785
wenzelm@12386
   786
lemma impE':
wenzelm@12937
   787
  assumes 1: "P --> Q"
wenzelm@12937
   788
    and 2: "Q ==> R"
wenzelm@12937
   789
    and 3: "P --> Q ==> P"
wenzelm@12937
   790
  shows R
wenzelm@12386
   791
proof -
wenzelm@12386
   792
  from 3 and 1 have P .
wenzelm@12386
   793
  with 1 have Q by (rule impE)
wenzelm@12386
   794
  with 2 show R .
wenzelm@12386
   795
qed
wenzelm@12386
   796
wenzelm@12386
   797
lemma allE':
wenzelm@12937
   798
  assumes 1: "ALL x. P x"
wenzelm@12937
   799
    and 2: "P x ==> ALL x. P x ==> Q"
wenzelm@12937
   800
  shows Q
wenzelm@12386
   801
proof -
wenzelm@12386
   802
  from 1 have "P x" by (rule spec)
wenzelm@12386
   803
  from this and 1 show Q by (rule 2)
wenzelm@12386
   804
qed
wenzelm@12386
   805
wenzelm@12937
   806
lemma notE':
wenzelm@12937
   807
  assumes 1: "~ P"
wenzelm@12937
   808
    and 2: "~ P ==> P"
wenzelm@12937
   809
  shows R
wenzelm@12386
   810
proof -
wenzelm@12386
   811
  from 2 and 1 have P .
wenzelm@12386
   812
  with 1 show R by (rule notE)
wenzelm@12386
   813
qed
wenzelm@12386
   814
wenzelm@12386
   815
lemmas [CPure.elim!] = disjE iffE FalseE conjE exE
wenzelm@12386
   816
  and [CPure.intro!] = iffI conjI impI TrueI notI allI refl
wenzelm@12386
   817
  and [CPure.elim 2] = allE notE' impE'
wenzelm@12386
   818
  and [CPure.intro] = exI disjI2 disjI1
wenzelm@12386
   819
wenzelm@12386
   820
lemmas [trans] = trans
wenzelm@12386
   821
  and [sym] = sym not_sym
wenzelm@12386
   822
  and [CPure.elim?] = iffD1 iffD2 impE
wenzelm@11750
   823
wenzelm@11438
   824
wenzelm@11750
   825
subsubsection {* Atomizing meta-level connectives *}
wenzelm@11750
   826
wenzelm@11750
   827
lemma atomize_all [atomize]: "(!!x. P x) == Trueprop (ALL x. P x)"
wenzelm@12003
   828
proof
wenzelm@9488
   829
  assume "!!x. P x"
wenzelm@10383
   830
  show "ALL x. P x" by (rule allI)
wenzelm@9488
   831
next
wenzelm@9488
   832
  assume "ALL x. P x"
wenzelm@10383
   833
  thus "!!x. P x" by (rule allE)
wenzelm@9488
   834
qed
wenzelm@9488
   835
wenzelm@11750
   836
lemma atomize_imp [atomize]: "(A ==> B) == Trueprop (A --> B)"
wenzelm@12003
   837
proof
wenzelm@9488
   838
  assume r: "A ==> B"
wenzelm@10383
   839
  show "A --> B" by (rule impI) (rule r)
wenzelm@9488
   840
next
wenzelm@9488
   841
  assume "A --> B" and A
wenzelm@10383
   842
  thus B by (rule mp)
wenzelm@9488
   843
qed
wenzelm@9488
   844
paulson@14749
   845
lemma atomize_not: "(A ==> False) == Trueprop (~A)"
paulson@14749
   846
proof
paulson@14749
   847
  assume r: "A ==> False"
paulson@14749
   848
  show "~A" by (rule notI) (rule r)
paulson@14749
   849
next
paulson@14749
   850
  assume "~A" and A
paulson@14749
   851
  thus False by (rule notE)
paulson@14749
   852
qed
paulson@14749
   853
wenzelm@11750
   854
lemma atomize_eq [atomize]: "(x == y) == Trueprop (x = y)"
wenzelm@12003
   855
proof
wenzelm@10432
   856
  assume "x == y"
wenzelm@10432
   857
  show "x = y" by (unfold prems) (rule refl)
wenzelm@10432
   858
next
wenzelm@10432
   859
  assume "x = y"
wenzelm@10432
   860
  thus "x == y" by (rule eq_reflection)
wenzelm@10432
   861
qed
wenzelm@10432
   862
wenzelm@12023
   863
lemma atomize_conj [atomize]:
wenzelm@12023
   864
  "(!!C. (A ==> B ==> PROP C) ==> PROP C) == Trueprop (A & B)"
wenzelm@12003
   865
proof
wenzelm@11953
   866
  assume "!!C. (A ==> B ==> PROP C) ==> PROP C"
wenzelm@11953
   867
  show "A & B" by (rule conjI)
wenzelm@11953
   868
next
wenzelm@11953
   869
  fix C
wenzelm@11953
   870
  assume "A & B"
wenzelm@11953
   871
  assume "A ==> B ==> PROP C"
wenzelm@11953
   872
  thus "PROP C"
wenzelm@11953
   873
  proof this
wenzelm@11953
   874
    show A by (rule conjunct1)
wenzelm@11953
   875
    show B by (rule conjunct2)
wenzelm@11953
   876
  qed
wenzelm@11953
   877
qed
wenzelm@11953
   878
wenzelm@12386
   879
lemmas [symmetric, rulify] = atomize_all atomize_imp
wenzelm@12386
   880
wenzelm@11750
   881
wenzelm@11750
   882
subsubsection {* Classical Reasoner setup *}
wenzelm@9529
   883
wenzelm@10383
   884
use "cladata.ML"
wenzelm@10383
   885
setup hypsubst_setup
wenzelm@11977
   886
wenzelm@12386
   887
ML_setup {*
wenzelm@12386
   888
  Context.>> (ContextRules.addSWrapper (fn tac => hyp_subst_tac' ORELSE' tac));
wenzelm@12386
   889
*}
wenzelm@11977
   890
wenzelm@10383
   891
setup Classical.setup
wenzelm@10383
   892
setup clasetup
wenzelm@10383
   893
wenzelm@12386
   894
lemmas [intro?] = ext
wenzelm@12386
   895
  and [elim?] = ex1_implies_ex
wenzelm@11977
   896
wenzelm@9869
   897
use "blastdata.ML"
wenzelm@9869
   898
setup Blast.setup
wenzelm@4868
   899
wenzelm@11750
   900
wenzelm@11750
   901
subsubsection {* Simplifier setup *}
wenzelm@11750
   902
wenzelm@12281
   903
lemma meta_eq_to_obj_eq: "x == y ==> x = y"
wenzelm@12281
   904
proof -
wenzelm@12281
   905
  assume r: "x == y"
wenzelm@12281
   906
  show "x = y" by (unfold r) (rule refl)
wenzelm@12281
   907
qed
wenzelm@12281
   908
wenzelm@12281
   909
lemma eta_contract_eq: "(%s. f s) = f" ..
wenzelm@12281
   910
wenzelm@12281
   911
lemma simp_thms:
wenzelm@12937
   912
  shows not_not: "(~ ~ P) = P"
nipkow@15354
   913
  and Not_eq_iff: "((~P) = (~Q)) = (P = Q)"
wenzelm@12937
   914
  and
berghofe@12436
   915
    "(P ~= Q) = (P = (~Q))"
berghofe@12436
   916
    "(P | ~P) = True"    "(~P | P) = True"
wenzelm@12281
   917
    "(x = x) = True"
wenzelm@12281
   918
    "(~True) = False"  "(~False) = True"
berghofe@12436
   919
    "(~P) ~= P"  "P ~= (~P)"
wenzelm@12281
   920
    "(True=P) = P"  "(P=True) = P"  "(False=P) = (~P)"  "(P=False) = (~P)"
wenzelm@12281
   921
    "(True --> P) = P"  "(False --> P) = True"
wenzelm@12281
   922
    "(P --> True) = True"  "(P --> P) = True"
wenzelm@12281
   923
    "(P --> False) = (~P)"  "(P --> ~P) = (~P)"
wenzelm@12281
   924
    "(P & True) = P"  "(True & P) = P"
wenzelm@12281
   925
    "(P & False) = False"  "(False & P) = False"
wenzelm@12281
   926
    "(P & P) = P"  "(P & (P & Q)) = (P & Q)"
wenzelm@12281
   927
    "(P & ~P) = False"    "(~P & P) = False"
wenzelm@12281
   928
    "(P | True) = True"  "(True | P) = True"
wenzelm@12281
   929
    "(P | False) = P"  "(False | P) = P"
berghofe@12436
   930
    "(P | P) = P"  "(P | (P | Q)) = (P | Q)" and
wenzelm@12281
   931
    "(ALL x. P) = P"  "(EX x. P) = P"  "EX x. x=t"  "EX x. t=x"
wenzelm@12281
   932
    -- {* needed for the one-point-rule quantifier simplification procs *}
wenzelm@12281
   933
    -- {* essential for termination!! *} and
wenzelm@12281
   934
    "!!P. (EX x. x=t & P(x)) = P(t)"
wenzelm@12281
   935
    "!!P. (EX x. t=x & P(x)) = P(t)"
wenzelm@12281
   936
    "!!P. (ALL x. x=t --> P(x)) = P(t)"
wenzelm@12937
   937
    "!!P. (ALL x. t=x --> P(x)) = P(t)"
berghofe@12436
   938
  by (blast, blast, blast, blast, blast, rules+)
wenzelm@13421
   939
wenzelm@12281
   940
lemma imp_cong: "(P = P') ==> (P' ==> (Q = Q')) ==> ((P --> Q) = (P' --> Q'))"
wenzelm@12354
   941
  by rules
wenzelm@12281
   942
wenzelm@12281
   943
lemma ex_simps:
wenzelm@12281
   944
  "!!P Q. (EX x. P x & Q)   = ((EX x. P x) & Q)"
wenzelm@12281
   945
  "!!P Q. (EX x. P & Q x)   = (P & (EX x. Q x))"
wenzelm@12281
   946
  "!!P Q. (EX x. P x | Q)   = ((EX x. P x) | Q)"
wenzelm@12281
   947
  "!!P Q. (EX x. P | Q x)   = (P | (EX x. Q x))"
wenzelm@12281
   948
  "!!P Q. (EX x. P x --> Q) = ((ALL x. P x) --> Q)"
wenzelm@12281
   949
  "!!P Q. (EX x. P --> Q x) = (P --> (EX x. Q x))"
wenzelm@12281
   950
  -- {* Miniscoping: pushing in existential quantifiers. *}
berghofe@12436
   951
  by (rules | blast)+
wenzelm@12281
   952
wenzelm@12281
   953
lemma all_simps:
wenzelm@12281
   954
  "!!P Q. (ALL x. P x & Q)   = ((ALL x. P x) & Q)"
wenzelm@12281
   955
  "!!P Q. (ALL x. P & Q x)   = (P & (ALL x. Q x))"
wenzelm@12281
   956
  "!!P Q. (ALL x. P x | Q)   = ((ALL x. P x) | Q)"
wenzelm@12281
   957
  "!!P Q. (ALL x. P | Q x)   = (P | (ALL x. Q x))"
wenzelm@12281
   958
  "!!P Q. (ALL x. P x --> Q) = ((EX x. P x) --> Q)"
wenzelm@12281
   959
  "!!P Q. (ALL x. P --> Q x) = (P --> (ALL x. Q x))"
wenzelm@12281
   960
  -- {* Miniscoping: pushing in universal quantifiers. *}
berghofe@12436
   961
  by (rules | blast)+
wenzelm@12281
   962
paulson@14201
   963
lemma disj_absorb: "(A | A) = A"
paulson@14201
   964
  by blast
paulson@14201
   965
paulson@14201
   966
lemma disj_left_absorb: "(A | (A | B)) = (A | B)"
paulson@14201
   967
  by blast
paulson@14201
   968
paulson@14201
   969
lemma conj_absorb: "(A & A) = A"
paulson@14201
   970
  by blast
paulson@14201
   971
paulson@14201
   972
lemma conj_left_absorb: "(A & (A & B)) = (A & B)"
paulson@14201
   973
  by blast
paulson@14201
   974
wenzelm@12281
   975
lemma eq_ac:
wenzelm@12937
   976
  shows eq_commute: "(a=b) = (b=a)"
wenzelm@12937
   977
    and eq_left_commute: "(P=(Q=R)) = (Q=(P=R))"
wenzelm@12937
   978
    and eq_assoc: "((P=Q)=R) = (P=(Q=R))" by (rules, blast+)
berghofe@12436
   979
lemma neq_commute: "(a~=b) = (b~=a)" by rules
wenzelm@12281
   980
wenzelm@12281
   981
lemma conj_comms:
wenzelm@12937
   982
  shows conj_commute: "(P&Q) = (Q&P)"
wenzelm@12937
   983
    and conj_left_commute: "(P&(Q&R)) = (Q&(P&R))" by rules+
berghofe@12436
   984
lemma conj_assoc: "((P&Q)&R) = (P&(Q&R))" by rules
wenzelm@12281
   985
wenzelm@12281
   986
lemma disj_comms:
wenzelm@12937
   987
  shows disj_commute: "(P|Q) = (Q|P)"
wenzelm@12937
   988
    and disj_left_commute: "(P|(Q|R)) = (Q|(P|R))" by rules+
berghofe@12436
   989
lemma disj_assoc: "((P|Q)|R) = (P|(Q|R))" by rules
wenzelm@12281
   990
berghofe@12436
   991
lemma conj_disj_distribL: "(P&(Q|R)) = (P&Q | P&R)" by rules
berghofe@12436
   992
lemma conj_disj_distribR: "((P|Q)&R) = (P&R | Q&R)" by rules
wenzelm@12281
   993
berghofe@12436
   994
lemma disj_conj_distribL: "(P|(Q&R)) = ((P|Q) & (P|R))" by rules
berghofe@12436
   995
lemma disj_conj_distribR: "((P&Q)|R) = ((P|R) & (Q|R))" by rules
wenzelm@12281
   996
berghofe@12436
   997
lemma imp_conjR: "(P --> (Q&R)) = ((P-->Q) & (P-->R))" by rules
berghofe@12436
   998
lemma imp_conjL: "((P&Q) -->R)  = (P --> (Q --> R))" by rules
berghofe@12436
   999
lemma imp_disjL: "((P|Q) --> R) = ((P-->R)&(Q-->R))" by rules
wenzelm@12281
  1000
wenzelm@12281
  1001
text {* These two are specialized, but @{text imp_disj_not1} is useful in @{text "Auth/Yahalom"}. *}
wenzelm@12281
  1002
lemma imp_disj_not1: "(P --> Q | R) = (~Q --> P --> R)" by blast
wenzelm@12281
  1003
lemma imp_disj_not2: "(P --> Q | R) = (~R --> P --> Q)" by blast
wenzelm@12281
  1004
wenzelm@12281
  1005
lemma imp_disj1: "((P-->Q)|R) = (P--> Q|R)" by blast
wenzelm@12281
  1006
lemma imp_disj2: "(Q|(P-->R)) = (P--> Q|R)" by blast
wenzelm@12281
  1007
berghofe@12436
  1008
lemma de_Morgan_disj: "(~(P | Q)) = (~P & ~Q)" by rules
wenzelm@12281
  1009
lemma de_Morgan_conj: "(~(P & Q)) = (~P | ~Q)" by blast
wenzelm@12281
  1010
lemma not_imp: "(~(P --> Q)) = (P & ~Q)" by blast
wenzelm@12281
  1011
lemma not_iff: "(P~=Q) = (P = (~Q))" by blast
wenzelm@12281
  1012
lemma disj_not1: "(~P | Q) = (P --> Q)" by blast
wenzelm@12281
  1013
lemma disj_not2: "(P | ~Q) = (Q --> P)"  -- {* changes orientation :-( *}
wenzelm@12281
  1014
  by blast
wenzelm@12281
  1015
lemma imp_conv_disj: "(P --> Q) = ((~P) | Q)" by blast
wenzelm@12281
  1016
berghofe@12436
  1017
lemma iff_conv_conj_imp: "(P = Q) = ((P --> Q) & (Q --> P))" by rules
wenzelm@12281
  1018
wenzelm@12281
  1019
wenzelm@12281
  1020
lemma cases_simp: "((P --> Q) & (~P --> Q)) = Q"
wenzelm@12281
  1021
  -- {* Avoids duplication of subgoals after @{text split_if}, when the true and false *}
wenzelm@12281
  1022
  -- {* cases boil down to the same thing. *}
wenzelm@12281
  1023
  by blast
wenzelm@12281
  1024
wenzelm@12281
  1025
lemma not_all: "(~ (! x. P(x))) = (? x.~P(x))" by blast
wenzelm@12281
  1026
lemma imp_all: "((! x. P x) --> Q) = (? x. P x --> Q)" by blast
berghofe@12436
  1027
lemma not_ex: "(~ (? x. P(x))) = (! x.~P(x))" by rules
berghofe@12436
  1028
lemma imp_ex: "((? x. P x) --> Q) = (! x. P x --> Q)" by rules
wenzelm@12281
  1029
berghofe@12436
  1030
lemma ex_disj_distrib: "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))" by rules
berghofe@12436
  1031
lemma all_conj_distrib: "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))" by rules
wenzelm@12281
  1032
wenzelm@12281
  1033
text {*
wenzelm@12281
  1034
  \medskip The @{text "&"} congruence rule: not included by default!
wenzelm@12281
  1035
  May slow rewrite proofs down by as much as 50\% *}
wenzelm@12281
  1036
wenzelm@12281
  1037
lemma conj_cong:
wenzelm@12281
  1038
    "(P = P') ==> (P' ==> (Q = Q')) ==> ((P & Q) = (P' & Q'))"
wenzelm@12354
  1039
  by rules
wenzelm@12281
  1040
wenzelm@12281
  1041
lemma rev_conj_cong:
wenzelm@12281
  1042
    "(Q = Q') ==> (Q' ==> (P = P')) ==> ((P & Q) = (P' & Q'))"
wenzelm@12354
  1043
  by rules
wenzelm@12281
  1044
wenzelm@12281
  1045
text {* The @{text "|"} congruence rule: not included by default! *}
wenzelm@12281
  1046
wenzelm@12281
  1047
lemma disj_cong:
wenzelm@12281
  1048
    "(P = P') ==> (~P' ==> (Q = Q')) ==> ((P | Q) = (P' | Q'))"
wenzelm@12281
  1049
  by blast
wenzelm@12281
  1050
wenzelm@12281
  1051
lemma eq_sym_conv: "(x = y) = (y = x)"
wenzelm@12354
  1052
  by rules
wenzelm@12281
  1053
wenzelm@12281
  1054
wenzelm@12281
  1055
text {* \medskip if-then-else rules *}
wenzelm@12281
  1056
wenzelm@12281
  1057
lemma if_True: "(if True then x else y) = x"
wenzelm@12281
  1058
  by (unfold if_def) blast
wenzelm@12281
  1059
wenzelm@12281
  1060
lemma if_False: "(if False then x else y) = y"
wenzelm@12281
  1061
  by (unfold if_def) blast
wenzelm@12281
  1062
wenzelm@12281
  1063
lemma if_P: "P ==> (if P then x else y) = x"
wenzelm@12281
  1064
  by (unfold if_def) blast
wenzelm@12281
  1065
wenzelm@12281
  1066
lemma if_not_P: "~P ==> (if P then x else y) = y"
wenzelm@12281
  1067
  by (unfold if_def) blast
wenzelm@12281
  1068
wenzelm@12281
  1069
lemma split_if: "P (if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))"
wenzelm@12281
  1070
  apply (rule case_split [of Q])
wenzelm@12281
  1071
   apply (subst if_P)
paulson@14208
  1072
    prefer 3 apply (subst if_not_P, blast+)
wenzelm@12281
  1073
  done
wenzelm@12281
  1074
wenzelm@12281
  1075
lemma split_if_asm: "P (if Q then x else y) = (~((Q & ~P x) | (~Q & ~P y)))"
paulson@14208
  1076
by (subst split_if, blast)
wenzelm@12281
  1077
wenzelm@12281
  1078
lemmas if_splits = split_if split_if_asm
wenzelm@12281
  1079
wenzelm@12281
  1080
lemma if_def2: "(if Q then x else y) = ((Q --> x) & (~ Q --> y))"
wenzelm@12281
  1081
  by (rule split_if)
wenzelm@12281
  1082
wenzelm@12281
  1083
lemma if_cancel: "(if c then x else x) = x"
paulson@14208
  1084
by (subst split_if, blast)
wenzelm@12281
  1085
wenzelm@12281
  1086
lemma if_eq_cancel: "(if x = y then y else x) = x"
paulson@14208
  1087
by (subst split_if, blast)
wenzelm@12281
  1088
wenzelm@12281
  1089
lemma if_bool_eq_conj: "(if P then Q else R) = ((P-->Q) & (~P-->R))"
wenzelm@12281
  1090
  -- {* This form is useful for expanding @{text if}s on the RIGHT of the @{text "==>"} symbol. *}
wenzelm@12281
  1091
  by (rule split_if)
wenzelm@12281
  1092
wenzelm@12281
  1093
lemma if_bool_eq_disj: "(if P then Q else R) = ((P&Q) | (~P&R))"
wenzelm@12281
  1094
  -- {* And this form is useful for expanding @{text if}s on the LEFT. *}
paulson@14208
  1095
  apply (subst split_if, blast)
wenzelm@12281
  1096
  done
wenzelm@12281
  1097
berghofe@12436
  1098
lemma Eq_TrueI: "P ==> P == True" by (unfold atomize_eq) rules
berghofe@12436
  1099
lemma Eq_FalseI: "~P ==> P == False" by (unfold atomize_eq) rules
wenzelm@12281
  1100
schirmer@15423
  1101
text {* \medskip let rules for simproc *}
schirmer@15423
  1102
schirmer@15423
  1103
lemma Let_folded: "f x \<equiv> g x \<Longrightarrow>  Let x f \<equiv> Let x g"
schirmer@15423
  1104
  by (unfold Let_def)
schirmer@15423
  1105
schirmer@15423
  1106
lemma Let_unfold: "f x \<equiv> g \<Longrightarrow>  Let x f \<equiv> g"
schirmer@15423
  1107
  by (unfold Let_def)
schirmer@15423
  1108
paulson@14201
  1109
subsubsection {* Actual Installation of the Simplifier *}
paulson@14201
  1110
wenzelm@9869
  1111
use "simpdata.ML"
wenzelm@9869
  1112
setup Simplifier.setup
wenzelm@9869
  1113
setup "Simplifier.method_setup Splitter.split_modifiers" setup simpsetup
wenzelm@9869
  1114
setup Splitter.setup setup Clasimp.setup
wenzelm@9869
  1115
paulson@15411
  1116
declare disj_absorb [simp] conj_absorb [simp]
paulson@14201
  1117
nipkow@13723
  1118
lemma ex1_eq[iff]: "EX! x. x = t" "EX! x. t = x"
nipkow@13723
  1119
by blast+
nipkow@13723
  1120
berghofe@13638
  1121
theorem choice_eq: "(ALL x. EX! y. P x y) = (EX! f. ALL x. P x (f x))"
berghofe@13638
  1122
  apply (rule iffI)
berghofe@13638
  1123
  apply (rule_tac a = "%x. THE y. P x y" in ex1I)
berghofe@13638
  1124
  apply (fast dest!: theI')
berghofe@13638
  1125
  apply (fast intro: ext the1_equality [symmetric])
berghofe@13638
  1126
  apply (erule ex1E)
berghofe@13638
  1127
  apply (rule allI)
berghofe@13638
  1128
  apply (rule ex1I)
berghofe@13638
  1129
  apply (erule spec)
berghofe@13638
  1130
  apply (erule_tac x = "%z. if z = x then y else f z" in allE)
berghofe@13638
  1131
  apply (erule impE)
berghofe@13638
  1132
  apply (rule allI)
berghofe@13638
  1133
  apply (rule_tac P = "xa = x" in case_split_thm)
paulson@14208
  1134
  apply (drule_tac [3] x = x in fun_cong, simp_all)
berghofe@13638
  1135
  done
berghofe@13638
  1136
nipkow@13438
  1137
text{*Needs only HOL-lemmas:*}
nipkow@13438
  1138
lemma mk_left_commute:
nipkow@13438
  1139
  assumes a: "\<And>x y z. f (f x y) z = f x (f y z)" and
nipkow@13438
  1140
          c: "\<And>x y. f x y = f y x"
nipkow@13438
  1141
  shows "f x (f y z) = f y (f x z)"
nipkow@13438
  1142
by(rule trans[OF trans[OF c a] arg_cong[OF c, of "f y"]])
nipkow@13438
  1143
wenzelm@11750
  1144
wenzelm@11824
  1145
subsubsection {* Generic cases and induction *}
wenzelm@11824
  1146
wenzelm@11824
  1147
constdefs
wenzelm@11989
  1148
  induct_forall :: "('a => bool) => bool"
wenzelm@11989
  1149
  "induct_forall P == \<forall>x. P x"
wenzelm@11989
  1150
  induct_implies :: "bool => bool => bool"
wenzelm@11989
  1151
  "induct_implies A B == A --> B"
wenzelm@11989
  1152
  induct_equal :: "'a => 'a => bool"
wenzelm@11989
  1153
  "induct_equal x y == x = y"
wenzelm@11989
  1154
  induct_conj :: "bool => bool => bool"
wenzelm@11989
  1155
  "induct_conj A B == A & B"
wenzelm@11824
  1156
wenzelm@11989
  1157
lemma induct_forall_eq: "(!!x. P x) == Trueprop (induct_forall (\<lambda>x. P x))"
wenzelm@11989
  1158
  by (simp only: atomize_all induct_forall_def)
wenzelm@11824
  1159
wenzelm@11989
  1160
lemma induct_implies_eq: "(A ==> B) == Trueprop (induct_implies A B)"
wenzelm@11989
  1161
  by (simp only: atomize_imp induct_implies_def)
wenzelm@11824
  1162
wenzelm@11989
  1163
lemma induct_equal_eq: "(x == y) == Trueprop (induct_equal x y)"
wenzelm@11989
  1164
  by (simp only: atomize_eq induct_equal_def)
wenzelm@11824
  1165
wenzelm@11989
  1166
lemma induct_forall_conj: "induct_forall (\<lambda>x. induct_conj (A x) (B x)) =
wenzelm@11989
  1167
    induct_conj (induct_forall A) (induct_forall B)"
wenzelm@12354
  1168
  by (unfold induct_forall_def induct_conj_def) rules
wenzelm@11824
  1169
wenzelm@11989
  1170
lemma induct_implies_conj: "induct_implies C (induct_conj A B) =
wenzelm@11989
  1171
    induct_conj (induct_implies C A) (induct_implies C B)"
wenzelm@12354
  1172
  by (unfold induct_implies_def induct_conj_def) rules
wenzelm@11989
  1173
berghofe@13598
  1174
lemma induct_conj_curry: "(induct_conj A B ==> PROP C) == (A ==> B ==> PROP C)"
berghofe@13598
  1175
proof
berghofe@13598
  1176
  assume r: "induct_conj A B ==> PROP C" and A B
berghofe@13598
  1177
  show "PROP C" by (rule r) (simp! add: induct_conj_def)
berghofe@13598
  1178
next
berghofe@13598
  1179
  assume r: "A ==> B ==> PROP C" and "induct_conj A B"
berghofe@13598
  1180
  show "PROP C" by (rule r) (simp! add: induct_conj_def)+
berghofe@13598
  1181
qed
wenzelm@11824
  1182
wenzelm@11989
  1183
lemma induct_impliesI: "(A ==> B) ==> induct_implies A B"
wenzelm@11989
  1184
  by (simp add: induct_implies_def)
wenzelm@11824
  1185
wenzelm@12161
  1186
lemmas induct_atomize = atomize_conj induct_forall_eq induct_implies_eq induct_equal_eq
wenzelm@12161
  1187
lemmas induct_rulify1 [symmetric, standard] = induct_forall_eq induct_implies_eq induct_equal_eq
wenzelm@12161
  1188
lemmas induct_rulify2 = induct_forall_def induct_implies_def induct_equal_def induct_conj_def
wenzelm@11989
  1189
lemmas induct_conj = induct_forall_conj induct_implies_conj induct_conj_curry
wenzelm@11824
  1190
wenzelm@11989
  1191
hide const induct_forall induct_implies induct_equal induct_conj
wenzelm@11824
  1192
wenzelm@11824
  1193
wenzelm@11824
  1194
text {* Method setup. *}
wenzelm@11824
  1195
wenzelm@11824
  1196
ML {*
wenzelm@11824
  1197
  structure InductMethod = InductMethodFun
wenzelm@11824
  1198
  (struct
paulson@15411
  1199
    val dest_concls = HOLogic.dest_concls
paulson@15411
  1200
    val cases_default = thm "case_split"
paulson@15411
  1201
    val local_impI = thm "induct_impliesI"
paulson@15411
  1202
    val conjI = thm "conjI"
paulson@15411
  1203
    val atomize = thms "induct_atomize"
paulson@15411
  1204
    val rulify1 = thms "induct_rulify1"
paulson@15411
  1205
    val rulify2 = thms "induct_rulify2"
paulson@15411
  1206
    val localize = [Thm.symmetric (thm "induct_implies_def")]
wenzelm@11824
  1207
  end);
wenzelm@11824
  1208
*}
wenzelm@11824
  1209
wenzelm@11824
  1210
setup InductMethod.setup
wenzelm@11824
  1211
wenzelm@11824
  1212
wenzelm@11750
  1213
subsection {* Order signatures and orders *}
wenzelm@11750
  1214
wenzelm@11750
  1215
axclass
wenzelm@12338
  1216
  ord < type
wenzelm@11750
  1217
wenzelm@11750
  1218
syntax
wenzelm@11750
  1219
  "op <"        :: "['a::ord, 'a] => bool"             ("op <")
wenzelm@11750
  1220
  "op <="       :: "['a::ord, 'a] => bool"             ("op <=")
wenzelm@11750
  1221
wenzelm@11750
  1222
global
wenzelm@11750
  1223
wenzelm@11750
  1224
consts
wenzelm@11750
  1225
  "op <"        :: "['a::ord, 'a] => bool"             ("(_/ < _)"  [50, 51] 50)
wenzelm@11750
  1226
  "op <="       :: "['a::ord, 'a] => bool"             ("(_/ <= _)" [50, 51] 50)
wenzelm@11750
  1227
wenzelm@11750
  1228
local
wenzelm@11750
  1229
wenzelm@12114
  1230
syntax (xsymbols)
wenzelm@11750
  1231
  "op <="       :: "['a::ord, 'a] => bool"             ("op \<le>")
wenzelm@11750
  1232
  "op <="       :: "['a::ord, 'a] => bool"             ("(_/ \<le> _)"  [50, 51] 50)
wenzelm@11750
  1233
kleing@14565
  1234
syntax (HTML output)
kleing@14565
  1235
  "op <="       :: "['a::ord, 'a] => bool"             ("op \<le>")
kleing@14565
  1236
  "op <="       :: "['a::ord, 'a] => bool"             ("(_/ \<le> _)"  [50, 51] 50)
kleing@14565
  1237
nipkow@15354
  1238
text{* Syntactic sugar: *}
wenzelm@11750
  1239
nipkow@15354
  1240
consts
nipkow@15354
  1241
  "_gt" :: "'a::ord => 'a => bool"             (infixl ">" 50)
nipkow@15354
  1242
  "_ge" :: "'a::ord => 'a => bool"             (infixl ">=" 50)
nipkow@15354
  1243
translations
nipkow@15354
  1244
  "x > y"  => "y < x"
nipkow@15354
  1245
  "x >= y" => "y <= x"
nipkow@15354
  1246
nipkow@15354
  1247
syntax (xsymbols)
nipkow@15354
  1248
  "_ge"       :: "'a::ord => 'a => bool"             (infixl "\<ge>" 50)
nipkow@15354
  1249
nipkow@15354
  1250
syntax (HTML output)
nipkow@15354
  1251
  "_ge"       :: "['a::ord, 'a] => bool"             (infixl "\<ge>" 50)
nipkow@15354
  1252
paulson@14295
  1253
wenzelm@11750
  1254
subsubsection {* Monotonicity *}
wenzelm@11750
  1255
wenzelm@13412
  1256
locale mono =
wenzelm@13412
  1257
  fixes f
wenzelm@13412
  1258
  assumes mono: "A <= B ==> f A <= f B"
wenzelm@11750
  1259
wenzelm@13421
  1260
lemmas monoI [intro?] = mono.intro
wenzelm@13412
  1261
  and monoD [dest?] = mono.mono
wenzelm@11750
  1262
wenzelm@11750
  1263
constdefs
wenzelm@11750
  1264
  min :: "['a::ord, 'a] => 'a"
wenzelm@11750
  1265
  "min a b == (if a <= b then a else b)"
wenzelm@11750
  1266
  max :: "['a::ord, 'a] => 'a"
wenzelm@11750
  1267
  "max a b == (if a <= b then b else a)"
wenzelm@11750
  1268
wenzelm@11750
  1269
lemma min_leastL: "(!!x. least <= x) ==> min least x = least"
wenzelm@11750
  1270
  by (simp add: min_def)
wenzelm@11750
  1271
wenzelm@11750
  1272
lemma min_of_mono:
wenzelm@11750
  1273
    "ALL x y. (f x <= f y) = (x <= y) ==> min (f m) (f n) = f (min m n)"
wenzelm@11750
  1274
  by (simp add: min_def)
wenzelm@11750
  1275
wenzelm@11750
  1276
lemma max_leastL: "(!!x. least <= x) ==> max least x = x"
wenzelm@11750
  1277
  by (simp add: max_def)
wenzelm@11750
  1278
wenzelm@11750
  1279
lemma max_of_mono:
wenzelm@11750
  1280
    "ALL x y. (f x <= f y) = (x <= y) ==> max (f m) (f n) = f (max m n)"
wenzelm@11750
  1281
  by (simp add: max_def)
wenzelm@11750
  1282
wenzelm@11750
  1283
wenzelm@11750
  1284
subsubsection "Orders"
wenzelm@11750
  1285
wenzelm@11750
  1286
axclass order < ord
wenzelm@11750
  1287
  order_refl [iff]: "x <= x"
wenzelm@11750
  1288
  order_trans: "x <= y ==> y <= z ==> x <= z"
wenzelm@11750
  1289
  order_antisym: "x <= y ==> y <= x ==> x = y"
wenzelm@11750
  1290
  order_less_le: "(x < y) = (x <= y & x ~= y)"
wenzelm@11750
  1291
wenzelm@11750
  1292
wenzelm@11750
  1293
text {* Reflexivity. *}
wenzelm@11750
  1294
wenzelm@11750
  1295
lemma order_eq_refl: "!!x::'a::order. x = y ==> x <= y"
wenzelm@11750
  1296
    -- {* This form is useful with the classical reasoner. *}
wenzelm@11750
  1297
  apply (erule ssubst)
wenzelm@11750
  1298
  apply (rule order_refl)
wenzelm@11750
  1299
  done
wenzelm@11750
  1300
nipkow@13553
  1301
lemma order_less_irrefl [iff]: "~ x < (x::'a::order)"
wenzelm@11750
  1302
  by (simp add: order_less_le)
wenzelm@11750
  1303
wenzelm@11750
  1304
lemma order_le_less: "((x::'a::order) <= y) = (x < y | x = y)"
wenzelm@11750
  1305
    -- {* NOT suitable for iff, since it can cause PROOF FAILED. *}
paulson@14208
  1306
  apply (simp add: order_less_le, blast)
wenzelm@11750
  1307
  done
wenzelm@11750
  1308
wenzelm@11750
  1309
lemmas order_le_imp_less_or_eq = order_le_less [THEN iffD1, standard]
wenzelm@11750
  1310
wenzelm@11750
  1311
lemma order_less_imp_le: "!!x::'a::order. x < y ==> x <= y"
wenzelm@11750
  1312
  by (simp add: order_less_le)
wenzelm@11750
  1313
wenzelm@11750
  1314
wenzelm@11750
  1315
text {* Asymmetry. *}
wenzelm@11750
  1316
wenzelm@11750
  1317
lemma order_less_not_sym: "(x::'a::order) < y ==> ~ (y < x)"
wenzelm@11750
  1318
  by (simp add: order_less_le order_antisym)
wenzelm@11750
  1319
wenzelm@11750
  1320
lemma order_less_asym: "x < (y::'a::order) ==> (~P ==> y < x) ==> P"
wenzelm@11750
  1321
  apply (drule order_less_not_sym)
paulson@14208
  1322
  apply (erule contrapos_np, simp)
wenzelm@11750
  1323
  done
wenzelm@11750
  1324
paulson@15411
  1325
lemma order_eq_iff: "!!x::'a::order. (x = y) = (x \<le> y & y \<le> x)"
paulson@14295
  1326
by (blast intro: order_antisym)
paulson@14295
  1327
nipkow@15197
  1328
lemma order_antisym_conv: "(y::'a::order) <= x ==> (x <= y) = (x = y)"
nipkow@15197
  1329
by(blast intro:order_antisym)
wenzelm@11750
  1330
wenzelm@11750
  1331
text {* Transitivity. *}
wenzelm@11750
  1332
wenzelm@11750
  1333
lemma order_less_trans: "!!x::'a::order. [| x < y; y < z |] ==> x < z"
wenzelm@11750
  1334
  apply (simp add: order_less_le)
wenzelm@11750
  1335
  apply (blast intro: order_trans order_antisym)
wenzelm@11750
  1336
  done
wenzelm@11750
  1337
wenzelm@11750
  1338
lemma order_le_less_trans: "!!x::'a::order. [| x <= y; y < z |] ==> x < z"
wenzelm@11750
  1339
  apply (simp add: order_less_le)
wenzelm@11750
  1340
  apply (blast intro: order_trans order_antisym)
wenzelm@11750
  1341
  done
wenzelm@11750
  1342
wenzelm@11750
  1343
lemma order_less_le_trans: "!!x::'a::order. [| x < y; y <= z |] ==> x < z"
wenzelm@11750
  1344
  apply (simp add: order_less_le)
wenzelm@11750
  1345
  apply (blast intro: order_trans order_antisym)
wenzelm@11750
  1346
  done
wenzelm@11750
  1347
wenzelm@11750
  1348
wenzelm@11750
  1349
text {* Useful for simplification, but too risky to include by default. *}
wenzelm@11750
  1350
wenzelm@11750
  1351
lemma order_less_imp_not_less: "(x::'a::order) < y ==>  (~ y < x) = True"
wenzelm@11750
  1352
  by (blast elim: order_less_asym)
wenzelm@11750
  1353
wenzelm@11750
  1354
lemma order_less_imp_triv: "(x::'a::order) < y ==>  (y < x --> P) = True"
wenzelm@11750
  1355
  by (blast elim: order_less_asym)
wenzelm@11750
  1356
wenzelm@11750
  1357
lemma order_less_imp_not_eq: "(x::'a::order) < y ==>  (x = y) = False"
wenzelm@11750
  1358
  by auto
wenzelm@11750
  1359
wenzelm@11750
  1360
lemma order_less_imp_not_eq2: "(x::'a::order) < y ==>  (y = x) = False"
wenzelm@11750
  1361
  by auto
wenzelm@11750
  1362
wenzelm@11750
  1363
wenzelm@11750
  1364
text {* Other operators. *}
wenzelm@11750
  1365
wenzelm@11750
  1366
lemma min_leastR: "(!!x::'a::order. least <= x) ==> min x least = least"
wenzelm@11750
  1367
  apply (simp add: min_def)
wenzelm@11750
  1368
  apply (blast intro: order_antisym)
wenzelm@11750
  1369
  done
wenzelm@11750
  1370
wenzelm@11750
  1371
lemma max_leastR: "(!!x::'a::order. least <= x) ==> max x least = x"
wenzelm@11750
  1372
  apply (simp add: max_def)
wenzelm@11750
  1373
  apply (blast intro: order_antisym)
wenzelm@11750
  1374
  done
wenzelm@11750
  1375
wenzelm@11750
  1376
wenzelm@11750
  1377
subsubsection {* Least value operator *}
wenzelm@11750
  1378
wenzelm@11750
  1379
constdefs
wenzelm@11750
  1380
  Least :: "('a::ord => bool) => 'a"               (binder "LEAST " 10)
wenzelm@11750
  1381
  "Least P == THE x. P x & (ALL y. P y --> x <= y)"
wenzelm@11750
  1382
    -- {* We can no longer use LeastM because the latter requires Hilbert-AC. *}
wenzelm@11750
  1383
wenzelm@11750
  1384
lemma LeastI2:
wenzelm@11750
  1385
  "[| P (x::'a::order);
wenzelm@11750
  1386
      !!y. P y ==> x <= y;
wenzelm@11750
  1387
      !!x. [| P x; ALL y. P y --> x \<le> y |] ==> Q x |]
wenzelm@12281
  1388
   ==> Q (Least P)"
wenzelm@11750
  1389
  apply (unfold Least_def)
wenzelm@11750
  1390
  apply (rule theI2)
wenzelm@11750
  1391
    apply (blast intro: order_antisym)+
wenzelm@11750
  1392
  done
wenzelm@11750
  1393
wenzelm@11750
  1394
lemma Least_equality:
wenzelm@12281
  1395
    "[| P (k::'a::order); !!x. P x ==> k <= x |] ==> (LEAST x. P x) = k"
wenzelm@11750
  1396
  apply (simp add: Least_def)
wenzelm@11750
  1397
  apply (rule the_equality)
wenzelm@11750
  1398
  apply (auto intro!: order_antisym)
wenzelm@11750
  1399
  done
wenzelm@11750
  1400
wenzelm@11750
  1401
wenzelm@11750
  1402
subsubsection "Linear / total orders"
wenzelm@11750
  1403
wenzelm@11750
  1404
axclass linorder < order
wenzelm@11750
  1405
  linorder_linear: "x <= y | y <= x"
wenzelm@11750
  1406
wenzelm@11750
  1407
lemma linorder_less_linear: "!!x::'a::linorder. x<y | x=y | y<x"
wenzelm@11750
  1408
  apply (simp add: order_less_le)
paulson@14208
  1409
  apply (insert linorder_linear, blast)
wenzelm@11750
  1410
  done
wenzelm@11750
  1411
paulson@15079
  1412
lemma linorder_le_less_linear: "!!x::'a::linorder. x\<le>y | y<x"
paulson@15079
  1413
  by (simp add: order_le_less linorder_less_linear)
paulson@15079
  1414
paulson@14365
  1415
lemma linorder_le_cases [case_names le ge]:
paulson@14365
  1416
    "((x::'a::linorder) \<le> y ==> P) ==> (y \<le> x ==> P) ==> P"
paulson@14365
  1417
  by (insert linorder_linear, blast)
paulson@14365
  1418
wenzelm@11750
  1419
lemma linorder_cases [case_names less equal greater]:
wenzelm@11750
  1420
    "((x::'a::linorder) < y ==> P) ==> (x = y ==> P) ==> (y < x ==> P) ==> P"
paulson@14365
  1421
  by (insert linorder_less_linear, blast)
wenzelm@11750
  1422
wenzelm@11750
  1423
lemma linorder_not_less: "!!x::'a::linorder. (~ x < y) = (y <= x)"
wenzelm@11750
  1424
  apply (simp add: order_less_le)
wenzelm@11750
  1425
  apply (insert linorder_linear)
wenzelm@11750
  1426
  apply (blast intro: order_antisym)
wenzelm@11750
  1427
  done
wenzelm@11750
  1428
wenzelm@11750
  1429
lemma linorder_not_le: "!!x::'a::linorder. (~ x <= y) = (y < x)"
wenzelm@11750
  1430
  apply (simp add: order_less_le)
wenzelm@11750
  1431
  apply (insert linorder_linear)
wenzelm@11750
  1432
  apply (blast intro: order_antisym)
wenzelm@11750
  1433
  done
wenzelm@11750
  1434
wenzelm@11750
  1435
lemma linorder_neq_iff: "!!x::'a::linorder. (x ~= y) = (x<y | y<x)"
paulson@14208
  1436
by (cut_tac x = x and y = y in linorder_less_linear, auto)
wenzelm@11750
  1437
wenzelm@11750
  1438
lemma linorder_neqE: "x ~= (y::'a::linorder) ==> (x < y ==> R) ==> (y < x ==> R) ==> R"
paulson@14208
  1439
by (simp add: linorder_neq_iff, blast)
wenzelm@11750
  1440
nipkow@15197
  1441
lemma linorder_antisym_conv1: "~ (x::'a::linorder) < y ==> (x <= y) = (x = y)"
nipkow@15197
  1442
by(blast intro:order_antisym dest:linorder_not_less[THEN iffD1])
nipkow@15197
  1443
nipkow@15197
  1444
lemma linorder_antisym_conv2: "(x::'a::linorder) <= y ==> (~ x < y) = (x = y)"
nipkow@15197
  1445
by(blast intro:order_antisym dest:linorder_not_less[THEN iffD1])
nipkow@15197
  1446
nipkow@15197
  1447
lemma linorder_antisym_conv3: "~ (y::'a::linorder) < x ==> (~ x < y) = (x = y)"
nipkow@15197
  1448
by(blast intro:order_antisym dest:linorder_not_less[THEN iffD1])
nipkow@15197
  1449
nipkow@15197
  1450
use "antisym_setup.ML";
nipkow@15197
  1451
setup antisym_setup
wenzelm@11750
  1452
wenzelm@11750
  1453
subsubsection "Min and max on (linear) orders"
wenzelm@11750
  1454
wenzelm@11750
  1455
lemma min_same [simp]: "min (x::'a::order) x = x"
wenzelm@11750
  1456
  by (simp add: min_def)
wenzelm@11750
  1457
wenzelm@11750
  1458
lemma max_same [simp]: "max (x::'a::order) x = x"
wenzelm@11750
  1459
  by (simp add: max_def)
wenzelm@11750
  1460
wenzelm@11750
  1461
lemma le_max_iff_disj: "!!z::'a::linorder. (z <= max x y) = (z <= x | z <= y)"
wenzelm@11750
  1462
  apply (simp add: max_def)
wenzelm@11750
  1463
  apply (insert linorder_linear)
wenzelm@11750
  1464
  apply (blast intro: order_trans)
wenzelm@11750
  1465
  done
wenzelm@11750
  1466
wenzelm@11750
  1467
lemma le_maxI1: "(x::'a::linorder) <= max x y"
wenzelm@11750
  1468
  by (simp add: le_max_iff_disj)
wenzelm@11750
  1469
wenzelm@11750
  1470
lemma le_maxI2: "(y::'a::linorder) <= max x y"
wenzelm@11750
  1471
    -- {* CANNOT use with @{text "[intro!]"} because blast will give PROOF FAILED. *}
wenzelm@11750
  1472
  by (simp add: le_max_iff_disj)
wenzelm@11750
  1473
wenzelm@11750
  1474
lemma less_max_iff_disj: "!!z::'a::linorder. (z < max x y) = (z < x | z < y)"
wenzelm@11750
  1475
  apply (simp add: max_def order_le_less)
wenzelm@11750
  1476
  apply (insert linorder_less_linear)
wenzelm@11750
  1477
  apply (blast intro: order_less_trans)
wenzelm@11750
  1478
  done
wenzelm@11750
  1479
wenzelm@11750
  1480
lemma max_le_iff_conj [simp]:
wenzelm@11750
  1481
    "!!z::'a::linorder. (max x y <= z) = (x <= z & y <= z)"
wenzelm@11750
  1482
  apply (simp add: max_def)
wenzelm@11750
  1483
  apply (insert linorder_linear)
wenzelm@11750
  1484
  apply (blast intro: order_trans)
wenzelm@11750
  1485
  done
wenzelm@11750
  1486
wenzelm@11750
  1487
lemma max_less_iff_conj [simp]:
wenzelm@11750
  1488
    "!!z::'a::linorder. (max x y < z) = (x < z & y < z)"
wenzelm@11750
  1489
  apply (simp add: order_le_less max_def)
wenzelm@11750
  1490
  apply (insert linorder_less_linear)
wenzelm@11750
  1491
  apply (blast intro: order_less_trans)
wenzelm@11750
  1492
  done
wenzelm@11750
  1493
wenzelm@11750
  1494
lemma le_min_iff_conj [simp]:
wenzelm@11750
  1495
    "!!z::'a::linorder. (z <= min x y) = (z <= x & z <= y)"
wenzelm@12892
  1496
    -- {* @{text "[iff]"} screws up a @{text blast} in MiniML *}
wenzelm@11750
  1497
  apply (simp add: min_def)
wenzelm@11750
  1498
  apply (insert linorder_linear)
wenzelm@11750
  1499
  apply (blast intro: order_trans)
wenzelm@11750
  1500
  done
wenzelm@11750
  1501
wenzelm@11750
  1502
lemma min_less_iff_conj [simp]:
wenzelm@11750
  1503
    "!!z::'a::linorder. (z < min x y) = (z < x & z < y)"
wenzelm@11750
  1504
  apply (simp add: order_le_less min_def)
wenzelm@11750
  1505
  apply (insert linorder_less_linear)
wenzelm@11750
  1506
  apply (blast intro: order_less_trans)
wenzelm@11750
  1507
  done
wenzelm@11750
  1508
wenzelm@11750
  1509
lemma min_le_iff_disj: "!!z::'a::linorder. (min x y <= z) = (x <= z | y <= z)"
wenzelm@11750
  1510
  apply (simp add: min_def)
wenzelm@11750
  1511
  apply (insert linorder_linear)
wenzelm@11750
  1512
  apply (blast intro: order_trans)
wenzelm@11750
  1513
  done
wenzelm@11750
  1514
wenzelm@11750
  1515
lemma min_less_iff_disj: "!!z::'a::linorder. (min x y < z) = (x < z | y < z)"
wenzelm@11750
  1516
  apply (simp add: min_def order_le_less)
wenzelm@11750
  1517
  apply (insert linorder_less_linear)
wenzelm@11750
  1518
  apply (blast intro: order_less_trans)
wenzelm@11750
  1519
  done
wenzelm@11750
  1520
nipkow@13438
  1521
lemma max_assoc: "!!x::'a::linorder. max (max x y) z = max x (max y z)"
nipkow@13438
  1522
apply(simp add:max_def)
nipkow@13438
  1523
apply(rule conjI)
nipkow@13438
  1524
apply(blast intro:order_trans)
nipkow@13438
  1525
apply(simp add:linorder_not_le)
nipkow@13438
  1526
apply(blast dest: order_less_trans order_le_less_trans)
nipkow@13438
  1527
done
nipkow@13438
  1528
nipkow@13438
  1529
lemma max_commute: "!!x::'a::linorder. max x y = max y x"
nipkow@13438
  1530
apply(simp add:max_def)
nipkow@13438
  1531
apply(simp add:linorder_not_le)
nipkow@13438
  1532
apply(blast dest: order_less_trans)
nipkow@13438
  1533
done
nipkow@13438
  1534
nipkow@13438
  1535
lemmas max_ac = max_assoc max_commute
nipkow@13438
  1536
                mk_left_commute[of max,OF max_assoc max_commute]
nipkow@13438
  1537
nipkow@13438
  1538
lemma min_assoc: "!!x::'a::linorder. min (min x y) z = min x (min y z)"
nipkow@13438
  1539
apply(simp add:min_def)
nipkow@13438
  1540
apply(rule conjI)
nipkow@13438
  1541
apply(blast intro:order_trans)
nipkow@13438
  1542
apply(simp add:linorder_not_le)
nipkow@13438
  1543
apply(blast dest: order_less_trans order_le_less_trans)
nipkow@13438
  1544
done
nipkow@13438
  1545
nipkow@13438
  1546
lemma min_commute: "!!x::'a::linorder. min x y = min y x"
nipkow@13438
  1547
apply(simp add:min_def)
nipkow@13438
  1548
apply(simp add:linorder_not_le)
nipkow@13438
  1549
apply(blast dest: order_less_trans)
nipkow@13438
  1550
done
nipkow@13438
  1551
nipkow@13438
  1552
lemmas min_ac = min_assoc min_commute
nipkow@13438
  1553
                mk_left_commute[of min,OF min_assoc min_commute]
nipkow@13438
  1554
wenzelm@11750
  1555
lemma split_min:
wenzelm@11750
  1556
    "P (min (i::'a::linorder) j) = ((i <= j --> P(i)) & (~ i <= j --> P(j)))"
wenzelm@11750
  1557
  by (simp add: min_def)
wenzelm@11750
  1558
wenzelm@11750
  1559
lemma split_max:
wenzelm@11750
  1560
    "P (max (i::'a::linorder) j) = ((i <= j --> P(j)) & (~ i <= j --> P(i)))"
wenzelm@11750
  1561
  by (simp add: max_def)
wenzelm@11750
  1562
wenzelm@11750
  1563
ballarin@14398
  1564
subsubsection {* Transitivity rules for calculational reasoning *}
ballarin@14398
  1565
ballarin@14398
  1566
ballarin@14398
  1567
lemma order_neq_le_trans: "a ~= b ==> (a::'a::order) <= b ==> a < b"
ballarin@14398
  1568
  by (simp add: order_less_le)
ballarin@14398
  1569
ballarin@14398
  1570
lemma order_le_neq_trans: "(a::'a::order) <= b ==> a ~= b ==> a < b"
ballarin@14398
  1571
  by (simp add: order_less_le)
ballarin@14398
  1572
ballarin@14398
  1573
lemma order_less_asym': "(a::'a::order) < b ==> b < a ==> P"
ballarin@14398
  1574
  by (rule order_less_asym)
ballarin@14398
  1575
ballarin@14398
  1576
ballarin@14444
  1577
subsubsection {* Setup of transitivity reasoner as Solver *}
ballarin@14398
  1578
ballarin@14398
  1579
lemma less_imp_neq: "[| (x::'a::order) < y |] ==> x ~= y"
ballarin@14398
  1580
  by (erule contrapos_pn, erule subst, rule order_less_irrefl)
ballarin@14398
  1581
ballarin@14398
  1582
lemma eq_neq_eq_imp_neq: "[| x = a ; a ~= b; b = y |] ==> x ~= y"
ballarin@14398
  1583
  by (erule subst, erule ssubst, assumption)
ballarin@14398
  1584
ballarin@14398
  1585
ML_setup {*
ballarin@14398
  1586
ballarin@15103
  1587
(* The setting up of Quasi_Tac serves as a demo.  Since there is no
ballarin@15103
  1588
   class for quasi orders, the tactics Quasi_Tac.trans_tac and
ballarin@15103
  1589
   Quasi_Tac.quasi_tac are not of much use. *)
ballarin@15103
  1590
paulson@15288
  1591
fun decomp_gen sort sign (Trueprop $ t) =
paulson@15288
  1592
  let fun of_sort t = Sign.of_sort sign (type_of t, sort)
paulson@15288
  1593
  fun dec (Const ("Not", _) $ t) = (
paulson@15288
  1594
	  case dec t of
paulson@15288
  1595
	    None => None
paulson@15288
  1596
	  | Some (t1, rel, t2) => Some (t1, "~" ^ rel, t2))
paulson@15411
  1597
	| dec (Const ("op =",  _) $ t1 $ t2) =
paulson@15288
  1598
	    if of_sort t1
paulson@15288
  1599
	    then Some (t1, "=", t2)
paulson@15288
  1600
	    else None
paulson@15411
  1601
	| dec (Const ("op <=",  _) $ t1 $ t2) =
paulson@15288
  1602
	    if of_sort t1
paulson@15288
  1603
	    then Some (t1, "<=", t2)
paulson@15288
  1604
	    else None
paulson@15411
  1605
	| dec (Const ("op <",  _) $ t1 $ t2) =
paulson@15288
  1606
	    if of_sort t1
paulson@15288
  1607
	    then Some (t1, "<", t2)
paulson@15288
  1608
	    else None
paulson@15288
  1609
	| dec _ = None
paulson@15288
  1610
  in dec t end;
paulson@15288
  1611
ballarin@15103
  1612
structure Quasi_Tac = Quasi_Tac_Fun (
ballarin@15103
  1613
  struct
ballarin@15103
  1614
    val le_trans = thm "order_trans";
ballarin@15103
  1615
    val le_refl = thm "order_refl";
ballarin@15103
  1616
    val eqD1 = thm "order_eq_refl";
ballarin@15103
  1617
    val eqD2 = thm "sym" RS thm "order_eq_refl";
ballarin@15103
  1618
    val less_reflE = thm "order_less_irrefl" RS thm "notE";
ballarin@15103
  1619
    val less_imp_le = thm "order_less_imp_le";
ballarin@15103
  1620
    val le_neq_trans = thm "order_le_neq_trans";
ballarin@15103
  1621
    val neq_le_trans = thm "order_neq_le_trans";
ballarin@15103
  1622
    val less_imp_neq = thm "less_imp_neq";
ballarin@15103
  1623
    val decomp_trans = decomp_gen ["HOL.order"];
ballarin@15103
  1624
    val decomp_quasi = decomp_gen ["HOL.order"];
ballarin@15103
  1625
ballarin@15103
  1626
  end);  (* struct *)
ballarin@15103
  1627
ballarin@15103
  1628
structure Order_Tac = Order_Tac_Fun (
ballarin@14398
  1629
  struct
ballarin@14398
  1630
    val less_reflE = thm "order_less_irrefl" RS thm "notE";
ballarin@14398
  1631
    val le_refl = thm "order_refl";
ballarin@14398
  1632
    val less_imp_le = thm "order_less_imp_le";
ballarin@14398
  1633
    val not_lessI = thm "linorder_not_less" RS thm "iffD2";
ballarin@14398
  1634
    val not_leI = thm "linorder_not_le" RS thm "iffD2";
ballarin@14398
  1635
    val not_lessD = thm "linorder_not_less" RS thm "iffD1";
ballarin@14398
  1636
    val not_leD = thm "linorder_not_le" RS thm "iffD1";
ballarin@14398
  1637
    val eqI = thm "order_antisym";
ballarin@14398
  1638
    val eqD1 = thm "order_eq_refl";
ballarin@14398
  1639
    val eqD2 = thm "sym" RS thm "order_eq_refl";
ballarin@14398
  1640
    val less_trans = thm "order_less_trans";
ballarin@14398
  1641
    val less_le_trans = thm "order_less_le_trans";
ballarin@14398
  1642
    val le_less_trans = thm "order_le_less_trans";
ballarin@14398
  1643
    val le_trans = thm "order_trans";
ballarin@14398
  1644
    val le_neq_trans = thm "order_le_neq_trans";
ballarin@14398
  1645
    val neq_le_trans = thm "order_neq_le_trans";
ballarin@14398
  1646
    val less_imp_neq = thm "less_imp_neq";
ballarin@14398
  1647
    val eq_neq_eq_imp_neq = thm "eq_neq_eq_imp_neq";
ballarin@14398
  1648
    val decomp_part = decomp_gen ["HOL.order"];
ballarin@14398
  1649
    val decomp_lin = decomp_gen ["HOL.linorder"];
ballarin@14398
  1650
ballarin@14398
  1651
  end);  (* struct *)
ballarin@14398
  1652
wenzelm@14590
  1653
simpset_ref() := simpset ()
ballarin@15103
  1654
    addSolver (mk_solver "Trans_linear" (fn _ => Order_Tac.linear_tac))
ballarin@15103
  1655
    addSolver (mk_solver "Trans_partial" (fn _ => Order_Tac.partial_tac));
ballarin@14444
  1656
  (* Adding the transitivity reasoners also as safe solvers showed a slight
ballarin@14444
  1657
     speed up, but the reasoning strength appears to be not higher (at least
ballarin@14444
  1658
     no breaking of additional proofs in the entire HOL distribution, as
ballarin@14444
  1659
     of 5 March 2004, was observed). *)
ballarin@14398
  1660
*}
ballarin@14398
  1661
ballarin@15103
  1662
(* Optional setup of methods *)
ballarin@14398
  1663
ballarin@15103
  1664
(*
ballarin@14398
  1665
method_setup trans_partial =
ballarin@15103
  1666
  {* Method.no_args (Method.SIMPLE_METHOD' HEADGOAL (Order_Tac.partial_tac)) *}
paulson@15411
  1667
  {* transitivity reasoner for partial orders *}	
ballarin@14398
  1668
method_setup trans_linear =
ballarin@15103
  1669
  {* Method.no_args (Method.SIMPLE_METHOD' HEADGOAL (Order_Tac.linear_tac)) *}
ballarin@15103
  1670
  {* transitivity reasoner for linear orders *}
ballarin@14398
  1671
*)
ballarin@14398
  1672
ballarin@14444
  1673
(*
ballarin@14444
  1674
declare order.order_refl [simp del] order_less_irrefl [simp del]
ballarin@15103
  1675
ballarin@15103
  1676
can currently not be removed, abel_cancel relies on it.
ballarin@14444
  1677
*)
ballarin@14444
  1678
wenzelm@11750
  1679
subsubsection "Bounded quantifiers"
wenzelm@11750
  1680
wenzelm@11750
  1681
syntax
wenzelm@11750
  1682
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3ALL _<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
  1683
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3EX _<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
  1684
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3ALL _<=_./ _)" [0, 0, 10] 10)
wenzelm@11750
  1685
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3EX _<=_./ _)" [0, 0, 10] 10)
wenzelm@11750
  1686
nipkow@15360
  1687
  "_gtAll" :: "[idt, 'a, bool] => bool"   ("(3ALL _>_./ _)"  [0, 0, 10] 10)
nipkow@15360
  1688
  "_gtEx"  :: "[idt, 'a, bool] => bool"   ("(3EX _>_./ _)"  [0, 0, 10] 10)
nipkow@15360
  1689
  "_geAll"   :: "[idt, 'a, bool] => bool"   ("(3ALL _>=_./ _)" [0, 0, 10] 10)
nipkow@15360
  1690
  "_geEx"    :: "[idt, 'a, bool] => bool"   ("(3EX _>=_./ _)" [0, 0, 10] 10)
nipkow@15360
  1691
wenzelm@12114
  1692
syntax (xsymbols)
wenzelm@11750
  1693
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
  1694
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
  1695
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
wenzelm@11750
  1696
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
wenzelm@11750
  1697
nipkow@15360
  1698
  "_gtAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_>_./ _)"  [0, 0, 10] 10)
nipkow@15360
  1699
  "_gtEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_>_./ _)"  [0, 0, 10] 10)
nipkow@15360
  1700
  "_geAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<ge>_./ _)" [0, 0, 10] 10)
nipkow@15360
  1701
  "_geEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<ge>_./ _)" [0, 0, 10] 10)
nipkow@15360
  1702
wenzelm@11750
  1703
syntax (HOL)
wenzelm@11750
  1704
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3! _<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
  1705
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3? _<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
  1706
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3! _<=_./ _)" [0, 0, 10] 10)
wenzelm@11750
  1707
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3? _<=_./ _)" [0, 0, 10] 10)
wenzelm@11750
  1708
kleing@14565
  1709
syntax (HTML output)
kleing@14565
  1710
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
kleing@14565
  1711
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
kleing@14565
  1712
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
kleing@14565
  1713
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
kleing@14565
  1714
nipkow@15360
  1715
  "_gtAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_>_./ _)"  [0, 0, 10] 10)
nipkow@15360
  1716
  "_gtEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_>_./ _)"  [0, 0, 10] 10)
nipkow@15360
  1717
  "_geAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<ge>_./ _)" [0, 0, 10] 10)
nipkow@15360
  1718
  "_geEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<ge>_./ _)" [0, 0, 10] 10)
nipkow@15360
  1719
wenzelm@11750
  1720
translations
wenzelm@11750
  1721
 "ALL x<y. P"   =>  "ALL x. x < y --> P"
wenzelm@11750
  1722
 "EX x<y. P"    =>  "EX x. x < y  & P"
wenzelm@11750
  1723
 "ALL x<=y. P"  =>  "ALL x. x <= y --> P"
wenzelm@11750
  1724
 "EX x<=y. P"   =>  "EX x. x <= y & P"
nipkow@15360
  1725
 "ALL x>y. P"   =>  "ALL x. x > y --> P"
nipkow@15360
  1726
 "EX x>y. P"    =>  "EX x. x > y  & P"
nipkow@15360
  1727
 "ALL x>=y. P"  =>  "ALL x. x >= y --> P"
nipkow@15360
  1728
 "EX x>=y. P"   =>  "EX x. x >= y & P"
wenzelm@11750
  1729
kleing@14357
  1730
print_translation {*
kleing@14357
  1731
let
nipkow@15363
  1732
  fun mk v v' q n P =
nipkow@15363
  1733
    if v=v' andalso not(v  mem (map fst (Term.add_frees([],n))))
nipkow@15363
  1734
    then Syntax.const q $ Syntax.mark_bound v' $ n $ P else raise Match;
paulson@15411
  1735
  fun all_tr' [Const ("_bound",_) $ Free (v,_),
paulson@15411
  1736
               Const("op -->",_) $ (Const ("op <",_) $ (Const ("_bound",_) $ Free (v',_)) $ n ) $ P] =
nipkow@15363
  1737
    mk v v' "_lessAll" n P
kleing@14357
  1738
paulson@15411
  1739
  | all_tr' [Const ("_bound",_) $ Free (v,_),
paulson@15411
  1740
               Const("op -->",_) $ (Const ("op <=",_) $ (Const ("_bound",_) $ Free (v',_)) $ n ) $ P] =
nipkow@15363
  1741
    mk v v' "_leAll" n P
nipkow@15362
  1742
paulson@15411
  1743
  | all_tr' [Const ("_bound",_) $ Free (v,_),
paulson@15411
  1744
               Const("op -->",_) $ (Const ("op <",_) $ n $ (Const ("_bound",_) $ Free (v',_))) $ P] =
nipkow@15363
  1745
    mk v v' "_gtAll" n P
nipkow@15362
  1746
paulson@15411
  1747
  | all_tr' [Const ("_bound",_) $ Free (v,_),
paulson@15411
  1748
               Const("op -->",_) $ (Const ("op <=",_) $ n $ (Const ("_bound",_) $ Free (v',_))) $ P] =
nipkow@15363
  1749
    mk v v' "_geAll" n P;
kleing@14357
  1750
paulson@15411
  1751
  fun ex_tr' [Const ("_bound",_) $ Free (v,_),
paulson@15411
  1752
               Const("op &",_) $ (Const ("op <",_) $ (Const ("_bound",_) $ Free (v',_)) $ n ) $ P] =
nipkow@15363
  1753
    mk v v' "_lessEx" n P
kleing@14357
  1754
paulson@15411
  1755
  | ex_tr' [Const ("_bound",_) $ Free (v,_),
paulson@15411
  1756
               Const("op &",_) $ (Const ("op <=",_) $ (Const ("_bound",_) $ Free (v',_)) $ n ) $ P] =
nipkow@15363
  1757
    mk v v' "_leEx" n P
nipkow@15362
  1758
paulson@15411
  1759
  | ex_tr' [Const ("_bound",_) $ Free (v,_),
paulson@15411
  1760
               Const("op &",_) $ (Const ("op <",_) $ n $ (Const ("_bound",_) $ Free (v',_))) $ P] =
nipkow@15363
  1761
    mk v v' "_gtEx" n P
nipkow@15362
  1762
paulson@15411
  1763
  | ex_tr' [Const ("_bound",_) $ Free (v,_),
paulson@15411
  1764
               Const("op &",_) $ (Const ("op <=",_) $ n $ (Const ("_bound",_) $ Free (v',_))) $ P] =
nipkow@15363
  1765
    mk v v' "_geEx" n P
kleing@14357
  1766
in
kleing@14357
  1767
[("ALL ", all_tr'), ("EX ", ex_tr')]
clasohm@923
  1768
end
kleing@14357
  1769
*}
kleing@14357
  1770
kleing@14357
  1771
end
paulson@15411
  1772