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