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