src/HOL/HOL.thy
author wenzelm
Wed Jul 24 22:15:55 2002 +0200 (2002-07-24)
changeset 13421 8fcdf4a26468
parent 13412 666137b488a4
child 13438 527811f00c56
permissions -rw-r--r--
simplified locale predicates;
     1 (*  Title:      HOL/HOL.thy
     2     ID:         $Id$
     3     Author:     Tobias Nipkow, Markus Wenzel, and Larry Paulson
     4     License:    GPL (GNU GENERAL PUBLIC LICENSE)
     5 *)
     6 
     7 header {* The basis of Higher-Order Logic *}
     8 
     9 theory HOL = CPure
    10 files ("HOL_lemmas.ML") ("cladata.ML") ("blastdata.ML") ("simpdata.ML"):
    11 
    12 
    13 subsection {* Primitive logic *}
    14 
    15 subsubsection {* Core syntax *}
    16 
    17 classes type < logic
    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 syntax (output)
    79   "="           :: "['a, 'a] => bool"                    (infix 50)
    80   "_not_equal"  :: "['a, 'a] => bool"                    (infix "~=" 50)
    81 
    82 syntax (xsymbols)
    83   Not           :: "bool => bool"                        ("\<not> _" [40] 40)
    84   "op &"        :: "[bool, bool] => bool"                (infixr "\<and>" 35)
    85   "op |"        :: "[bool, bool] => bool"                (infixr "\<or>" 30)
    86   "op -->"      :: "[bool, bool] => bool"                (infixr "\<longrightarrow>" 25)
    87   "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
    88   "ALL "        :: "[idts, bool] => bool"                ("(3\<forall>_./ _)" [0, 10] 10)
    89   "EX "         :: "[idts, bool] => bool"                ("(3\<exists>_./ _)" [0, 10] 10)
    90   "EX! "        :: "[idts, bool] => bool"                ("(3\<exists>!_./ _)" [0, 10] 10)
    91   "_case1"      :: "['a, 'b] => case_syn"                ("(2_ \<Rightarrow>/ _)" 10)
    92 (*"_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ \\<orelse> _")*)
    93 
    94 syntax (xsymbols output)
    95   "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
    96 
    97 syntax (HTML output)
    98   Not           :: "bool => bool"                        ("\<not> _" [40] 40)
    99 
   100 syntax (HOL)
   101   "ALL "        :: "[idts, bool] => bool"                ("(3! _./ _)" [0, 10] 10)
   102   "EX "         :: "[idts, bool] => bool"                ("(3? _./ _)" [0, 10] 10)
   103   "EX! "        :: "[idts, bool] => bool"                ("(3?! _./ _)" [0, 10] 10)
   104 
   105 
   106 subsubsection {* Axioms and basic definitions *}
   107 
   108 axioms
   109   eq_reflection: "(x=y) ==> (x==y)"
   110 
   111   refl:         "t = (t::'a)"
   112   subst:        "[| s = t; P(s) |] ==> P(t::'a)"
   113 
   114   ext:          "(!!x::'a. (f x ::'b) = g x) ==> (%x. f x) = (%x. g x)"
   115     -- {* Extensionality is built into the meta-logic, and this rule expresses *}
   116     -- {* a related property.  It is an eta-expanded version of the traditional *}
   117     -- {* rule, and similar to the ABS rule of HOL *}
   118 
   119   the_eq_trivial: "(THE x. x = a) = (a::'a)"
   120 
   121   impI:         "(P ==> Q) ==> P-->Q"
   122   mp:           "[| P-->Q;  P |] ==> Q"
   123 
   124 defs
   125   True_def:     "True      == ((%x::bool. x) = (%x. x))"
   126   All_def:      "All(P)    == (P = (%x. True))"
   127   Ex_def:       "Ex(P)     == !Q. (!x. P x --> Q) --> Q"
   128   False_def:    "False     == (!P. P)"
   129   not_def:      "~ P       == P-->False"
   130   and_def:      "P & Q     == !R. (P-->Q-->R) --> R"
   131   or_def:       "P | Q     == !R. (P-->R) --> (Q-->R) --> R"
   132   Ex1_def:      "Ex1(P)    == ? x. P(x) & (! y. P(y) --> y=x)"
   133 
   134 axioms
   135   iff:          "(P-->Q) --> (Q-->P) --> (P=Q)"
   136   True_or_False:  "(P=True) | (P=False)"
   137 
   138 defs
   139   Let_def:      "Let s f == f(s)"
   140   if_def:       "If P x y == THE z::'a. (P=True --> z=x) & (P=False --> z=y)"
   141 
   142   arbitrary_def:  "False ==> arbitrary == (THE x. False)"
   143     -- {* @{term arbitrary} is completely unspecified, but is made to appear as a
   144     definition syntactically *}
   145 
   146 
   147 subsubsection {* Generic algebraic operations *}
   148 
   149 axclass zero < type
   150 axclass one < type
   151 axclass plus < type
   152 axclass minus < type
   153 axclass times < type
   154 axclass inverse < type
   155 
   156 global
   157 
   158 consts
   159   "0"           :: "'a::zero"                       ("0")
   160   "1"           :: "'a::one"                        ("1")
   161   "+"           :: "['a::plus, 'a]  => 'a"          (infixl 65)
   162   -             :: "['a::minus, 'a] => 'a"          (infixl 65)
   163   uminus        :: "['a::minus] => 'a"              ("- _" [81] 80)
   164   *             :: "['a::times, 'a] => 'a"          (infixl 70)
   165 
   166 local
   167 
   168 typed_print_translation {*
   169   let
   170     fun tr' c = (c, fn show_sorts => fn T => fn ts =>
   171       if T = dummyT orelse not (! show_types) andalso can Term.dest_Type T then raise Match
   172       else Syntax.const Syntax.constrainC $ Syntax.const c $ Syntax.term_of_typ show_sorts T);
   173   in [tr' "0", tr' "1"] end;
   174 *} -- {* show types that are presumably too general *}
   175 
   176 
   177 consts
   178   abs           :: "'a::minus => 'a"
   179   inverse       :: "'a::inverse => 'a"
   180   divide        :: "['a::inverse, 'a] => 'a"        (infixl "'/" 70)
   181 
   182 syntax (xsymbols)
   183   abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
   184 syntax (HTML output)
   185   abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
   186 
   187 axclass plus_ac0 < plus, zero
   188   commute: "x + y = y + x"
   189   assoc:   "(x + y) + z = x + (y + z)"
   190   zero:    "0 + x = x"
   191 
   192 
   193 subsection {* Theory and package setup *}
   194 
   195 subsubsection {* Basic lemmas *}
   196 
   197 use "HOL_lemmas.ML"
   198 theorems case_split = case_split_thm [case_names True False]
   199 
   200 
   201 subsubsection {* Intuitionistic Reasoning *}
   202 
   203 lemma impE':
   204   assumes 1: "P --> Q"
   205     and 2: "Q ==> R"
   206     and 3: "P --> Q ==> P"
   207   shows R
   208 proof -
   209   from 3 and 1 have P .
   210   with 1 have Q by (rule impE)
   211   with 2 show R .
   212 qed
   213 
   214 lemma allE':
   215   assumes 1: "ALL x. P x"
   216     and 2: "P x ==> ALL x. P x ==> Q"
   217   shows Q
   218 proof -
   219   from 1 have "P x" by (rule spec)
   220   from this and 1 show Q by (rule 2)
   221 qed
   222 
   223 lemma notE':
   224   assumes 1: "~ P"
   225     and 2: "~ P ==> P"
   226   shows R
   227 proof -
   228   from 2 and 1 have P .
   229   with 1 show R by (rule notE)
   230 qed
   231 
   232 lemmas [CPure.elim!] = disjE iffE FalseE conjE exE
   233   and [CPure.intro!] = iffI conjI impI TrueI notI allI refl
   234   and [CPure.elim 2] = allE notE' impE'
   235   and [CPure.intro] = exI disjI2 disjI1
   236 
   237 lemmas [trans] = trans
   238   and [sym] = sym not_sym
   239   and [CPure.elim?] = iffD1 iffD2 impE
   240 
   241 
   242 subsubsection {* Atomizing meta-level connectives *}
   243 
   244 lemma atomize_all [atomize]: "(!!x. P x) == Trueprop (ALL x. P x)"
   245 proof
   246   assume "!!x. P x"
   247   show "ALL x. P x" by (rule allI)
   248 next
   249   assume "ALL x. P x"
   250   thus "!!x. P x" by (rule allE)
   251 qed
   252 
   253 lemma atomize_imp [atomize]: "(A ==> B) == Trueprop (A --> B)"
   254 proof
   255   assume r: "A ==> B"
   256   show "A --> B" by (rule impI) (rule r)
   257 next
   258   assume "A --> B" and A
   259   thus B by (rule mp)
   260 qed
   261 
   262 lemma atomize_eq [atomize]: "(x == y) == Trueprop (x = y)"
   263 proof
   264   assume "x == y"
   265   show "x = y" by (unfold prems) (rule refl)
   266 next
   267   assume "x = y"
   268   thus "x == y" by (rule eq_reflection)
   269 qed
   270 
   271 lemma atomize_conj [atomize]:
   272   "(!!C. (A ==> B ==> PROP C) ==> PROP C) == Trueprop (A & B)"
   273 proof
   274   assume "!!C. (A ==> B ==> PROP C) ==> PROP C"
   275   show "A & B" by (rule conjI)
   276 next
   277   fix C
   278   assume "A & B"
   279   assume "A ==> B ==> PROP C"
   280   thus "PROP C"
   281   proof this
   282     show A by (rule conjunct1)
   283     show B by (rule conjunct2)
   284   qed
   285 qed
   286 
   287 lemmas [symmetric, rulify] = atomize_all atomize_imp
   288 
   289 
   290 subsubsection {* Classical Reasoner setup *}
   291 
   292 use "cladata.ML"
   293 setup hypsubst_setup
   294 
   295 ML_setup {*
   296   Context.>> (ContextRules.addSWrapper (fn tac => hyp_subst_tac' ORELSE' tac));
   297 *}
   298 
   299 setup Classical.setup
   300 setup clasetup
   301 
   302 lemmas [intro?] = ext
   303   and [elim?] = ex1_implies_ex
   304 
   305 use "blastdata.ML"
   306 setup Blast.setup
   307 
   308 
   309 subsubsection {* Simplifier setup *}
   310 
   311 lemma meta_eq_to_obj_eq: "x == y ==> x = y"
   312 proof -
   313   assume r: "x == y"
   314   show "x = y" by (unfold r) (rule refl)
   315 qed
   316 
   317 lemma eta_contract_eq: "(%s. f s) = f" ..
   318 
   319 lemma simp_thms:
   320   shows not_not: "(~ ~ P) = P"
   321   and
   322     "(P ~= Q) = (P = (~Q))"
   323     "(P | ~P) = True"    "(~P | P) = True"
   324     "((~P) = (~Q)) = (P=Q)"
   325     "(x = x) = True"
   326     "(~True) = False"  "(~False) = True"
   327     "(~P) ~= P"  "P ~= (~P)"
   328     "(True=P) = P"  "(P=True) = P"  "(False=P) = (~P)"  "(P=False) = (~P)"
   329     "(True --> P) = P"  "(False --> P) = True"
   330     "(P --> True) = True"  "(P --> P) = True"
   331     "(P --> False) = (~P)"  "(P --> ~P) = (~P)"
   332     "(P & True) = P"  "(True & P) = P"
   333     "(P & False) = False"  "(False & P) = False"
   334     "(P & P) = P"  "(P & (P & Q)) = (P & Q)"
   335     "(P & ~P) = False"    "(~P & P) = False"
   336     "(P | True) = True"  "(True | P) = True"
   337     "(P | False) = P"  "(False | P) = P"
   338     "(P | P) = P"  "(P | (P | Q)) = (P | Q)" and
   339     "(ALL x. P) = P"  "(EX x. P) = P"  "EX x. x=t"  "EX x. t=x"
   340     -- {* needed for the one-point-rule quantifier simplification procs *}
   341     -- {* essential for termination!! *} and
   342     "!!P. (EX x. x=t & P(x)) = P(t)"
   343     "!!P. (EX x. t=x & P(x)) = P(t)"
   344     "!!P. (ALL x. x=t --> P(x)) = P(t)"
   345     "!!P. (ALL x. t=x --> P(x)) = P(t)"
   346   by (blast, blast, blast, blast, blast, rules+)
   347 
   348 lemma imp_cong: "(P = P') ==> (P' ==> (Q = Q')) ==> ((P --> Q) = (P' --> Q'))"
   349   by rules
   350 
   351 lemma ex_simps:
   352   "!!P Q. (EX x. P x & Q)   = ((EX x. P x) & Q)"
   353   "!!P Q. (EX x. P & Q x)   = (P & (EX x. Q x))"
   354   "!!P Q. (EX x. P x | Q)   = ((EX x. P x) | Q)"
   355   "!!P Q. (EX x. P | Q x)   = (P | (EX x. Q x))"
   356   "!!P Q. (EX x. P x --> Q) = ((ALL x. P x) --> Q)"
   357   "!!P Q. (EX x. P --> Q x) = (P --> (EX x. Q x))"
   358   -- {* Miniscoping: pushing in existential quantifiers. *}
   359   by (rules | blast)+
   360 
   361 lemma all_simps:
   362   "!!P Q. (ALL x. P x & Q)   = ((ALL x. P x) & Q)"
   363   "!!P Q. (ALL x. P & Q x)   = (P & (ALL x. Q x))"
   364   "!!P Q. (ALL x. P x | Q)   = ((ALL x. P x) | Q)"
   365   "!!P Q. (ALL x. P | Q x)   = (P | (ALL x. Q x))"
   366   "!!P Q. (ALL x. P x --> Q) = ((EX x. P x) --> Q)"
   367   "!!P Q. (ALL x. P --> Q x) = (P --> (ALL x. Q x))"
   368   -- {* Miniscoping: pushing in universal quantifiers. *}
   369   by (rules | blast)+
   370 
   371 lemma eq_ac:
   372   shows eq_commute: "(a=b) = (b=a)"
   373     and eq_left_commute: "(P=(Q=R)) = (Q=(P=R))"
   374     and eq_assoc: "((P=Q)=R) = (P=(Q=R))" by (rules, blast+)
   375 lemma neq_commute: "(a~=b) = (b~=a)" by rules
   376 
   377 lemma conj_comms:
   378   shows conj_commute: "(P&Q) = (Q&P)"
   379     and conj_left_commute: "(P&(Q&R)) = (Q&(P&R))" by rules+
   380 lemma conj_assoc: "((P&Q)&R) = (P&(Q&R))" by rules
   381 
   382 lemma disj_comms:
   383   shows disj_commute: "(P|Q) = (Q|P)"
   384     and disj_left_commute: "(P|(Q|R)) = (Q|(P|R))" by rules+
   385 lemma disj_assoc: "((P|Q)|R) = (P|(Q|R))" by rules
   386 
   387 lemma conj_disj_distribL: "(P&(Q|R)) = (P&Q | P&R)" by rules
   388 lemma conj_disj_distribR: "((P|Q)&R) = (P&R | Q&R)" by rules
   389 
   390 lemma disj_conj_distribL: "(P|(Q&R)) = ((P|Q) & (P|R))" by rules
   391 lemma disj_conj_distribR: "((P&Q)|R) = ((P|R) & (Q|R))" by rules
   392 
   393 lemma imp_conjR: "(P --> (Q&R)) = ((P-->Q) & (P-->R))" by rules
   394 lemma imp_conjL: "((P&Q) -->R)  = (P --> (Q --> R))" by rules
   395 lemma imp_disjL: "((P|Q) --> R) = ((P-->R)&(Q-->R))" by rules
   396 
   397 text {* These two are specialized, but @{text imp_disj_not1} is useful in @{text "Auth/Yahalom"}. *}
   398 lemma imp_disj_not1: "(P --> Q | R) = (~Q --> P --> R)" by blast
   399 lemma imp_disj_not2: "(P --> Q | R) = (~R --> P --> Q)" by blast
   400 
   401 lemma imp_disj1: "((P-->Q)|R) = (P--> Q|R)" by blast
   402 lemma imp_disj2: "(Q|(P-->R)) = (P--> Q|R)" by blast
   403 
   404 lemma de_Morgan_disj: "(~(P | Q)) = (~P & ~Q)" by rules
   405 lemma de_Morgan_conj: "(~(P & Q)) = (~P | ~Q)" by blast
   406 lemma not_imp: "(~(P --> Q)) = (P & ~Q)" by blast
   407 lemma not_iff: "(P~=Q) = (P = (~Q))" by blast
   408 lemma disj_not1: "(~P | Q) = (P --> Q)" by blast
   409 lemma disj_not2: "(P | ~Q) = (Q --> P)"  -- {* changes orientation :-( *}
   410   by blast
   411 lemma imp_conv_disj: "(P --> Q) = ((~P) | Q)" by blast
   412 
   413 lemma iff_conv_conj_imp: "(P = Q) = ((P --> Q) & (Q --> P))" by rules
   414 
   415 
   416 lemma cases_simp: "((P --> Q) & (~P --> Q)) = Q"
   417   -- {* Avoids duplication of subgoals after @{text split_if}, when the true and false *}
   418   -- {* cases boil down to the same thing. *}
   419   by blast
   420 
   421 lemma not_all: "(~ (! x. P(x))) = (? x.~P(x))" by blast
   422 lemma imp_all: "((! x. P x) --> Q) = (? x. P x --> Q)" by blast
   423 lemma not_ex: "(~ (? x. P(x))) = (! x.~P(x))" by rules
   424 lemma imp_ex: "((? x. P x) --> Q) = (! x. P x --> Q)" by rules
   425 
   426 lemma ex_disj_distrib: "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))" by rules
   427 lemma all_conj_distrib: "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))" by rules
   428 
   429 text {*
   430   \medskip The @{text "&"} congruence rule: not included by default!
   431   May slow rewrite proofs down by as much as 50\% *}
   432 
   433 lemma conj_cong:
   434     "(P = P') ==> (P' ==> (Q = Q')) ==> ((P & Q) = (P' & Q'))"
   435   by rules
   436 
   437 lemma rev_conj_cong:
   438     "(Q = Q') ==> (Q' ==> (P = P')) ==> ((P & Q) = (P' & Q'))"
   439   by rules
   440 
   441 text {* The @{text "|"} congruence rule: not included by default! *}
   442 
   443 lemma disj_cong:
   444     "(P = P') ==> (~P' ==> (Q = Q')) ==> ((P | Q) = (P' | Q'))"
   445   by blast
   446 
   447 lemma eq_sym_conv: "(x = y) = (y = x)"
   448   by rules
   449 
   450 
   451 text {* \medskip if-then-else rules *}
   452 
   453 lemma if_True: "(if True then x else y) = x"
   454   by (unfold if_def) blast
   455 
   456 lemma if_False: "(if False then x else y) = y"
   457   by (unfold if_def) blast
   458 
   459 lemma if_P: "P ==> (if P then x else y) = x"
   460   by (unfold if_def) blast
   461 
   462 lemma if_not_P: "~P ==> (if P then x else y) = y"
   463   by (unfold if_def) blast
   464 
   465 lemma split_if: "P (if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))"
   466   apply (rule case_split [of Q])
   467    apply (subst if_P)
   468     prefer 3 apply (subst if_not_P)
   469      apply blast+
   470   done
   471 
   472 lemma split_if_asm: "P (if Q then x else y) = (~((Q & ~P x) | (~Q & ~P y)))"
   473   apply (subst split_if)
   474   apply blast
   475   done
   476 
   477 lemmas if_splits = split_if split_if_asm
   478 
   479 lemma if_def2: "(if Q then x else y) = ((Q --> x) & (~ Q --> y))"
   480   by (rule split_if)
   481 
   482 lemma if_cancel: "(if c then x else x) = x"
   483   apply (subst split_if)
   484   apply blast
   485   done
   486 
   487 lemma if_eq_cancel: "(if x = y then y else x) = x"
   488   apply (subst split_if)
   489   apply blast
   490   done
   491 
   492 lemma if_bool_eq_conj: "(if P then Q else R) = ((P-->Q) & (~P-->R))"
   493   -- {* This form is useful for expanding @{text if}s on the RIGHT of the @{text "==>"} symbol. *}
   494   by (rule split_if)
   495 
   496 lemma if_bool_eq_disj: "(if P then Q else R) = ((P&Q) | (~P&R))"
   497   -- {* And this form is useful for expanding @{text if}s on the LEFT. *}
   498   apply (subst split_if)
   499   apply blast
   500   done
   501 
   502 lemma Eq_TrueI: "P ==> P == True" by (unfold atomize_eq) rules
   503 lemma Eq_FalseI: "~P ==> P == False" by (unfold atomize_eq) rules
   504 
   505 use "simpdata.ML"
   506 setup Simplifier.setup
   507 setup "Simplifier.method_setup Splitter.split_modifiers" setup simpsetup
   508 setup Splitter.setup setup Clasimp.setup
   509 
   510 
   511 subsubsection {* Generic cases and induction *}
   512 
   513 constdefs
   514   induct_forall :: "('a => bool) => bool"
   515   "induct_forall P == \<forall>x. P x"
   516   induct_implies :: "bool => bool => bool"
   517   "induct_implies A B == A --> B"
   518   induct_equal :: "'a => 'a => bool"
   519   "induct_equal x y == x = y"
   520   induct_conj :: "bool => bool => bool"
   521   "induct_conj A B == A & B"
   522 
   523 lemma induct_forall_eq: "(!!x. P x) == Trueprop (induct_forall (\<lambda>x. P x))"
   524   by (simp only: atomize_all induct_forall_def)
   525 
   526 lemma induct_implies_eq: "(A ==> B) == Trueprop (induct_implies A B)"
   527   by (simp only: atomize_imp induct_implies_def)
   528 
   529 lemma induct_equal_eq: "(x == y) == Trueprop (induct_equal x y)"
   530   by (simp only: atomize_eq induct_equal_def)
   531 
   532 lemma induct_forall_conj: "induct_forall (\<lambda>x. induct_conj (A x) (B x)) =
   533     induct_conj (induct_forall A) (induct_forall B)"
   534   by (unfold induct_forall_def induct_conj_def) rules
   535 
   536 lemma induct_implies_conj: "induct_implies C (induct_conj A B) =
   537     induct_conj (induct_implies C A) (induct_implies C B)"
   538   by (unfold induct_implies_def induct_conj_def) rules
   539 
   540 lemma induct_conj_curry: "(induct_conj A B ==> C) == (A ==> B ==> C)"
   541   by (simp only: atomize_imp atomize_eq induct_conj_def) (rules intro: equal_intr_rule)
   542 
   543 lemma induct_impliesI: "(A ==> B) ==> induct_implies A B"
   544   by (simp add: induct_implies_def)
   545 
   546 lemmas induct_atomize = atomize_conj induct_forall_eq induct_implies_eq induct_equal_eq
   547 lemmas induct_rulify1 [symmetric, standard] = induct_forall_eq induct_implies_eq induct_equal_eq
   548 lemmas induct_rulify2 = induct_forall_def induct_implies_def induct_equal_def induct_conj_def
   549 lemmas induct_conj = induct_forall_conj induct_implies_conj induct_conj_curry
   550 
   551 hide const induct_forall induct_implies induct_equal induct_conj
   552 
   553 
   554 text {* Method setup. *}
   555 
   556 ML {*
   557   structure InductMethod = InductMethodFun
   558   (struct
   559     val dest_concls = HOLogic.dest_concls;
   560     val cases_default = thm "case_split";
   561     val local_impI = thm "induct_impliesI";
   562     val conjI = thm "conjI";
   563     val atomize = thms "induct_atomize";
   564     val rulify1 = thms "induct_rulify1";
   565     val rulify2 = thms "induct_rulify2";
   566     val localize = [Thm.symmetric (thm "induct_implies_def")];
   567   end);
   568 *}
   569 
   570 setup InductMethod.setup
   571 
   572 
   573 subsection {* Order signatures and orders *}
   574 
   575 axclass
   576   ord < type
   577 
   578 syntax
   579   "op <"        :: "['a::ord, 'a] => bool"             ("op <")
   580   "op <="       :: "['a::ord, 'a] => bool"             ("op <=")
   581 
   582 global
   583 
   584 consts
   585   "op <"        :: "['a::ord, 'a] => bool"             ("(_/ < _)"  [50, 51] 50)
   586   "op <="       :: "['a::ord, 'a] => bool"             ("(_/ <= _)" [50, 51] 50)
   587 
   588 local
   589 
   590 syntax (xsymbols)
   591   "op <="       :: "['a::ord, 'a] => bool"             ("op \<le>")
   592   "op <="       :: "['a::ord, 'a] => bool"             ("(_/ \<le> _)"  [50, 51] 50)
   593 
   594 (*Tell blast about overloading of < and <= to reduce the risk of
   595   its applying a rule for the wrong type*)
   596 ML {*
   597 Blast.overloaded ("op <" , domain_type);
   598 Blast.overloaded ("op <=", domain_type);
   599 *}
   600 
   601 
   602 subsubsection {* Monotonicity *}
   603 
   604 locale mono =
   605   fixes f
   606   assumes mono: "A <= B ==> f A <= f B"
   607 
   608 lemmas monoI [intro?] = mono.intro
   609   and monoD [dest?] = mono.mono
   610 
   611 constdefs
   612   min :: "['a::ord, 'a] => 'a"
   613   "min a b == (if a <= b then a else b)"
   614   max :: "['a::ord, 'a] => 'a"
   615   "max a b == (if a <= b then b else a)"
   616 
   617 lemma min_leastL: "(!!x. least <= x) ==> min least x = least"
   618   by (simp add: min_def)
   619 
   620 lemma min_of_mono:
   621     "ALL x y. (f x <= f y) = (x <= y) ==> min (f m) (f n) = f (min m n)"
   622   by (simp add: min_def)
   623 
   624 lemma max_leastL: "(!!x. least <= x) ==> max least x = x"
   625   by (simp add: max_def)
   626 
   627 lemma max_of_mono:
   628     "ALL x y. (f x <= f y) = (x <= y) ==> max (f m) (f n) = f (max m n)"
   629   by (simp add: max_def)
   630 
   631 
   632 subsubsection "Orders"
   633 
   634 axclass order < ord
   635   order_refl [iff]: "x <= x"
   636   order_trans: "x <= y ==> y <= z ==> x <= z"
   637   order_antisym: "x <= y ==> y <= x ==> x = y"
   638   order_less_le: "(x < y) = (x <= y & x ~= y)"
   639 
   640 
   641 text {* Reflexivity. *}
   642 
   643 lemma order_eq_refl: "!!x::'a::order. x = y ==> x <= y"
   644     -- {* This form is useful with the classical reasoner. *}
   645   apply (erule ssubst)
   646   apply (rule order_refl)
   647   done
   648 
   649 lemma order_less_irrefl [simp]: "~ x < (x::'a::order)"
   650   by (simp add: order_less_le)
   651 
   652 lemma order_le_less: "((x::'a::order) <= y) = (x < y | x = y)"
   653     -- {* NOT suitable for iff, since it can cause PROOF FAILED. *}
   654   apply (simp add: order_less_le)
   655   apply blast
   656   done
   657 
   658 lemmas order_le_imp_less_or_eq = order_le_less [THEN iffD1, standard]
   659 
   660 lemma order_less_imp_le: "!!x::'a::order. x < y ==> x <= y"
   661   by (simp add: order_less_le)
   662 
   663 
   664 text {* Asymmetry. *}
   665 
   666 lemma order_less_not_sym: "(x::'a::order) < y ==> ~ (y < x)"
   667   by (simp add: order_less_le order_antisym)
   668 
   669 lemma order_less_asym: "x < (y::'a::order) ==> (~P ==> y < x) ==> P"
   670   apply (drule order_less_not_sym)
   671   apply (erule contrapos_np)
   672   apply simp
   673   done
   674 
   675 
   676 text {* Transitivity. *}
   677 
   678 lemma order_less_trans: "!!x::'a::order. [| x < y; y < z |] ==> x < z"
   679   apply (simp add: order_less_le)
   680   apply (blast intro: order_trans order_antisym)
   681   done
   682 
   683 lemma order_le_less_trans: "!!x::'a::order. [| x <= y; y < z |] ==> x < z"
   684   apply (simp add: order_less_le)
   685   apply (blast intro: order_trans order_antisym)
   686   done
   687 
   688 lemma order_less_le_trans: "!!x::'a::order. [| x < y; y <= z |] ==> x < z"
   689   apply (simp add: order_less_le)
   690   apply (blast intro: order_trans order_antisym)
   691   done
   692 
   693 
   694 text {* Useful for simplification, but too risky to include by default. *}
   695 
   696 lemma order_less_imp_not_less: "(x::'a::order) < y ==>  (~ y < x) = True"
   697   by (blast elim: order_less_asym)
   698 
   699 lemma order_less_imp_triv: "(x::'a::order) < y ==>  (y < x --> P) = True"
   700   by (blast elim: order_less_asym)
   701 
   702 lemma order_less_imp_not_eq: "(x::'a::order) < y ==>  (x = y) = False"
   703   by auto
   704 
   705 lemma order_less_imp_not_eq2: "(x::'a::order) < y ==>  (y = x) = False"
   706   by auto
   707 
   708 
   709 text {* Other operators. *}
   710 
   711 lemma min_leastR: "(!!x::'a::order. least <= x) ==> min x least = least"
   712   apply (simp add: min_def)
   713   apply (blast intro: order_antisym)
   714   done
   715 
   716 lemma max_leastR: "(!!x::'a::order. least <= x) ==> max x least = x"
   717   apply (simp add: max_def)
   718   apply (blast intro: order_antisym)
   719   done
   720 
   721 
   722 subsubsection {* Least value operator *}
   723 
   724 constdefs
   725   Least :: "('a::ord => bool) => 'a"               (binder "LEAST " 10)
   726   "Least P == THE x. P x & (ALL y. P y --> x <= y)"
   727     -- {* We can no longer use LeastM because the latter requires Hilbert-AC. *}
   728 
   729 lemma LeastI2:
   730   "[| P (x::'a::order);
   731       !!y. P y ==> x <= y;
   732       !!x. [| P x; ALL y. P y --> x \<le> y |] ==> Q x |]
   733    ==> Q (Least P)"
   734   apply (unfold Least_def)
   735   apply (rule theI2)
   736     apply (blast intro: order_antisym)+
   737   done
   738 
   739 lemma Least_equality:
   740     "[| P (k::'a::order); !!x. P x ==> k <= x |] ==> (LEAST x. P x) = k"
   741   apply (simp add: Least_def)
   742   apply (rule the_equality)
   743   apply (auto intro!: order_antisym)
   744   done
   745 
   746 
   747 subsubsection "Linear / total orders"
   748 
   749 axclass linorder < order
   750   linorder_linear: "x <= y | y <= x"
   751 
   752 lemma linorder_less_linear: "!!x::'a::linorder. x<y | x=y | y<x"
   753   apply (simp add: order_less_le)
   754   apply (insert linorder_linear)
   755   apply blast
   756   done
   757 
   758 lemma linorder_cases [case_names less equal greater]:
   759     "((x::'a::linorder) < y ==> P) ==> (x = y ==> P) ==> (y < x ==> P) ==> P"
   760   apply (insert linorder_less_linear)
   761   apply blast
   762   done
   763 
   764 lemma linorder_not_less: "!!x::'a::linorder. (~ x < y) = (y <= x)"
   765   apply (simp add: order_less_le)
   766   apply (insert linorder_linear)
   767   apply (blast intro: order_antisym)
   768   done
   769 
   770 lemma linorder_not_le: "!!x::'a::linorder. (~ x <= y) = (y < x)"
   771   apply (simp add: order_less_le)
   772   apply (insert linorder_linear)
   773   apply (blast intro: order_antisym)
   774   done
   775 
   776 lemma linorder_neq_iff: "!!x::'a::linorder. (x ~= y) = (x<y | y<x)"
   777   apply (cut_tac x = x and y = y in linorder_less_linear)
   778   apply auto
   779   done
   780 
   781 lemma linorder_neqE: "x ~= (y::'a::linorder) ==> (x < y ==> R) ==> (y < x ==> R) ==> R"
   782   apply (simp add: linorder_neq_iff)
   783   apply blast
   784   done
   785 
   786 
   787 subsubsection "Min and max on (linear) orders"
   788 
   789 lemma min_same [simp]: "min (x::'a::order) x = x"
   790   by (simp add: min_def)
   791 
   792 lemma max_same [simp]: "max (x::'a::order) x = x"
   793   by (simp add: max_def)
   794 
   795 lemma le_max_iff_disj: "!!z::'a::linorder. (z <= max x y) = (z <= x | z <= y)"
   796   apply (simp add: max_def)
   797   apply (insert linorder_linear)
   798   apply (blast intro: order_trans)
   799   done
   800 
   801 lemma le_maxI1: "(x::'a::linorder) <= max x y"
   802   by (simp add: le_max_iff_disj)
   803 
   804 lemma le_maxI2: "(y::'a::linorder) <= max x y"
   805     -- {* CANNOT use with @{text "[intro!]"} because blast will give PROOF FAILED. *}
   806   by (simp add: le_max_iff_disj)
   807 
   808 lemma less_max_iff_disj: "!!z::'a::linorder. (z < max x y) = (z < x | z < y)"
   809   apply (simp add: max_def order_le_less)
   810   apply (insert linorder_less_linear)
   811   apply (blast intro: order_less_trans)
   812   done
   813 
   814 lemma max_le_iff_conj [simp]:
   815     "!!z::'a::linorder. (max x y <= z) = (x <= z & y <= z)"
   816   apply (simp add: max_def)
   817   apply (insert linorder_linear)
   818   apply (blast intro: order_trans)
   819   done
   820 
   821 lemma max_less_iff_conj [simp]:
   822     "!!z::'a::linorder. (max x y < z) = (x < z & y < z)"
   823   apply (simp add: order_le_less max_def)
   824   apply (insert linorder_less_linear)
   825   apply (blast intro: order_less_trans)
   826   done
   827 
   828 lemma le_min_iff_conj [simp]:
   829     "!!z::'a::linorder. (z <= min x y) = (z <= x & z <= y)"
   830     -- {* @{text "[iff]"} screws up a @{text blast} in MiniML *}
   831   apply (simp add: min_def)
   832   apply (insert linorder_linear)
   833   apply (blast intro: order_trans)
   834   done
   835 
   836 lemma min_less_iff_conj [simp]:
   837     "!!z::'a::linorder. (z < min x y) = (z < x & z < y)"
   838   apply (simp add: order_le_less min_def)
   839   apply (insert linorder_less_linear)
   840   apply (blast intro: order_less_trans)
   841   done
   842 
   843 lemma min_le_iff_disj: "!!z::'a::linorder. (min x y <= z) = (x <= z | y <= z)"
   844   apply (simp add: min_def)
   845   apply (insert linorder_linear)
   846   apply (blast intro: order_trans)
   847   done
   848 
   849 lemma min_less_iff_disj: "!!z::'a::linorder. (min x y < z) = (x < z | y < z)"
   850   apply (simp add: min_def order_le_less)
   851   apply (insert linorder_less_linear)
   852   apply (blast intro: order_less_trans)
   853   done
   854 
   855 lemma split_min:
   856     "P (min (i::'a::linorder) j) = ((i <= j --> P(i)) & (~ i <= j --> P(j)))"
   857   by (simp add: min_def)
   858 
   859 lemma split_max:
   860     "P (max (i::'a::linorder) j) = ((i <= j --> P(j)) & (~ i <= j --> P(i)))"
   861   by (simp add: max_def)
   862 
   863 
   864 subsubsection "Bounded quantifiers"
   865 
   866 syntax
   867   "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3ALL _<_./ _)"  [0, 0, 10] 10)
   868   "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3EX _<_./ _)"  [0, 0, 10] 10)
   869   "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3ALL _<=_./ _)" [0, 0, 10] 10)
   870   "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3EX _<=_./ _)" [0, 0, 10] 10)
   871 
   872 syntax (xsymbols)
   873   "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
   874   "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
   875   "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
   876   "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
   877 
   878 syntax (HOL)
   879   "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3! _<_./ _)"  [0, 0, 10] 10)
   880   "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3? _<_./ _)"  [0, 0, 10] 10)
   881   "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3! _<=_./ _)" [0, 0, 10] 10)
   882   "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3? _<=_./ _)" [0, 0, 10] 10)
   883 
   884 translations
   885  "ALL x<y. P"   =>  "ALL x. x < y --> P"
   886  "EX x<y. P"    =>  "EX x. x < y  & P"
   887  "ALL x<=y. P"  =>  "ALL x. x <= y --> P"
   888  "EX x<=y. P"   =>  "EX x. x <= y & P"
   889 
   890 end