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