src/HOL/HOL.thy
author paulson
Tue Dec 07 16:15:05 2004 +0100 (2004-12-07)
changeset 15380 455cfa766dad
parent 15363 885a40edcdba
child 15411 1d195de59497
permissions -rw-r--r--
proof of subst by S Merz
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
nipkow@15131
    10
files ("HOL_lemmas.ML") ("cladata.ML") ("blastdata.ML") ("simpdata.ML")
nipkow@15197
    11
      ("antisym_setup.ML")
nipkow@15131
    12
begin
wenzelm@2260
    13
wenzelm@11750
    14
subsection {* Primitive logic *}
wenzelm@11750
    15
wenzelm@11750
    16
subsubsection {* Core syntax *}
wenzelm@2260
    17
wenzelm@14854
    18
classes type
wenzelm@12338
    19
defaultsort type
wenzelm@3947
    20
wenzelm@12338
    21
global
clasohm@923
    22
wenzelm@7357
    23
typedecl bool
clasohm@923
    24
clasohm@923
    25
arities
wenzelm@12338
    26
  bool :: type
wenzelm@12338
    27
  fun :: (type, type) type
clasohm@923
    28
wenzelm@11750
    29
judgment
wenzelm@11750
    30
  Trueprop      :: "bool => prop"                   ("(_)" 5)
clasohm@923
    31
wenzelm@11750
    32
consts
wenzelm@7357
    33
  Not           :: "bool => bool"                   ("~ _" [40] 40)
wenzelm@7357
    34
  True          :: bool
wenzelm@7357
    35
  False         :: bool
wenzelm@7357
    36
  If            :: "[bool, 'a, 'a] => 'a"           ("(if (_)/ then (_)/ else (_))" 10)
wenzelm@3947
    37
  arbitrary     :: 'a
clasohm@923
    38
wenzelm@11432
    39
  The           :: "('a => bool) => 'a"
wenzelm@7357
    40
  All           :: "('a => bool) => bool"           (binder "ALL " 10)
wenzelm@7357
    41
  Ex            :: "('a => bool) => bool"           (binder "EX " 10)
wenzelm@7357
    42
  Ex1           :: "('a => bool) => bool"           (binder "EX! " 10)
wenzelm@7357
    43
  Let           :: "['a, 'a => 'b] => 'b"
clasohm@923
    44
wenzelm@7357
    45
  "="           :: "['a, 'a] => bool"               (infixl 50)
wenzelm@7357
    46
  &             :: "[bool, bool] => bool"           (infixr 35)
wenzelm@7357
    47
  "|"           :: "[bool, bool] => bool"           (infixr 30)
wenzelm@7357
    48
  -->           :: "[bool, bool] => bool"           (infixr 25)
clasohm@923
    49
wenzelm@10432
    50
local
wenzelm@10432
    51
wenzelm@2260
    52
wenzelm@11750
    53
subsubsection {* Additional concrete syntax *}
wenzelm@2260
    54
wenzelm@4868
    55
nonterminals
clasohm@923
    56
  letbinds  letbind
clasohm@923
    57
  case_syn  cases_syn
clasohm@923
    58
clasohm@923
    59
syntax
wenzelm@12650
    60
  "_not_equal"  :: "['a, 'a] => bool"                    (infixl "~=" 50)
wenzelm@11432
    61
  "_The"        :: "[pttrn, bool] => 'a"                 ("(3THE _./ _)" [0, 10] 10)
clasohm@923
    62
wenzelm@7357
    63
  "_bind"       :: "[pttrn, 'a] => letbind"              ("(2_ =/ _)" 10)
wenzelm@7357
    64
  ""            :: "letbind => letbinds"                 ("_")
wenzelm@7357
    65
  "_binds"      :: "[letbind, letbinds] => letbinds"     ("_;/ _")
wenzelm@7357
    66
  "_Let"        :: "[letbinds, 'a] => 'a"                ("(let (_)/ in (_))" 10)
clasohm@923
    67
wenzelm@9060
    68
  "_case_syntax":: "['a, cases_syn] => 'b"               ("(case _ of/ _)" 10)
wenzelm@9060
    69
  "_case1"      :: "['a, 'b] => case_syn"                ("(2_ =>/ _)" 10)
wenzelm@7357
    70
  ""            :: "case_syn => cases_syn"               ("_")
wenzelm@9060
    71
  "_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ | _")
clasohm@923
    72
clasohm@923
    73
translations
wenzelm@7238
    74
  "x ~= y"                == "~ (x = y)"
nipkow@13764
    75
  "THE x. P"              == "The (%x. P)"
clasohm@923
    76
  "_Let (_binds b bs) e"  == "_Let b (_Let bs e)"
nipkow@1114
    77
  "let x = a in e"        == "Let a (%x. e)"
clasohm@923
    78
nipkow@13763
    79
print_translation {*
nipkow@13763
    80
(* To avoid eta-contraction of body: *)
nipkow@13763
    81
[("The", fn [Abs abs] =>
nipkow@13763
    82
     let val (x,t) = atomic_abs_tr' abs
nipkow@13763
    83
     in Syntax.const "_The" $ x $ t end)]
nipkow@13763
    84
*}
nipkow@13763
    85
wenzelm@12633
    86
syntax (output)
wenzelm@11687
    87
  "="           :: "['a, 'a] => bool"                    (infix 50)
wenzelm@12650
    88
  "_not_equal"  :: "['a, 'a] => bool"                    (infix "~=" 50)
wenzelm@2260
    89
wenzelm@12114
    90
syntax (xsymbols)
wenzelm@11687
    91
  Not           :: "bool => bool"                        ("\<not> _" [40] 40)
wenzelm@11687
    92
  "op &"        :: "[bool, bool] => bool"                (infixr "\<and>" 35)
wenzelm@11687
    93
  "op |"        :: "[bool, bool] => bool"                (infixr "\<or>" 30)
wenzelm@12114
    94
  "op -->"      :: "[bool, bool] => bool"                (infixr "\<longrightarrow>" 25)
wenzelm@12650
    95
  "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
wenzelm@11687
    96
  "ALL "        :: "[idts, bool] => bool"                ("(3\<forall>_./ _)" [0, 10] 10)
wenzelm@11687
    97
  "EX "         :: "[idts, bool] => bool"                ("(3\<exists>_./ _)" [0, 10] 10)
wenzelm@11687
    98
  "EX! "        :: "[idts, bool] => bool"                ("(3\<exists>!_./ _)" [0, 10] 10)
wenzelm@11687
    99
  "_case1"      :: "['a, 'b] => case_syn"                ("(2_ \<Rightarrow>/ _)" 10)
schirmer@14361
   100
(*"_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ \<orelse> _")*)
wenzelm@2372
   101
wenzelm@12114
   102
syntax (xsymbols output)
wenzelm@12650
   103
  "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
wenzelm@3820
   104
wenzelm@6340
   105
syntax (HTML output)
kleing@14565
   106
  "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
wenzelm@11687
   107
  Not           :: "bool => bool"                        ("\<not> _" [40] 40)
kleing@14565
   108
  "op &"        :: "[bool, bool] => bool"                (infixr "\<and>" 35)
kleing@14565
   109
  "op |"        :: "[bool, bool] => bool"                (infixr "\<or>" 30)
kleing@14565
   110
  "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
kleing@14565
   111
  "ALL "        :: "[idts, bool] => bool"                ("(3\<forall>_./ _)" [0, 10] 10)
kleing@14565
   112
  "EX "         :: "[idts, bool] => bool"                ("(3\<exists>_./ _)" [0, 10] 10)
kleing@14565
   113
  "EX! "        :: "[idts, bool] => bool"                ("(3\<exists>!_./ _)" [0, 10] 10)
wenzelm@6340
   114
wenzelm@7238
   115
syntax (HOL)
wenzelm@7357
   116
  "ALL "        :: "[idts, bool] => bool"                ("(3! _./ _)" [0, 10] 10)
wenzelm@7357
   117
  "EX "         :: "[idts, bool] => bool"                ("(3? _./ _)" [0, 10] 10)
wenzelm@7357
   118
  "EX! "        :: "[idts, bool] => bool"                ("(3?! _./ _)" [0, 10] 10)
wenzelm@7238
   119
wenzelm@7238
   120
wenzelm@11750
   121
subsubsection {* Axioms and basic definitions *}
wenzelm@2260
   122
wenzelm@7357
   123
axioms
paulson@15380
   124
  eq_reflection:  "(x=y) ==> (x==y)"
clasohm@923
   125
paulson@15380
   126
  refl:           "t = (t::'a)"
paulson@6289
   127
paulson@15380
   128
  ext:            "(!!x::'a. (f x ::'b) = g x) ==> (%x. f x) = (%x. g x)"
paulson@15380
   129
    -- {*Extensionality is built into the meta-logic, and this rule expresses
paulson@15380
   130
         a related property.  It is an eta-expanded version of the traditional
paulson@15380
   131
         rule, and similar to the ABS rule of HOL*}
paulson@6289
   132
wenzelm@11432
   133
  the_eq_trivial: "(THE x. x = a) = (a::'a)"
clasohm@923
   134
paulson@15380
   135
  impI:           "(P ==> Q) ==> P-->Q"
paulson@15380
   136
  mp:             "[| P-->Q;  P |] ==> Q"
paulson@15380
   137
paulson@15380
   138
paulson@15380
   139
text{*Thanks to Stephan Merz*}
paulson@15380
   140
theorem subst:
paulson@15380
   141
  assumes eq: "s = t" and p: "P(s)"
paulson@15380
   142
  shows "P(t::'a)"
paulson@15380
   143
proof -
paulson@15380
   144
  from eq have meta: "s \<equiv> t"
paulson@15380
   145
    by (rule eq_reflection)
paulson@15380
   146
  from p show ?thesis
paulson@15380
   147
    by (unfold meta)
paulson@15380
   148
qed
clasohm@923
   149
clasohm@923
   150
defs
wenzelm@7357
   151
  True_def:     "True      == ((%x::bool. x) = (%x. x))"
wenzelm@7357
   152
  All_def:      "All(P)    == (P = (%x. True))"
paulson@11451
   153
  Ex_def:       "Ex(P)     == !Q. (!x. P x --> Q) --> Q"
wenzelm@7357
   154
  False_def:    "False     == (!P. P)"
wenzelm@7357
   155
  not_def:      "~ P       == P-->False"
wenzelm@7357
   156
  and_def:      "P & Q     == !R. (P-->Q-->R) --> R"
wenzelm@7357
   157
  or_def:       "P | Q     == !R. (P-->R) --> (Q-->R) --> R"
wenzelm@7357
   158
  Ex1_def:      "Ex1(P)    == ? x. P(x) & (! y. P(y) --> y=x)"
clasohm@923
   159
wenzelm@7357
   160
axioms
wenzelm@7357
   161
  iff:          "(P-->Q) --> (Q-->P) --> (P=Q)"
wenzelm@7357
   162
  True_or_False:  "(P=True) | (P=False)"
clasohm@923
   163
clasohm@923
   164
defs
wenzelm@7357
   165
  Let_def:      "Let s f == f(s)"
paulson@11451
   166
  if_def:       "If P x y == THE z::'a. (P=True --> z=x) & (P=False --> z=y)"
wenzelm@5069
   167
skalberg@14223
   168
finalconsts
skalberg@14223
   169
  "op ="
skalberg@14223
   170
  "op -->"
skalberg@14223
   171
  The
skalberg@14223
   172
  arbitrary
nipkow@3320
   173
wenzelm@11750
   174
subsubsection {* Generic algebraic operations *}
wenzelm@4868
   175
wenzelm@12338
   176
axclass zero < type
wenzelm@12338
   177
axclass one < type
wenzelm@12338
   178
axclass plus < type
wenzelm@12338
   179
axclass minus < type
wenzelm@12338
   180
axclass times < type
wenzelm@12338
   181
axclass inverse < type
wenzelm@11750
   182
wenzelm@11750
   183
global
wenzelm@11750
   184
wenzelm@11750
   185
consts
wenzelm@11750
   186
  "0"           :: "'a::zero"                       ("0")
wenzelm@11750
   187
  "1"           :: "'a::one"                        ("1")
wenzelm@11750
   188
  "+"           :: "['a::plus, 'a]  => 'a"          (infixl 65)
wenzelm@11750
   189
  -             :: "['a::minus, 'a] => 'a"          (infixl 65)
wenzelm@11750
   190
  uminus        :: "['a::minus] => 'a"              ("- _" [81] 80)
wenzelm@11750
   191
  *             :: "['a::times, 'a] => 'a"          (infixl 70)
wenzelm@11750
   192
wenzelm@13456
   193
syntax
wenzelm@13456
   194
  "_index1"  :: index    ("\<^sub>1")
wenzelm@13456
   195
translations
wenzelm@14690
   196
  (index) "\<^sub>1" => (index) "\<^bsub>\<struct>\<^esub>"
wenzelm@13456
   197
wenzelm@11750
   198
local
wenzelm@11750
   199
wenzelm@11750
   200
typed_print_translation {*
wenzelm@11750
   201
  let
wenzelm@11750
   202
    fun tr' c = (c, fn show_sorts => fn T => fn ts =>
wenzelm@11750
   203
      if T = dummyT orelse not (! show_types) andalso can Term.dest_Type T then raise Match
wenzelm@11750
   204
      else Syntax.const Syntax.constrainC $ Syntax.const c $ Syntax.term_of_typ show_sorts T);
wenzelm@11750
   205
  in [tr' "0", tr' "1"] end;
wenzelm@11750
   206
*} -- {* show types that are presumably too general *}
wenzelm@11750
   207
wenzelm@11750
   208
wenzelm@11750
   209
consts
wenzelm@11750
   210
  abs           :: "'a::minus => 'a"
wenzelm@11750
   211
  inverse       :: "'a::inverse => 'a"
wenzelm@11750
   212
  divide        :: "['a::inverse, 'a] => 'a"        (infixl "'/" 70)
wenzelm@11750
   213
wenzelm@11750
   214
syntax (xsymbols)
wenzelm@11750
   215
  abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
wenzelm@11750
   216
syntax (HTML output)
wenzelm@11750
   217
  abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
wenzelm@11750
   218
wenzelm@11750
   219
wenzelm@11750
   220
subsection {* Theory and package setup *}
wenzelm@11750
   221
wenzelm@11750
   222
subsubsection {* Basic lemmas *}
wenzelm@4868
   223
nipkow@9736
   224
use "HOL_lemmas.ML"
wenzelm@11687
   225
theorems case_split = case_split_thm [case_names True False]
wenzelm@9869
   226
wenzelm@12386
   227
wenzelm@12386
   228
subsubsection {* Intuitionistic Reasoning *}
wenzelm@12386
   229
wenzelm@12386
   230
lemma impE':
wenzelm@12937
   231
  assumes 1: "P --> Q"
wenzelm@12937
   232
    and 2: "Q ==> R"
wenzelm@12937
   233
    and 3: "P --> Q ==> P"
wenzelm@12937
   234
  shows R
wenzelm@12386
   235
proof -
wenzelm@12386
   236
  from 3 and 1 have P .
wenzelm@12386
   237
  with 1 have Q by (rule impE)
wenzelm@12386
   238
  with 2 show R .
wenzelm@12386
   239
qed
wenzelm@12386
   240
wenzelm@12386
   241
lemma allE':
wenzelm@12937
   242
  assumes 1: "ALL x. P x"
wenzelm@12937
   243
    and 2: "P x ==> ALL x. P x ==> Q"
wenzelm@12937
   244
  shows Q
wenzelm@12386
   245
proof -
wenzelm@12386
   246
  from 1 have "P x" by (rule spec)
wenzelm@12386
   247
  from this and 1 show Q by (rule 2)
wenzelm@12386
   248
qed
wenzelm@12386
   249
wenzelm@12937
   250
lemma notE':
wenzelm@12937
   251
  assumes 1: "~ P"
wenzelm@12937
   252
    and 2: "~ P ==> P"
wenzelm@12937
   253
  shows R
wenzelm@12386
   254
proof -
wenzelm@12386
   255
  from 2 and 1 have P .
wenzelm@12386
   256
  with 1 show R by (rule notE)
wenzelm@12386
   257
qed
wenzelm@12386
   258
wenzelm@12386
   259
lemmas [CPure.elim!] = disjE iffE FalseE conjE exE
wenzelm@12386
   260
  and [CPure.intro!] = iffI conjI impI TrueI notI allI refl
wenzelm@12386
   261
  and [CPure.elim 2] = allE notE' impE'
wenzelm@12386
   262
  and [CPure.intro] = exI disjI2 disjI1
wenzelm@12386
   263
wenzelm@12386
   264
lemmas [trans] = trans
wenzelm@12386
   265
  and [sym] = sym not_sym
wenzelm@12386
   266
  and [CPure.elim?] = iffD1 iffD2 impE
wenzelm@11750
   267
wenzelm@11438
   268
wenzelm@11750
   269
subsubsection {* Atomizing meta-level connectives *}
wenzelm@11750
   270
wenzelm@11750
   271
lemma atomize_all [atomize]: "(!!x. P x) == Trueprop (ALL x. P x)"
wenzelm@12003
   272
proof
wenzelm@9488
   273
  assume "!!x. P x"
wenzelm@10383
   274
  show "ALL x. P x" by (rule allI)
wenzelm@9488
   275
next
wenzelm@9488
   276
  assume "ALL x. P x"
wenzelm@10383
   277
  thus "!!x. P x" by (rule allE)
wenzelm@9488
   278
qed
wenzelm@9488
   279
wenzelm@11750
   280
lemma atomize_imp [atomize]: "(A ==> B) == Trueprop (A --> B)"
wenzelm@12003
   281
proof
wenzelm@9488
   282
  assume r: "A ==> B"
wenzelm@10383
   283
  show "A --> B" by (rule impI) (rule r)
wenzelm@9488
   284
next
wenzelm@9488
   285
  assume "A --> B" and A
wenzelm@10383
   286
  thus B by (rule mp)
wenzelm@9488
   287
qed
wenzelm@9488
   288
paulson@14749
   289
lemma atomize_not: "(A ==> False) == Trueprop (~A)"
paulson@14749
   290
proof
paulson@14749
   291
  assume r: "A ==> False"
paulson@14749
   292
  show "~A" by (rule notI) (rule r)
paulson@14749
   293
next
paulson@14749
   294
  assume "~A" and A
paulson@14749
   295
  thus False by (rule notE)
paulson@14749
   296
qed
paulson@14749
   297
wenzelm@11750
   298
lemma atomize_eq [atomize]: "(x == y) == Trueprop (x = y)"
wenzelm@12003
   299
proof
wenzelm@10432
   300
  assume "x == y"
wenzelm@10432
   301
  show "x = y" by (unfold prems) (rule refl)
wenzelm@10432
   302
next
wenzelm@10432
   303
  assume "x = y"
wenzelm@10432
   304
  thus "x == y" by (rule eq_reflection)
wenzelm@10432
   305
qed
wenzelm@10432
   306
wenzelm@12023
   307
lemma atomize_conj [atomize]:
wenzelm@12023
   308
  "(!!C. (A ==> B ==> PROP C) ==> PROP C) == Trueprop (A & B)"
wenzelm@12003
   309
proof
wenzelm@11953
   310
  assume "!!C. (A ==> B ==> PROP C) ==> PROP C"
wenzelm@11953
   311
  show "A & B" by (rule conjI)
wenzelm@11953
   312
next
wenzelm@11953
   313
  fix C
wenzelm@11953
   314
  assume "A & B"
wenzelm@11953
   315
  assume "A ==> B ==> PROP C"
wenzelm@11953
   316
  thus "PROP C"
wenzelm@11953
   317
  proof this
wenzelm@11953
   318
    show A by (rule conjunct1)
wenzelm@11953
   319
    show B by (rule conjunct2)
wenzelm@11953
   320
  qed
wenzelm@11953
   321
qed
wenzelm@11953
   322
wenzelm@12386
   323
lemmas [symmetric, rulify] = atomize_all atomize_imp
wenzelm@12386
   324
wenzelm@11750
   325
wenzelm@11750
   326
subsubsection {* Classical Reasoner setup *}
wenzelm@9529
   327
wenzelm@10383
   328
use "cladata.ML"
wenzelm@10383
   329
setup hypsubst_setup
wenzelm@11977
   330
wenzelm@12386
   331
ML_setup {*
wenzelm@12386
   332
  Context.>> (ContextRules.addSWrapper (fn tac => hyp_subst_tac' ORELSE' tac));
wenzelm@12386
   333
*}
wenzelm@11977
   334
wenzelm@10383
   335
setup Classical.setup
wenzelm@10383
   336
setup clasetup
wenzelm@10383
   337
wenzelm@12386
   338
lemmas [intro?] = ext
wenzelm@12386
   339
  and [elim?] = ex1_implies_ex
wenzelm@11977
   340
wenzelm@9869
   341
use "blastdata.ML"
wenzelm@9869
   342
setup Blast.setup
wenzelm@4868
   343
wenzelm@11750
   344
wenzelm@11750
   345
subsubsection {* Simplifier setup *}
wenzelm@11750
   346
wenzelm@12281
   347
lemma meta_eq_to_obj_eq: "x == y ==> x = y"
wenzelm@12281
   348
proof -
wenzelm@12281
   349
  assume r: "x == y"
wenzelm@12281
   350
  show "x = y" by (unfold r) (rule refl)
wenzelm@12281
   351
qed
wenzelm@12281
   352
wenzelm@12281
   353
lemma eta_contract_eq: "(%s. f s) = f" ..
wenzelm@12281
   354
wenzelm@12281
   355
lemma simp_thms:
wenzelm@12937
   356
  shows not_not: "(~ ~ P) = P"
nipkow@15354
   357
  and Not_eq_iff: "((~P) = (~Q)) = (P = Q)"
wenzelm@12937
   358
  and
berghofe@12436
   359
    "(P ~= Q) = (P = (~Q))"
berghofe@12436
   360
    "(P | ~P) = True"    "(~P | P) = True"
wenzelm@12281
   361
    "(x = x) = True"
wenzelm@12281
   362
    "(~True) = False"  "(~False) = True"
berghofe@12436
   363
    "(~P) ~= P"  "P ~= (~P)"
wenzelm@12281
   364
    "(True=P) = P"  "(P=True) = P"  "(False=P) = (~P)"  "(P=False) = (~P)"
wenzelm@12281
   365
    "(True --> P) = P"  "(False --> P) = True"
wenzelm@12281
   366
    "(P --> True) = True"  "(P --> P) = True"
wenzelm@12281
   367
    "(P --> False) = (~P)"  "(P --> ~P) = (~P)"
wenzelm@12281
   368
    "(P & True) = P"  "(True & P) = P"
wenzelm@12281
   369
    "(P & False) = False"  "(False & P) = False"
wenzelm@12281
   370
    "(P & P) = P"  "(P & (P & Q)) = (P & Q)"
wenzelm@12281
   371
    "(P & ~P) = False"    "(~P & P) = False"
wenzelm@12281
   372
    "(P | True) = True"  "(True | P) = True"
wenzelm@12281
   373
    "(P | False) = P"  "(False | P) = P"
berghofe@12436
   374
    "(P | P) = P"  "(P | (P | Q)) = (P | Q)" and
wenzelm@12281
   375
    "(ALL x. P) = P"  "(EX x. P) = P"  "EX x. x=t"  "EX x. t=x"
wenzelm@12281
   376
    -- {* needed for the one-point-rule quantifier simplification procs *}
wenzelm@12281
   377
    -- {* essential for termination!! *} and
wenzelm@12281
   378
    "!!P. (EX x. x=t & P(x)) = P(t)"
wenzelm@12281
   379
    "!!P. (EX x. t=x & P(x)) = P(t)"
wenzelm@12281
   380
    "!!P. (ALL x. x=t --> P(x)) = P(t)"
wenzelm@12937
   381
    "!!P. (ALL x. t=x --> P(x)) = P(t)"
berghofe@12436
   382
  by (blast, blast, blast, blast, blast, rules+)
wenzelm@13421
   383
wenzelm@12281
   384
lemma imp_cong: "(P = P') ==> (P' ==> (Q = Q')) ==> ((P --> Q) = (P' --> Q'))"
wenzelm@12354
   385
  by rules
wenzelm@12281
   386
wenzelm@12281
   387
lemma ex_simps:
wenzelm@12281
   388
  "!!P Q. (EX x. P x & Q)   = ((EX x. P x) & Q)"
wenzelm@12281
   389
  "!!P Q. (EX x. P & Q x)   = (P & (EX x. Q x))"
wenzelm@12281
   390
  "!!P Q. (EX x. P x | Q)   = ((EX x. P x) | Q)"
wenzelm@12281
   391
  "!!P Q. (EX x. P | Q x)   = (P | (EX x. Q x))"
wenzelm@12281
   392
  "!!P Q. (EX x. P x --> Q) = ((ALL x. P x) --> Q)"
wenzelm@12281
   393
  "!!P Q. (EX x. P --> Q x) = (P --> (EX x. Q x))"
wenzelm@12281
   394
  -- {* Miniscoping: pushing in existential quantifiers. *}
berghofe@12436
   395
  by (rules | blast)+
wenzelm@12281
   396
wenzelm@12281
   397
lemma all_simps:
wenzelm@12281
   398
  "!!P Q. (ALL x. P x & Q)   = ((ALL x. P x) & Q)"
wenzelm@12281
   399
  "!!P Q. (ALL x. P & Q x)   = (P & (ALL x. Q x))"
wenzelm@12281
   400
  "!!P Q. (ALL x. P x | Q)   = ((ALL x. P x) | Q)"
wenzelm@12281
   401
  "!!P Q. (ALL x. P | Q x)   = (P | (ALL x. Q x))"
wenzelm@12281
   402
  "!!P Q. (ALL x. P x --> Q) = ((EX x. P x) --> Q)"
wenzelm@12281
   403
  "!!P Q. (ALL x. P --> Q x) = (P --> (ALL x. Q x))"
wenzelm@12281
   404
  -- {* Miniscoping: pushing in universal quantifiers. *}
berghofe@12436
   405
  by (rules | blast)+
wenzelm@12281
   406
paulson@14201
   407
lemma disj_absorb: "(A | A) = A"
paulson@14201
   408
  by blast
paulson@14201
   409
paulson@14201
   410
lemma disj_left_absorb: "(A | (A | B)) = (A | B)"
paulson@14201
   411
  by blast
paulson@14201
   412
paulson@14201
   413
lemma conj_absorb: "(A & A) = A"
paulson@14201
   414
  by blast
paulson@14201
   415
paulson@14201
   416
lemma conj_left_absorb: "(A & (A & B)) = (A & B)"
paulson@14201
   417
  by blast
paulson@14201
   418
wenzelm@12281
   419
lemma eq_ac:
wenzelm@12937
   420
  shows eq_commute: "(a=b) = (b=a)"
wenzelm@12937
   421
    and eq_left_commute: "(P=(Q=R)) = (Q=(P=R))"
wenzelm@12937
   422
    and eq_assoc: "((P=Q)=R) = (P=(Q=R))" by (rules, blast+)
berghofe@12436
   423
lemma neq_commute: "(a~=b) = (b~=a)" by rules
wenzelm@12281
   424
wenzelm@12281
   425
lemma conj_comms:
wenzelm@12937
   426
  shows conj_commute: "(P&Q) = (Q&P)"
wenzelm@12937
   427
    and conj_left_commute: "(P&(Q&R)) = (Q&(P&R))" by rules+
berghofe@12436
   428
lemma conj_assoc: "((P&Q)&R) = (P&(Q&R))" by rules
wenzelm@12281
   429
wenzelm@12281
   430
lemma disj_comms:
wenzelm@12937
   431
  shows disj_commute: "(P|Q) = (Q|P)"
wenzelm@12937
   432
    and disj_left_commute: "(P|(Q|R)) = (Q|(P|R))" by rules+
berghofe@12436
   433
lemma disj_assoc: "((P|Q)|R) = (P|(Q|R))" by rules
wenzelm@12281
   434
berghofe@12436
   435
lemma conj_disj_distribL: "(P&(Q|R)) = (P&Q | P&R)" by rules
berghofe@12436
   436
lemma conj_disj_distribR: "((P|Q)&R) = (P&R | Q&R)" by rules
wenzelm@12281
   437
berghofe@12436
   438
lemma disj_conj_distribL: "(P|(Q&R)) = ((P|Q) & (P|R))" by rules
berghofe@12436
   439
lemma disj_conj_distribR: "((P&Q)|R) = ((P|R) & (Q|R))" by rules
wenzelm@12281
   440
berghofe@12436
   441
lemma imp_conjR: "(P --> (Q&R)) = ((P-->Q) & (P-->R))" by rules
berghofe@12436
   442
lemma imp_conjL: "((P&Q) -->R)  = (P --> (Q --> R))" by rules
berghofe@12436
   443
lemma imp_disjL: "((P|Q) --> R) = ((P-->R)&(Q-->R))" by rules
wenzelm@12281
   444
wenzelm@12281
   445
text {* These two are specialized, but @{text imp_disj_not1} is useful in @{text "Auth/Yahalom"}. *}
wenzelm@12281
   446
lemma imp_disj_not1: "(P --> Q | R) = (~Q --> P --> R)" by blast
wenzelm@12281
   447
lemma imp_disj_not2: "(P --> Q | R) = (~R --> P --> Q)" by blast
wenzelm@12281
   448
wenzelm@12281
   449
lemma imp_disj1: "((P-->Q)|R) = (P--> Q|R)" by blast
wenzelm@12281
   450
lemma imp_disj2: "(Q|(P-->R)) = (P--> Q|R)" by blast
wenzelm@12281
   451
berghofe@12436
   452
lemma de_Morgan_disj: "(~(P | Q)) = (~P & ~Q)" by rules
wenzelm@12281
   453
lemma de_Morgan_conj: "(~(P & Q)) = (~P | ~Q)" by blast
wenzelm@12281
   454
lemma not_imp: "(~(P --> Q)) = (P & ~Q)" by blast
wenzelm@12281
   455
lemma not_iff: "(P~=Q) = (P = (~Q))" by blast
wenzelm@12281
   456
lemma disj_not1: "(~P | Q) = (P --> Q)" by blast
wenzelm@12281
   457
lemma disj_not2: "(P | ~Q) = (Q --> P)"  -- {* changes orientation :-( *}
wenzelm@12281
   458
  by blast
wenzelm@12281
   459
lemma imp_conv_disj: "(P --> Q) = ((~P) | Q)" by blast
wenzelm@12281
   460
berghofe@12436
   461
lemma iff_conv_conj_imp: "(P = Q) = ((P --> Q) & (Q --> P))" by rules
wenzelm@12281
   462
wenzelm@12281
   463
wenzelm@12281
   464
lemma cases_simp: "((P --> Q) & (~P --> Q)) = Q"
wenzelm@12281
   465
  -- {* Avoids duplication of subgoals after @{text split_if}, when the true and false *}
wenzelm@12281
   466
  -- {* cases boil down to the same thing. *}
wenzelm@12281
   467
  by blast
wenzelm@12281
   468
wenzelm@12281
   469
lemma not_all: "(~ (! x. P(x))) = (? x.~P(x))" by blast
wenzelm@12281
   470
lemma imp_all: "((! x. P x) --> Q) = (? x. P x --> Q)" by blast
berghofe@12436
   471
lemma not_ex: "(~ (? x. P(x))) = (! x.~P(x))" by rules
berghofe@12436
   472
lemma imp_ex: "((? x. P x) --> Q) = (! x. P x --> Q)" by rules
wenzelm@12281
   473
berghofe@12436
   474
lemma ex_disj_distrib: "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))" by rules
berghofe@12436
   475
lemma all_conj_distrib: "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))" by rules
wenzelm@12281
   476
wenzelm@12281
   477
text {*
wenzelm@12281
   478
  \medskip The @{text "&"} congruence rule: not included by default!
wenzelm@12281
   479
  May slow rewrite proofs down by as much as 50\% *}
wenzelm@12281
   480
wenzelm@12281
   481
lemma conj_cong:
wenzelm@12281
   482
    "(P = P') ==> (P' ==> (Q = Q')) ==> ((P & Q) = (P' & Q'))"
wenzelm@12354
   483
  by rules
wenzelm@12281
   484
wenzelm@12281
   485
lemma rev_conj_cong:
wenzelm@12281
   486
    "(Q = Q') ==> (Q' ==> (P = P')) ==> ((P & Q) = (P' & Q'))"
wenzelm@12354
   487
  by rules
wenzelm@12281
   488
wenzelm@12281
   489
text {* The @{text "|"} congruence rule: not included by default! *}
wenzelm@12281
   490
wenzelm@12281
   491
lemma disj_cong:
wenzelm@12281
   492
    "(P = P') ==> (~P' ==> (Q = Q')) ==> ((P | Q) = (P' | Q'))"
wenzelm@12281
   493
  by blast
wenzelm@12281
   494
wenzelm@12281
   495
lemma eq_sym_conv: "(x = y) = (y = x)"
wenzelm@12354
   496
  by rules
wenzelm@12281
   497
wenzelm@12281
   498
wenzelm@12281
   499
text {* \medskip if-then-else rules *}
wenzelm@12281
   500
wenzelm@12281
   501
lemma if_True: "(if True then x else y) = x"
wenzelm@12281
   502
  by (unfold if_def) blast
wenzelm@12281
   503
wenzelm@12281
   504
lemma if_False: "(if False then x else y) = y"
wenzelm@12281
   505
  by (unfold if_def) blast
wenzelm@12281
   506
wenzelm@12281
   507
lemma if_P: "P ==> (if P then x else y) = x"
wenzelm@12281
   508
  by (unfold if_def) blast
wenzelm@12281
   509
wenzelm@12281
   510
lemma if_not_P: "~P ==> (if P then x else y) = y"
wenzelm@12281
   511
  by (unfold if_def) blast
wenzelm@12281
   512
wenzelm@12281
   513
lemma split_if: "P (if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))"
wenzelm@12281
   514
  apply (rule case_split [of Q])
wenzelm@12281
   515
   apply (subst if_P)
paulson@14208
   516
    prefer 3 apply (subst if_not_P, blast+)
wenzelm@12281
   517
  done
wenzelm@12281
   518
wenzelm@12281
   519
lemma split_if_asm: "P (if Q then x else y) = (~((Q & ~P x) | (~Q & ~P y)))"
paulson@14208
   520
by (subst split_if, blast)
wenzelm@12281
   521
wenzelm@12281
   522
lemmas if_splits = split_if split_if_asm
wenzelm@12281
   523
wenzelm@12281
   524
lemma if_def2: "(if Q then x else y) = ((Q --> x) & (~ Q --> y))"
wenzelm@12281
   525
  by (rule split_if)
wenzelm@12281
   526
wenzelm@12281
   527
lemma if_cancel: "(if c then x else x) = x"
paulson@14208
   528
by (subst split_if, blast)
wenzelm@12281
   529
wenzelm@12281
   530
lemma if_eq_cancel: "(if x = y then y else x) = x"
paulson@14208
   531
by (subst split_if, blast)
wenzelm@12281
   532
wenzelm@12281
   533
lemma if_bool_eq_conj: "(if P then Q else R) = ((P-->Q) & (~P-->R))"
wenzelm@12281
   534
  -- {* This form is useful for expanding @{text if}s on the RIGHT of the @{text "==>"} symbol. *}
wenzelm@12281
   535
  by (rule split_if)
wenzelm@12281
   536
wenzelm@12281
   537
lemma if_bool_eq_disj: "(if P then Q else R) = ((P&Q) | (~P&R))"
wenzelm@12281
   538
  -- {* And this form is useful for expanding @{text if}s on the LEFT. *}
paulson@14208
   539
  apply (subst split_if, blast)
wenzelm@12281
   540
  done
wenzelm@12281
   541
berghofe@12436
   542
lemma Eq_TrueI: "P ==> P == True" by (unfold atomize_eq) rules
berghofe@12436
   543
lemma Eq_FalseI: "~P ==> P == False" by (unfold atomize_eq) rules
wenzelm@12281
   544
paulson@14201
   545
subsubsection {* Actual Installation of the Simplifier *}
paulson@14201
   546
wenzelm@9869
   547
use "simpdata.ML"
wenzelm@9869
   548
setup Simplifier.setup
wenzelm@9869
   549
setup "Simplifier.method_setup Splitter.split_modifiers" setup simpsetup
wenzelm@9869
   550
setup Splitter.setup setup Clasimp.setup
wenzelm@9869
   551
paulson@14201
   552
declare disj_absorb [simp] conj_absorb [simp] 
paulson@14201
   553
nipkow@13723
   554
lemma ex1_eq[iff]: "EX! x. x = t" "EX! x. t = x"
nipkow@13723
   555
by blast+
nipkow@13723
   556
berghofe@13638
   557
theorem choice_eq: "(ALL x. EX! y. P x y) = (EX! f. ALL x. P x (f x))"
berghofe@13638
   558
  apply (rule iffI)
berghofe@13638
   559
  apply (rule_tac a = "%x. THE y. P x y" in ex1I)
berghofe@13638
   560
  apply (fast dest!: theI')
berghofe@13638
   561
  apply (fast intro: ext the1_equality [symmetric])
berghofe@13638
   562
  apply (erule ex1E)
berghofe@13638
   563
  apply (rule allI)
berghofe@13638
   564
  apply (rule ex1I)
berghofe@13638
   565
  apply (erule spec)
berghofe@13638
   566
  apply (erule_tac x = "%z. if z = x then y else f z" in allE)
berghofe@13638
   567
  apply (erule impE)
berghofe@13638
   568
  apply (rule allI)
berghofe@13638
   569
  apply (rule_tac P = "xa = x" in case_split_thm)
paulson@14208
   570
  apply (drule_tac [3] x = x in fun_cong, simp_all)
berghofe@13638
   571
  done
berghofe@13638
   572
nipkow@13438
   573
text{*Needs only HOL-lemmas:*}
nipkow@13438
   574
lemma mk_left_commute:
nipkow@13438
   575
  assumes a: "\<And>x y z. f (f x y) z = f x (f y z)" and
nipkow@13438
   576
          c: "\<And>x y. f x y = f y x"
nipkow@13438
   577
  shows "f x (f y z) = f y (f x z)"
nipkow@13438
   578
by(rule trans[OF trans[OF c a] arg_cong[OF c, of "f y"]])
nipkow@13438
   579
wenzelm@11750
   580
wenzelm@11824
   581
subsubsection {* Generic cases and induction *}
wenzelm@11824
   582
wenzelm@11824
   583
constdefs
wenzelm@11989
   584
  induct_forall :: "('a => bool) => bool"
wenzelm@11989
   585
  "induct_forall P == \<forall>x. P x"
wenzelm@11989
   586
  induct_implies :: "bool => bool => bool"
wenzelm@11989
   587
  "induct_implies A B == A --> B"
wenzelm@11989
   588
  induct_equal :: "'a => 'a => bool"
wenzelm@11989
   589
  "induct_equal x y == x = y"
wenzelm@11989
   590
  induct_conj :: "bool => bool => bool"
wenzelm@11989
   591
  "induct_conj A B == A & B"
wenzelm@11824
   592
wenzelm@11989
   593
lemma induct_forall_eq: "(!!x. P x) == Trueprop (induct_forall (\<lambda>x. P x))"
wenzelm@11989
   594
  by (simp only: atomize_all induct_forall_def)
wenzelm@11824
   595
wenzelm@11989
   596
lemma induct_implies_eq: "(A ==> B) == Trueprop (induct_implies A B)"
wenzelm@11989
   597
  by (simp only: atomize_imp induct_implies_def)
wenzelm@11824
   598
wenzelm@11989
   599
lemma induct_equal_eq: "(x == y) == Trueprop (induct_equal x y)"
wenzelm@11989
   600
  by (simp only: atomize_eq induct_equal_def)
wenzelm@11824
   601
wenzelm@11989
   602
lemma induct_forall_conj: "induct_forall (\<lambda>x. induct_conj (A x) (B x)) =
wenzelm@11989
   603
    induct_conj (induct_forall A) (induct_forall B)"
wenzelm@12354
   604
  by (unfold induct_forall_def induct_conj_def) rules
wenzelm@11824
   605
wenzelm@11989
   606
lemma induct_implies_conj: "induct_implies C (induct_conj A B) =
wenzelm@11989
   607
    induct_conj (induct_implies C A) (induct_implies C B)"
wenzelm@12354
   608
  by (unfold induct_implies_def induct_conj_def) rules
wenzelm@11989
   609
berghofe@13598
   610
lemma induct_conj_curry: "(induct_conj A B ==> PROP C) == (A ==> B ==> PROP C)"
berghofe@13598
   611
proof
berghofe@13598
   612
  assume r: "induct_conj A B ==> PROP C" and A B
berghofe@13598
   613
  show "PROP C" by (rule r) (simp! add: induct_conj_def)
berghofe@13598
   614
next
berghofe@13598
   615
  assume r: "A ==> B ==> PROP C" and "induct_conj A B"
berghofe@13598
   616
  show "PROP C" by (rule r) (simp! add: induct_conj_def)+
berghofe@13598
   617
qed
wenzelm@11824
   618
wenzelm@11989
   619
lemma induct_impliesI: "(A ==> B) ==> induct_implies A B"
wenzelm@11989
   620
  by (simp add: induct_implies_def)
wenzelm@11824
   621
wenzelm@12161
   622
lemmas induct_atomize = atomize_conj induct_forall_eq induct_implies_eq induct_equal_eq
wenzelm@12161
   623
lemmas induct_rulify1 [symmetric, standard] = induct_forall_eq induct_implies_eq induct_equal_eq
wenzelm@12161
   624
lemmas induct_rulify2 = induct_forall_def induct_implies_def induct_equal_def induct_conj_def
wenzelm@11989
   625
lemmas induct_conj = induct_forall_conj induct_implies_conj induct_conj_curry
wenzelm@11824
   626
wenzelm@11989
   627
hide const induct_forall induct_implies induct_equal induct_conj
wenzelm@11824
   628
wenzelm@11824
   629
wenzelm@11824
   630
text {* Method setup. *}
wenzelm@11824
   631
wenzelm@11824
   632
ML {*
wenzelm@11824
   633
  structure InductMethod = InductMethodFun
wenzelm@11824
   634
  (struct
wenzelm@11824
   635
    val dest_concls = HOLogic.dest_concls;
wenzelm@11824
   636
    val cases_default = thm "case_split";
wenzelm@11989
   637
    val local_impI = thm "induct_impliesI";
wenzelm@11824
   638
    val conjI = thm "conjI";
wenzelm@11989
   639
    val atomize = thms "induct_atomize";
wenzelm@11989
   640
    val rulify1 = thms "induct_rulify1";
wenzelm@11989
   641
    val rulify2 = thms "induct_rulify2";
wenzelm@12240
   642
    val localize = [Thm.symmetric (thm "induct_implies_def")];
wenzelm@11824
   643
  end);
wenzelm@11824
   644
*}
wenzelm@11824
   645
wenzelm@11824
   646
setup InductMethod.setup
wenzelm@11824
   647
wenzelm@11824
   648
wenzelm@11750
   649
subsection {* Order signatures and orders *}
wenzelm@11750
   650
wenzelm@11750
   651
axclass
wenzelm@12338
   652
  ord < type
wenzelm@11750
   653
wenzelm@11750
   654
syntax
wenzelm@11750
   655
  "op <"        :: "['a::ord, 'a] => bool"             ("op <")
wenzelm@11750
   656
  "op <="       :: "['a::ord, 'a] => bool"             ("op <=")
wenzelm@11750
   657
wenzelm@11750
   658
global
wenzelm@11750
   659
wenzelm@11750
   660
consts
wenzelm@11750
   661
  "op <"        :: "['a::ord, 'a] => bool"             ("(_/ < _)"  [50, 51] 50)
wenzelm@11750
   662
  "op <="       :: "['a::ord, 'a] => bool"             ("(_/ <= _)" [50, 51] 50)
wenzelm@11750
   663
wenzelm@11750
   664
local
wenzelm@11750
   665
wenzelm@12114
   666
syntax (xsymbols)
wenzelm@11750
   667
  "op <="       :: "['a::ord, 'a] => bool"             ("op \<le>")
wenzelm@11750
   668
  "op <="       :: "['a::ord, 'a] => bool"             ("(_/ \<le> _)"  [50, 51] 50)
wenzelm@11750
   669
kleing@14565
   670
syntax (HTML output)
kleing@14565
   671
  "op <="       :: "['a::ord, 'a] => bool"             ("op \<le>")
kleing@14565
   672
  "op <="       :: "['a::ord, 'a] => bool"             ("(_/ \<le> _)"  [50, 51] 50)
kleing@14565
   673
nipkow@15354
   674
text{* Syntactic sugar: *}
wenzelm@11750
   675
nipkow@15354
   676
consts
nipkow@15354
   677
  "_gt" :: "'a::ord => 'a => bool"             (infixl ">" 50)
nipkow@15354
   678
  "_ge" :: "'a::ord => 'a => bool"             (infixl ">=" 50)
nipkow@15354
   679
translations
nipkow@15354
   680
  "x > y"  => "y < x"
nipkow@15354
   681
  "x >= y" => "y <= x"
nipkow@15354
   682
nipkow@15354
   683
syntax (xsymbols)
nipkow@15354
   684
  "_ge"       :: "'a::ord => 'a => bool"             (infixl "\<ge>" 50)
nipkow@15354
   685
nipkow@15354
   686
syntax (HTML output)
nipkow@15354
   687
  "_ge"       :: "['a::ord, 'a] => bool"             (infixl "\<ge>" 50)
nipkow@15354
   688
paulson@14295
   689
wenzelm@11750
   690
subsubsection {* Monotonicity *}
wenzelm@11750
   691
wenzelm@13412
   692
locale mono =
wenzelm@13412
   693
  fixes f
wenzelm@13412
   694
  assumes mono: "A <= B ==> f A <= f B"
wenzelm@11750
   695
wenzelm@13421
   696
lemmas monoI [intro?] = mono.intro
wenzelm@13412
   697
  and monoD [dest?] = mono.mono
wenzelm@11750
   698
wenzelm@11750
   699
constdefs
wenzelm@11750
   700
  min :: "['a::ord, 'a] => 'a"
wenzelm@11750
   701
  "min a b == (if a <= b then a else b)"
wenzelm@11750
   702
  max :: "['a::ord, 'a] => 'a"
wenzelm@11750
   703
  "max a b == (if a <= b then b else a)"
wenzelm@11750
   704
wenzelm@11750
   705
lemma min_leastL: "(!!x. least <= x) ==> min least x = least"
wenzelm@11750
   706
  by (simp add: min_def)
wenzelm@11750
   707
wenzelm@11750
   708
lemma min_of_mono:
wenzelm@11750
   709
    "ALL x y. (f x <= f y) = (x <= y) ==> min (f m) (f n) = f (min m n)"
wenzelm@11750
   710
  by (simp add: min_def)
wenzelm@11750
   711
wenzelm@11750
   712
lemma max_leastL: "(!!x. least <= x) ==> max least x = x"
wenzelm@11750
   713
  by (simp add: max_def)
wenzelm@11750
   714
wenzelm@11750
   715
lemma max_of_mono:
wenzelm@11750
   716
    "ALL x y. (f x <= f y) = (x <= y) ==> max (f m) (f n) = f (max m n)"
wenzelm@11750
   717
  by (simp add: max_def)
wenzelm@11750
   718
wenzelm@11750
   719
wenzelm@11750
   720
subsubsection "Orders"
wenzelm@11750
   721
wenzelm@11750
   722
axclass order < ord
wenzelm@11750
   723
  order_refl [iff]: "x <= x"
wenzelm@11750
   724
  order_trans: "x <= y ==> y <= z ==> x <= z"
wenzelm@11750
   725
  order_antisym: "x <= y ==> y <= x ==> x = y"
wenzelm@11750
   726
  order_less_le: "(x < y) = (x <= y & x ~= y)"
wenzelm@11750
   727
wenzelm@11750
   728
wenzelm@11750
   729
text {* Reflexivity. *}
wenzelm@11750
   730
wenzelm@11750
   731
lemma order_eq_refl: "!!x::'a::order. x = y ==> x <= y"
wenzelm@11750
   732
    -- {* This form is useful with the classical reasoner. *}
wenzelm@11750
   733
  apply (erule ssubst)
wenzelm@11750
   734
  apply (rule order_refl)
wenzelm@11750
   735
  done
wenzelm@11750
   736
nipkow@13553
   737
lemma order_less_irrefl [iff]: "~ x < (x::'a::order)"
wenzelm@11750
   738
  by (simp add: order_less_le)
wenzelm@11750
   739
wenzelm@11750
   740
lemma order_le_less: "((x::'a::order) <= y) = (x < y | x = y)"
wenzelm@11750
   741
    -- {* NOT suitable for iff, since it can cause PROOF FAILED. *}
paulson@14208
   742
  apply (simp add: order_less_le, blast)
wenzelm@11750
   743
  done
wenzelm@11750
   744
wenzelm@11750
   745
lemmas order_le_imp_less_or_eq = order_le_less [THEN iffD1, standard]
wenzelm@11750
   746
wenzelm@11750
   747
lemma order_less_imp_le: "!!x::'a::order. x < y ==> x <= y"
wenzelm@11750
   748
  by (simp add: order_less_le)
wenzelm@11750
   749
wenzelm@11750
   750
wenzelm@11750
   751
text {* Asymmetry. *}
wenzelm@11750
   752
wenzelm@11750
   753
lemma order_less_not_sym: "(x::'a::order) < y ==> ~ (y < x)"
wenzelm@11750
   754
  by (simp add: order_less_le order_antisym)
wenzelm@11750
   755
wenzelm@11750
   756
lemma order_less_asym: "x < (y::'a::order) ==> (~P ==> y < x) ==> P"
wenzelm@11750
   757
  apply (drule order_less_not_sym)
paulson@14208
   758
  apply (erule contrapos_np, simp)
wenzelm@11750
   759
  done
wenzelm@11750
   760
paulson@14295
   761
lemma order_eq_iff: "!!x::'a::order. (x = y) = (x \<le> y & y \<le> x)"  
paulson@14295
   762
by (blast intro: order_antisym)
paulson@14295
   763
nipkow@15197
   764
lemma order_antisym_conv: "(y::'a::order) <= x ==> (x <= y) = (x = y)"
nipkow@15197
   765
by(blast intro:order_antisym)
wenzelm@11750
   766
wenzelm@11750
   767
text {* Transitivity. *}
wenzelm@11750
   768
wenzelm@11750
   769
lemma order_less_trans: "!!x::'a::order. [| x < y; y < z |] ==> x < z"
wenzelm@11750
   770
  apply (simp add: order_less_le)
wenzelm@11750
   771
  apply (blast intro: order_trans order_antisym)
wenzelm@11750
   772
  done
wenzelm@11750
   773
wenzelm@11750
   774
lemma order_le_less_trans: "!!x::'a::order. [| x <= y; y < z |] ==> x < z"
wenzelm@11750
   775
  apply (simp add: order_less_le)
wenzelm@11750
   776
  apply (blast intro: order_trans order_antisym)
wenzelm@11750
   777
  done
wenzelm@11750
   778
wenzelm@11750
   779
lemma order_less_le_trans: "!!x::'a::order. [| x < y; y <= z |] ==> x < z"
wenzelm@11750
   780
  apply (simp add: order_less_le)
wenzelm@11750
   781
  apply (blast intro: order_trans order_antisym)
wenzelm@11750
   782
  done
wenzelm@11750
   783
wenzelm@11750
   784
wenzelm@11750
   785
text {* Useful for simplification, but too risky to include by default. *}
wenzelm@11750
   786
wenzelm@11750
   787
lemma order_less_imp_not_less: "(x::'a::order) < y ==>  (~ y < x) = True"
wenzelm@11750
   788
  by (blast elim: order_less_asym)
wenzelm@11750
   789
wenzelm@11750
   790
lemma order_less_imp_triv: "(x::'a::order) < y ==>  (y < x --> P) = True"
wenzelm@11750
   791
  by (blast elim: order_less_asym)
wenzelm@11750
   792
wenzelm@11750
   793
lemma order_less_imp_not_eq: "(x::'a::order) < y ==>  (x = y) = False"
wenzelm@11750
   794
  by auto
wenzelm@11750
   795
wenzelm@11750
   796
lemma order_less_imp_not_eq2: "(x::'a::order) < y ==>  (y = x) = False"
wenzelm@11750
   797
  by auto
wenzelm@11750
   798
wenzelm@11750
   799
wenzelm@11750
   800
text {* Other operators. *}
wenzelm@11750
   801
wenzelm@11750
   802
lemma min_leastR: "(!!x::'a::order. least <= x) ==> min x least = least"
wenzelm@11750
   803
  apply (simp add: min_def)
wenzelm@11750
   804
  apply (blast intro: order_antisym)
wenzelm@11750
   805
  done
wenzelm@11750
   806
wenzelm@11750
   807
lemma max_leastR: "(!!x::'a::order. least <= x) ==> max x least = x"
wenzelm@11750
   808
  apply (simp add: max_def)
wenzelm@11750
   809
  apply (blast intro: order_antisym)
wenzelm@11750
   810
  done
wenzelm@11750
   811
wenzelm@11750
   812
wenzelm@11750
   813
subsubsection {* Least value operator *}
wenzelm@11750
   814
wenzelm@11750
   815
constdefs
wenzelm@11750
   816
  Least :: "('a::ord => bool) => 'a"               (binder "LEAST " 10)
wenzelm@11750
   817
  "Least P == THE x. P x & (ALL y. P y --> x <= y)"
wenzelm@11750
   818
    -- {* We can no longer use LeastM because the latter requires Hilbert-AC. *}
wenzelm@11750
   819
wenzelm@11750
   820
lemma LeastI2:
wenzelm@11750
   821
  "[| P (x::'a::order);
wenzelm@11750
   822
      !!y. P y ==> x <= y;
wenzelm@11750
   823
      !!x. [| P x; ALL y. P y --> x \<le> y |] ==> Q x |]
wenzelm@12281
   824
   ==> Q (Least P)"
wenzelm@11750
   825
  apply (unfold Least_def)
wenzelm@11750
   826
  apply (rule theI2)
wenzelm@11750
   827
    apply (blast intro: order_antisym)+
wenzelm@11750
   828
  done
wenzelm@11750
   829
wenzelm@11750
   830
lemma Least_equality:
wenzelm@12281
   831
    "[| P (k::'a::order); !!x. P x ==> k <= x |] ==> (LEAST x. P x) = k"
wenzelm@11750
   832
  apply (simp add: Least_def)
wenzelm@11750
   833
  apply (rule the_equality)
wenzelm@11750
   834
  apply (auto intro!: order_antisym)
wenzelm@11750
   835
  done
wenzelm@11750
   836
wenzelm@11750
   837
wenzelm@11750
   838
subsubsection "Linear / total orders"
wenzelm@11750
   839
wenzelm@11750
   840
axclass linorder < order
wenzelm@11750
   841
  linorder_linear: "x <= y | y <= x"
wenzelm@11750
   842
wenzelm@11750
   843
lemma linorder_less_linear: "!!x::'a::linorder. x<y | x=y | y<x"
wenzelm@11750
   844
  apply (simp add: order_less_le)
paulson@14208
   845
  apply (insert linorder_linear, blast)
wenzelm@11750
   846
  done
wenzelm@11750
   847
paulson@15079
   848
lemma linorder_le_less_linear: "!!x::'a::linorder. x\<le>y | y<x"
paulson@15079
   849
  by (simp add: order_le_less linorder_less_linear)
paulson@15079
   850
paulson@14365
   851
lemma linorder_le_cases [case_names le ge]:
paulson@14365
   852
    "((x::'a::linorder) \<le> y ==> P) ==> (y \<le> x ==> P) ==> P"
paulson@14365
   853
  by (insert linorder_linear, blast)
paulson@14365
   854
wenzelm@11750
   855
lemma linorder_cases [case_names less equal greater]:
wenzelm@11750
   856
    "((x::'a::linorder) < y ==> P) ==> (x = y ==> P) ==> (y < x ==> P) ==> P"
paulson@14365
   857
  by (insert linorder_less_linear, blast)
wenzelm@11750
   858
wenzelm@11750
   859
lemma linorder_not_less: "!!x::'a::linorder. (~ x < y) = (y <= x)"
wenzelm@11750
   860
  apply (simp add: order_less_le)
wenzelm@11750
   861
  apply (insert linorder_linear)
wenzelm@11750
   862
  apply (blast intro: order_antisym)
wenzelm@11750
   863
  done
wenzelm@11750
   864
wenzelm@11750
   865
lemma linorder_not_le: "!!x::'a::linorder. (~ x <= y) = (y < x)"
wenzelm@11750
   866
  apply (simp add: order_less_le)
wenzelm@11750
   867
  apply (insert linorder_linear)
wenzelm@11750
   868
  apply (blast intro: order_antisym)
wenzelm@11750
   869
  done
wenzelm@11750
   870
wenzelm@11750
   871
lemma linorder_neq_iff: "!!x::'a::linorder. (x ~= y) = (x<y | y<x)"
paulson@14208
   872
by (cut_tac x = x and y = y in linorder_less_linear, auto)
wenzelm@11750
   873
wenzelm@11750
   874
lemma linorder_neqE: "x ~= (y::'a::linorder) ==> (x < y ==> R) ==> (y < x ==> R) ==> R"
paulson@14208
   875
by (simp add: linorder_neq_iff, blast)
wenzelm@11750
   876
nipkow@15197
   877
lemma linorder_antisym_conv1: "~ (x::'a::linorder) < y ==> (x <= y) = (x = y)"
nipkow@15197
   878
by(blast intro:order_antisym dest:linorder_not_less[THEN iffD1])
nipkow@15197
   879
nipkow@15197
   880
lemma linorder_antisym_conv2: "(x::'a::linorder) <= y ==> (~ x < y) = (x = y)"
nipkow@15197
   881
by(blast intro:order_antisym dest:linorder_not_less[THEN iffD1])
nipkow@15197
   882
nipkow@15197
   883
lemma linorder_antisym_conv3: "~ (y::'a::linorder) < x ==> (~ x < y) = (x = y)"
nipkow@15197
   884
by(blast intro:order_antisym dest:linorder_not_less[THEN iffD1])
nipkow@15197
   885
nipkow@15197
   886
use "antisym_setup.ML";
nipkow@15197
   887
setup antisym_setup
wenzelm@11750
   888
wenzelm@11750
   889
subsubsection "Min and max on (linear) orders"
wenzelm@11750
   890
wenzelm@11750
   891
lemma min_same [simp]: "min (x::'a::order) x = x"
wenzelm@11750
   892
  by (simp add: min_def)
wenzelm@11750
   893
wenzelm@11750
   894
lemma max_same [simp]: "max (x::'a::order) x = x"
wenzelm@11750
   895
  by (simp add: max_def)
wenzelm@11750
   896
wenzelm@11750
   897
lemma le_max_iff_disj: "!!z::'a::linorder. (z <= max x y) = (z <= x | z <= y)"
wenzelm@11750
   898
  apply (simp add: max_def)
wenzelm@11750
   899
  apply (insert linorder_linear)
wenzelm@11750
   900
  apply (blast intro: order_trans)
wenzelm@11750
   901
  done
wenzelm@11750
   902
wenzelm@11750
   903
lemma le_maxI1: "(x::'a::linorder) <= max x y"
wenzelm@11750
   904
  by (simp add: le_max_iff_disj)
wenzelm@11750
   905
wenzelm@11750
   906
lemma le_maxI2: "(y::'a::linorder) <= max x y"
wenzelm@11750
   907
    -- {* CANNOT use with @{text "[intro!]"} because blast will give PROOF FAILED. *}
wenzelm@11750
   908
  by (simp add: le_max_iff_disj)
wenzelm@11750
   909
wenzelm@11750
   910
lemma less_max_iff_disj: "!!z::'a::linorder. (z < max x y) = (z < x | z < y)"
wenzelm@11750
   911
  apply (simp add: max_def order_le_less)
wenzelm@11750
   912
  apply (insert linorder_less_linear)
wenzelm@11750
   913
  apply (blast intro: order_less_trans)
wenzelm@11750
   914
  done
wenzelm@11750
   915
wenzelm@11750
   916
lemma max_le_iff_conj [simp]:
wenzelm@11750
   917
    "!!z::'a::linorder. (max x y <= z) = (x <= z & y <= z)"
wenzelm@11750
   918
  apply (simp add: max_def)
wenzelm@11750
   919
  apply (insert linorder_linear)
wenzelm@11750
   920
  apply (blast intro: order_trans)
wenzelm@11750
   921
  done
wenzelm@11750
   922
wenzelm@11750
   923
lemma max_less_iff_conj [simp]:
wenzelm@11750
   924
    "!!z::'a::linorder. (max x y < z) = (x < z & y < z)"
wenzelm@11750
   925
  apply (simp add: order_le_less max_def)
wenzelm@11750
   926
  apply (insert linorder_less_linear)
wenzelm@11750
   927
  apply (blast intro: order_less_trans)
wenzelm@11750
   928
  done
wenzelm@11750
   929
wenzelm@11750
   930
lemma le_min_iff_conj [simp]:
wenzelm@11750
   931
    "!!z::'a::linorder. (z <= min x y) = (z <= x & z <= y)"
wenzelm@12892
   932
    -- {* @{text "[iff]"} screws up a @{text blast} in MiniML *}
wenzelm@11750
   933
  apply (simp add: min_def)
wenzelm@11750
   934
  apply (insert linorder_linear)
wenzelm@11750
   935
  apply (blast intro: order_trans)
wenzelm@11750
   936
  done
wenzelm@11750
   937
wenzelm@11750
   938
lemma min_less_iff_conj [simp]:
wenzelm@11750
   939
    "!!z::'a::linorder. (z < min x y) = (z < x & z < y)"
wenzelm@11750
   940
  apply (simp add: order_le_less min_def)
wenzelm@11750
   941
  apply (insert linorder_less_linear)
wenzelm@11750
   942
  apply (blast intro: order_less_trans)
wenzelm@11750
   943
  done
wenzelm@11750
   944
wenzelm@11750
   945
lemma min_le_iff_disj: "!!z::'a::linorder. (min x y <= z) = (x <= z | y <= z)"
wenzelm@11750
   946
  apply (simp add: min_def)
wenzelm@11750
   947
  apply (insert linorder_linear)
wenzelm@11750
   948
  apply (blast intro: order_trans)
wenzelm@11750
   949
  done
wenzelm@11750
   950
wenzelm@11750
   951
lemma min_less_iff_disj: "!!z::'a::linorder. (min x y < z) = (x < z | y < z)"
wenzelm@11750
   952
  apply (simp add: min_def order_le_less)
wenzelm@11750
   953
  apply (insert linorder_less_linear)
wenzelm@11750
   954
  apply (blast intro: order_less_trans)
wenzelm@11750
   955
  done
wenzelm@11750
   956
nipkow@13438
   957
lemma max_assoc: "!!x::'a::linorder. max (max x y) z = max x (max y z)"
nipkow@13438
   958
apply(simp add:max_def)
nipkow@13438
   959
apply(rule conjI)
nipkow@13438
   960
apply(blast intro:order_trans)
nipkow@13438
   961
apply(simp add:linorder_not_le)
nipkow@13438
   962
apply(blast dest: order_less_trans order_le_less_trans)
nipkow@13438
   963
done
nipkow@13438
   964
nipkow@13438
   965
lemma max_commute: "!!x::'a::linorder. max x y = max y x"
nipkow@13438
   966
apply(simp add:max_def)
nipkow@13438
   967
apply(simp add:linorder_not_le)
nipkow@13438
   968
apply(blast dest: order_less_trans)
nipkow@13438
   969
done
nipkow@13438
   970
nipkow@13438
   971
lemmas max_ac = max_assoc max_commute
nipkow@13438
   972
                mk_left_commute[of max,OF max_assoc max_commute]
nipkow@13438
   973
nipkow@13438
   974
lemma min_assoc: "!!x::'a::linorder. min (min x y) z = min x (min y z)"
nipkow@13438
   975
apply(simp add:min_def)
nipkow@13438
   976
apply(rule conjI)
nipkow@13438
   977
apply(blast intro:order_trans)
nipkow@13438
   978
apply(simp add:linorder_not_le)
nipkow@13438
   979
apply(blast dest: order_less_trans order_le_less_trans)
nipkow@13438
   980
done
nipkow@13438
   981
nipkow@13438
   982
lemma min_commute: "!!x::'a::linorder. min x y = min y x"
nipkow@13438
   983
apply(simp add:min_def)
nipkow@13438
   984
apply(simp add:linorder_not_le)
nipkow@13438
   985
apply(blast dest: order_less_trans)
nipkow@13438
   986
done
nipkow@13438
   987
nipkow@13438
   988
lemmas min_ac = min_assoc min_commute
nipkow@13438
   989
                mk_left_commute[of min,OF min_assoc min_commute]
nipkow@13438
   990
wenzelm@11750
   991
lemma split_min:
wenzelm@11750
   992
    "P (min (i::'a::linorder) j) = ((i <= j --> P(i)) & (~ i <= j --> P(j)))"
wenzelm@11750
   993
  by (simp add: min_def)
wenzelm@11750
   994
wenzelm@11750
   995
lemma split_max:
wenzelm@11750
   996
    "P (max (i::'a::linorder) j) = ((i <= j --> P(j)) & (~ i <= j --> P(i)))"
wenzelm@11750
   997
  by (simp add: max_def)
wenzelm@11750
   998
wenzelm@11750
   999
ballarin@14398
  1000
subsubsection {* Transitivity rules for calculational reasoning *}
ballarin@14398
  1001
ballarin@14398
  1002
ballarin@14398
  1003
lemma order_neq_le_trans: "a ~= b ==> (a::'a::order) <= b ==> a < b"
ballarin@14398
  1004
  by (simp add: order_less_le)
ballarin@14398
  1005
ballarin@14398
  1006
lemma order_le_neq_trans: "(a::'a::order) <= b ==> a ~= b ==> a < b"
ballarin@14398
  1007
  by (simp add: order_less_le)
ballarin@14398
  1008
ballarin@14398
  1009
lemma order_less_asym': "(a::'a::order) < b ==> b < a ==> P"
ballarin@14398
  1010
  by (rule order_less_asym)
ballarin@14398
  1011
ballarin@14398
  1012
ballarin@14444
  1013
subsubsection {* Setup of transitivity reasoner as Solver *}
ballarin@14398
  1014
ballarin@14398
  1015
lemma less_imp_neq: "[| (x::'a::order) < y |] ==> x ~= y"
ballarin@14398
  1016
  by (erule contrapos_pn, erule subst, rule order_less_irrefl)
ballarin@14398
  1017
ballarin@14398
  1018
lemma eq_neq_eq_imp_neq: "[| x = a ; a ~= b; b = y |] ==> x ~= y"
ballarin@14398
  1019
  by (erule subst, erule ssubst, assumption)
ballarin@14398
  1020
ballarin@14398
  1021
ML_setup {*
ballarin@14398
  1022
ballarin@15103
  1023
(* The setting up of Quasi_Tac serves as a demo.  Since there is no
ballarin@15103
  1024
   class for quasi orders, the tactics Quasi_Tac.trans_tac and
ballarin@15103
  1025
   Quasi_Tac.quasi_tac are not of much use. *)
ballarin@15103
  1026
paulson@15288
  1027
fun decomp_gen sort sign (Trueprop $ t) =
paulson@15288
  1028
  let fun of_sort t = Sign.of_sort sign (type_of t, sort)
paulson@15288
  1029
  fun dec (Const ("Not", _) $ t) = (
paulson@15288
  1030
	  case dec t of
paulson@15288
  1031
	    None => None
paulson@15288
  1032
	  | Some (t1, rel, t2) => Some (t1, "~" ^ rel, t2))
paulson@15288
  1033
	| dec (Const ("op =",  _) $ t1 $ t2) = 
paulson@15288
  1034
	    if of_sort t1
paulson@15288
  1035
	    then Some (t1, "=", t2)
paulson@15288
  1036
	    else None
paulson@15288
  1037
	| dec (Const ("op <=",  _) $ t1 $ t2) = 
paulson@15288
  1038
	    if of_sort t1
paulson@15288
  1039
	    then Some (t1, "<=", t2)
paulson@15288
  1040
	    else None
paulson@15288
  1041
	| dec (Const ("op <",  _) $ t1 $ t2) = 
paulson@15288
  1042
	    if of_sort t1
paulson@15288
  1043
	    then Some (t1, "<", t2)
paulson@15288
  1044
	    else None
paulson@15288
  1045
	| dec _ = None
paulson@15288
  1046
  in dec t end;
paulson@15288
  1047
ballarin@15103
  1048
structure Quasi_Tac = Quasi_Tac_Fun (
ballarin@15103
  1049
  struct
ballarin@15103
  1050
    val le_trans = thm "order_trans";
ballarin@15103
  1051
    val le_refl = thm "order_refl";
ballarin@15103
  1052
    val eqD1 = thm "order_eq_refl";
ballarin@15103
  1053
    val eqD2 = thm "sym" RS thm "order_eq_refl";
ballarin@15103
  1054
    val less_reflE = thm "order_less_irrefl" RS thm "notE";
ballarin@15103
  1055
    val less_imp_le = thm "order_less_imp_le";
ballarin@15103
  1056
    val le_neq_trans = thm "order_le_neq_trans";
ballarin@15103
  1057
    val neq_le_trans = thm "order_neq_le_trans";
ballarin@15103
  1058
    val less_imp_neq = thm "less_imp_neq";
ballarin@15103
  1059
    val decomp_trans = decomp_gen ["HOL.order"];
ballarin@15103
  1060
    val decomp_quasi = decomp_gen ["HOL.order"];
ballarin@15103
  1061
ballarin@15103
  1062
  end);  (* struct *)
ballarin@15103
  1063
ballarin@15103
  1064
structure Order_Tac = Order_Tac_Fun (
ballarin@14398
  1065
  struct
ballarin@14398
  1066
    val less_reflE = thm "order_less_irrefl" RS thm "notE";
ballarin@14398
  1067
    val le_refl = thm "order_refl";
ballarin@14398
  1068
    val less_imp_le = thm "order_less_imp_le";
ballarin@14398
  1069
    val not_lessI = thm "linorder_not_less" RS thm "iffD2";
ballarin@14398
  1070
    val not_leI = thm "linorder_not_le" RS thm "iffD2";
ballarin@14398
  1071
    val not_lessD = thm "linorder_not_less" RS thm "iffD1";
ballarin@14398
  1072
    val not_leD = thm "linorder_not_le" RS thm "iffD1";
ballarin@14398
  1073
    val eqI = thm "order_antisym";
ballarin@14398
  1074
    val eqD1 = thm "order_eq_refl";
ballarin@14398
  1075
    val eqD2 = thm "sym" RS thm "order_eq_refl";
ballarin@14398
  1076
    val less_trans = thm "order_less_trans";
ballarin@14398
  1077
    val less_le_trans = thm "order_less_le_trans";
ballarin@14398
  1078
    val le_less_trans = thm "order_le_less_trans";
ballarin@14398
  1079
    val le_trans = thm "order_trans";
ballarin@14398
  1080
    val le_neq_trans = thm "order_le_neq_trans";
ballarin@14398
  1081
    val neq_le_trans = thm "order_neq_le_trans";
ballarin@14398
  1082
    val less_imp_neq = thm "less_imp_neq";
ballarin@14398
  1083
    val eq_neq_eq_imp_neq = thm "eq_neq_eq_imp_neq";
ballarin@14398
  1084
    val decomp_part = decomp_gen ["HOL.order"];
ballarin@14398
  1085
    val decomp_lin = decomp_gen ["HOL.linorder"];
ballarin@14398
  1086
ballarin@14398
  1087
  end);  (* struct *)
ballarin@14398
  1088
wenzelm@14590
  1089
simpset_ref() := simpset ()
ballarin@15103
  1090
    addSolver (mk_solver "Trans_linear" (fn _ => Order_Tac.linear_tac))
ballarin@15103
  1091
    addSolver (mk_solver "Trans_partial" (fn _ => Order_Tac.partial_tac));
ballarin@14444
  1092
  (* Adding the transitivity reasoners also as safe solvers showed a slight
ballarin@14444
  1093
     speed up, but the reasoning strength appears to be not higher (at least
ballarin@14444
  1094
     no breaking of additional proofs in the entire HOL distribution, as
ballarin@14444
  1095
     of 5 March 2004, was observed). *)
ballarin@14398
  1096
*}
ballarin@14398
  1097
ballarin@15103
  1098
(* Optional setup of methods *)
ballarin@14398
  1099
ballarin@15103
  1100
(*
ballarin@14398
  1101
method_setup trans_partial =
ballarin@15103
  1102
  {* Method.no_args (Method.SIMPLE_METHOD' HEADGOAL (Order_Tac.partial_tac)) *}
ballarin@15103
  1103
  {* transitivity reasoner for partial orders *}	    
ballarin@14398
  1104
method_setup trans_linear =
ballarin@15103
  1105
  {* Method.no_args (Method.SIMPLE_METHOD' HEADGOAL (Order_Tac.linear_tac)) *}
ballarin@15103
  1106
  {* transitivity reasoner for linear orders *}
ballarin@14398
  1107
*)
ballarin@14398
  1108
ballarin@14444
  1109
(*
ballarin@14444
  1110
declare order.order_refl [simp del] order_less_irrefl [simp del]
ballarin@15103
  1111
ballarin@15103
  1112
can currently not be removed, abel_cancel relies on it.
ballarin@14444
  1113
*)
ballarin@14444
  1114
wenzelm@11750
  1115
subsubsection "Bounded quantifiers"
wenzelm@11750
  1116
wenzelm@11750
  1117
syntax
wenzelm@11750
  1118
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3ALL _<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
  1119
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3EX _<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
  1120
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3ALL _<=_./ _)" [0, 0, 10] 10)
wenzelm@11750
  1121
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3EX _<=_./ _)" [0, 0, 10] 10)
wenzelm@11750
  1122
nipkow@15360
  1123
  "_gtAll" :: "[idt, 'a, bool] => bool"   ("(3ALL _>_./ _)"  [0, 0, 10] 10)
nipkow@15360
  1124
  "_gtEx"  :: "[idt, 'a, bool] => bool"   ("(3EX _>_./ _)"  [0, 0, 10] 10)
nipkow@15360
  1125
  "_geAll"   :: "[idt, 'a, bool] => bool"   ("(3ALL _>=_./ _)" [0, 0, 10] 10)
nipkow@15360
  1126
  "_geEx"    :: "[idt, 'a, bool] => bool"   ("(3EX _>=_./ _)" [0, 0, 10] 10)
nipkow@15360
  1127
wenzelm@12114
  1128
syntax (xsymbols)
wenzelm@11750
  1129
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
  1130
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
  1131
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
wenzelm@11750
  1132
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
wenzelm@11750
  1133
nipkow@15360
  1134
  "_gtAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_>_./ _)"  [0, 0, 10] 10)
nipkow@15360
  1135
  "_gtEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_>_./ _)"  [0, 0, 10] 10)
nipkow@15360
  1136
  "_geAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<ge>_./ _)" [0, 0, 10] 10)
nipkow@15360
  1137
  "_geEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<ge>_./ _)" [0, 0, 10] 10)
nipkow@15360
  1138
wenzelm@11750
  1139
syntax (HOL)
wenzelm@11750
  1140
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3! _<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
  1141
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3? _<_./ _)"  [0, 0, 10] 10)
wenzelm@11750
  1142
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3! _<=_./ _)" [0, 0, 10] 10)
wenzelm@11750
  1143
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3? _<=_./ _)" [0, 0, 10] 10)
wenzelm@11750
  1144
kleing@14565
  1145
syntax (HTML output)
kleing@14565
  1146
  "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
kleing@14565
  1147
  "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
kleing@14565
  1148
  "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
kleing@14565
  1149
  "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
kleing@14565
  1150
nipkow@15360
  1151
  "_gtAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_>_./ _)"  [0, 0, 10] 10)
nipkow@15360
  1152
  "_gtEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_>_./ _)"  [0, 0, 10] 10)
nipkow@15360
  1153
  "_geAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<ge>_./ _)" [0, 0, 10] 10)
nipkow@15360
  1154
  "_geEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<ge>_./ _)" [0, 0, 10] 10)
nipkow@15360
  1155
wenzelm@11750
  1156
translations
wenzelm@11750
  1157
 "ALL x<y. P"   =>  "ALL x. x < y --> P"
wenzelm@11750
  1158
 "EX x<y. P"    =>  "EX x. x < y  & P"
wenzelm@11750
  1159
 "ALL x<=y. P"  =>  "ALL x. x <= y --> P"
wenzelm@11750
  1160
 "EX x<=y. P"   =>  "EX x. x <= y & P"
nipkow@15360
  1161
 "ALL x>y. P"   =>  "ALL x. x > y --> P"
nipkow@15360
  1162
 "EX x>y. P"    =>  "EX x. x > y  & P"
nipkow@15360
  1163
 "ALL x>=y. P"  =>  "ALL x. x >= y --> P"
nipkow@15360
  1164
 "EX x>=y. P"   =>  "EX x. x >= y & P"
wenzelm@11750
  1165
kleing@14357
  1166
print_translation {*
kleing@14357
  1167
let
nipkow@15363
  1168
  fun mk v v' q n P =
nipkow@15363
  1169
    if v=v' andalso not(v  mem (map fst (Term.add_frees([],n))))
nipkow@15363
  1170
    then Syntax.const q $ Syntax.mark_bound v' $ n $ P else raise Match;
kleing@14357
  1171
  fun all_tr' [Const ("_bound",_) $ Free (v,_), 
kleing@14357
  1172
               Const("op -->",_) $ (Const ("op <",_) $ (Const ("_bound",_) $ Free (v',_)) $ n ) $ P] = 
nipkow@15363
  1173
    mk v v' "_lessAll" n P
kleing@14357
  1174
kleing@14357
  1175
  | all_tr' [Const ("_bound",_) $ Free (v,_), 
kleing@14357
  1176
               Const("op -->",_) $ (Const ("op <=",_) $ (Const ("_bound",_) $ Free (v',_)) $ n ) $ P] = 
nipkow@15363
  1177
    mk v v' "_leAll" n P
nipkow@15362
  1178
nipkow@15362
  1179
  | all_tr' [Const ("_bound",_) $ Free (v,_), 
nipkow@15362
  1180
               Const("op -->",_) $ (Const ("op <",_) $ n $ (Const ("_bound",_) $ Free (v',_))) $ P] = 
nipkow@15363
  1181
    mk v v' "_gtAll" n P
nipkow@15362
  1182
nipkow@15362
  1183
  | all_tr' [Const ("_bound",_) $ Free (v,_), 
nipkow@15362
  1184
               Const("op -->",_) $ (Const ("op <=",_) $ n $ (Const ("_bound",_) $ Free (v',_))) $ P] = 
nipkow@15363
  1185
    mk v v' "_geAll" n P;
kleing@14357
  1186
kleing@14357
  1187
  fun ex_tr' [Const ("_bound",_) $ Free (v,_), 
kleing@14357
  1188
               Const("op &",_) $ (Const ("op <",_) $ (Const ("_bound",_) $ Free (v',_)) $ n ) $ P] = 
nipkow@15363
  1189
    mk v v' "_lessEx" n P
kleing@14357
  1190
kleing@14357
  1191
  | ex_tr' [Const ("_bound",_) $ Free (v,_), 
kleing@14357
  1192
               Const("op &",_) $ (Const ("op <=",_) $ (Const ("_bound",_) $ Free (v',_)) $ n ) $ P] = 
nipkow@15363
  1193
    mk v v' "_leEx" n P
nipkow@15362
  1194
nipkow@15362
  1195
  | ex_tr' [Const ("_bound",_) $ Free (v,_), 
nipkow@15362
  1196
               Const("op &",_) $ (Const ("op <",_) $ n $ (Const ("_bound",_) $ Free (v',_))) $ P] = 
nipkow@15363
  1197
    mk v v' "_gtEx" n P
nipkow@15362
  1198
nipkow@15362
  1199
  | ex_tr' [Const ("_bound",_) $ Free (v,_), 
nipkow@15362
  1200
               Const("op &",_) $ (Const ("op <=",_) $ n $ (Const ("_bound",_) $ Free (v',_))) $ P] = 
nipkow@15363
  1201
    mk v v' "_geEx" n P
kleing@14357
  1202
in
kleing@14357
  1203
[("ALL ", all_tr'), ("EX ", ex_tr')]
clasohm@923
  1204
end
kleing@14357
  1205
*}
kleing@14357
  1206
kleing@14357
  1207
end