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