src/HOL/HOL.thy
author wenzelm
Wed Dec 05 03:19:14 2001 +0100 (2001-12-05)
changeset 12386 9c38ec9eca1c
parent 12354 5f5ee25513c5
child 12436 a2df07fefed7
permissions -rw-r--r--
tuned declarations (rules, sym, etc.);
     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   ~=            :: "['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   "~="          :: "['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   "op ~="       :: "['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   "op ~="       :: "['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" and 2: "Q ==> R" and 3: "P --> Q ==> P") R
   205 proof -
   206   from 3 and 1 have P .
   207   with 1 have Q by (rule impE)
   208   with 2 show R .
   209 qed
   210 
   211 lemma allE':
   212   (assumes 1: "ALL x. P x" and 2: "P x ==> ALL x. P x ==> Q") Q
   213 proof -
   214   from 1 have "P x" by (rule spec)
   215   from this and 1 show Q by (rule 2)
   216 qed
   217 
   218 lemma notE': (assumes 1: "~ P" and 2: "~ P ==> P") R
   219 proof -
   220   from 2 and 1 have P .
   221   with 1 show R by (rule notE)
   222 qed
   223 
   224 lemmas [CPure.elim!] = disjE iffE FalseE conjE exE
   225   and [CPure.intro!] = iffI conjI impI TrueI notI allI refl
   226   and [CPure.elim 2] = allE notE' impE'
   227   and [CPure.intro] = exI disjI2 disjI1
   228 
   229 lemmas [trans] = trans
   230   and [sym] = sym not_sym
   231   and [CPure.elim?] = iffD1 iffD2 impE
   232 
   233 
   234 subsubsection {* Atomizing meta-level connectives *}
   235 
   236 lemma atomize_all [atomize]: "(!!x. P x) == Trueprop (ALL x. P x)"
   237 proof
   238   assume "!!x. P x"
   239   show "ALL x. P x" by (rule allI)
   240 next
   241   assume "ALL x. P x"
   242   thus "!!x. P x" by (rule allE)
   243 qed
   244 
   245 lemma atomize_imp [atomize]: "(A ==> B) == Trueprop (A --> B)"
   246 proof
   247   assume r: "A ==> B"
   248   show "A --> B" by (rule impI) (rule r)
   249 next
   250   assume "A --> B" and A
   251   thus B by (rule mp)
   252 qed
   253 
   254 lemma atomize_eq [atomize]: "(x == y) == Trueprop (x = y)"
   255 proof
   256   assume "x == y"
   257   show "x = y" by (unfold prems) (rule refl)
   258 next
   259   assume "x = y"
   260   thus "x == y" by (rule eq_reflection)
   261 qed
   262 
   263 lemma atomize_conj [atomize]:
   264   "(!!C. (A ==> B ==> PROP C) ==> PROP C) == Trueprop (A & B)"
   265 proof
   266   assume "!!C. (A ==> B ==> PROP C) ==> PROP C"
   267   show "A & B" by (rule conjI)
   268 next
   269   fix C
   270   assume "A & B"
   271   assume "A ==> B ==> PROP C"
   272   thus "PROP C"
   273   proof this
   274     show A by (rule conjunct1)
   275     show B by (rule conjunct2)
   276   qed
   277 qed
   278 
   279 lemmas [symmetric, rulify] = atomize_all atomize_imp
   280 
   281 
   282 subsubsection {* Classical Reasoner setup *}
   283 
   284 use "cladata.ML"
   285 setup hypsubst_setup
   286 
   287 ML_setup {*
   288   Context.>> (ContextRules.addSWrapper (fn tac => hyp_subst_tac' ORELSE' tac));
   289 *}
   290 
   291 setup Classical.setup
   292 setup clasetup
   293 
   294 lemmas [intro?] = ext
   295   and [elim?] = ex1_implies_ex
   296 
   297 use "blastdata.ML"
   298 setup Blast.setup
   299 
   300 
   301 subsubsection {* Simplifier setup *}
   302 
   303 lemma meta_eq_to_obj_eq: "x == y ==> x = y"
   304 proof -
   305   assume r: "x == y"
   306   show "x = y" by (unfold r) (rule refl)
   307 qed
   308 
   309 lemma eta_contract_eq: "(%s. f s) = f" ..
   310 
   311 lemma simp_thms:
   312   (not_not: "(~ ~ P) = P" and
   313     "(x = x) = True"
   314     "(~True) = False"  "(~False) = True"
   315     "(~P) ~= P"  "P ~= (~P)"  "(P ~= Q) = (P = (~Q))"
   316     "(True=P) = P"  "(P=True) = P"  "(False=P) = (~P)"  "(P=False) = (~P)"
   317     "(True --> P) = P"  "(False --> P) = True"
   318     "(P --> True) = True"  "(P --> P) = True"
   319     "(P --> False) = (~P)"  "(P --> ~P) = (~P)"
   320     "(P & True) = P"  "(True & P) = P"
   321     "(P & False) = False"  "(False & P) = False"
   322     "(P & P) = P"  "(P & (P & Q)) = (P & Q)"
   323     "(P & ~P) = False"    "(~P & P) = False"
   324     "(P | True) = True"  "(True | P) = True"
   325     "(P | False) = P"  "(False | P) = P"
   326     "(P | P) = P"  "(P | (P | Q)) = (P | Q)"
   327     "(P | ~P) = True"    "(~P | P) = True"
   328     "((~P) = (~Q)) = (P=Q)" and
   329     "(ALL x. P) = P"  "(EX x. P) = P"  "EX x. x=t"  "EX x. t=x"
   330     -- {* needed for the one-point-rule quantifier simplification procs *}
   331     -- {* essential for termination!! *} and
   332     "!!P. (EX x. x=t & P(x)) = P(t)"
   333     "!!P. (EX x. t=x & P(x)) = P(t)"
   334     "!!P. (ALL x. x=t --> P(x)) = P(t)"
   335     "!!P. (ALL x. t=x --> P(x)) = P(t)")
   336   by blast+
   337 
   338 lemma imp_cong: "(P = P') ==> (P' ==> (Q = Q')) ==> ((P --> Q) = (P' --> Q'))"
   339   by rules
   340 
   341 lemma ex_simps:
   342   "!!P Q. (EX x. P x & Q)   = ((EX x. P x) & Q)"
   343   "!!P Q. (EX x. P & Q x)   = (P & (EX x. Q x))"
   344   "!!P Q. (EX x. P x | Q)   = ((EX x. P x) | Q)"
   345   "!!P Q. (EX x. P | Q x)   = (P | (EX x. Q x))"
   346   "!!P Q. (EX x. P x --> Q) = ((ALL x. P x) --> Q)"
   347   "!!P Q. (EX x. P --> Q x) = (P --> (EX x. Q x))"
   348   -- {* Miniscoping: pushing in existential quantifiers. *}
   349   by blast+
   350 
   351 lemma all_simps:
   352   "!!P Q. (ALL x. P x & Q)   = ((ALL x. P x) & Q)"
   353   "!!P Q. (ALL x. P & Q x)   = (P & (ALL x. Q x))"
   354   "!!P Q. (ALL x. P x | Q)   = ((ALL x. P x) | Q)"
   355   "!!P Q. (ALL x. P | Q x)   = (P | (ALL x. Q x))"
   356   "!!P Q. (ALL x. P x --> Q) = ((EX x. P x) --> Q)"
   357   "!!P Q. (ALL x. P --> Q x) = (P --> (ALL x. Q x))"
   358   -- {* Miniscoping: pushing in universal quantifiers. *}
   359   by blast+
   360 
   361 lemma eq_ac:
   362  (eq_commute: "(a=b) = (b=a)" and
   363   eq_left_commute: "(P=(Q=R)) = (Q=(P=R))" and
   364   eq_assoc: "((P=Q)=R) = (P=(Q=R))") by blast+
   365 lemma neq_commute: "(a~=b) = (b~=a)" by blast
   366 
   367 lemma conj_comms:
   368  (conj_commute: "(P&Q) = (Q&P)" and
   369   conj_left_commute: "(P&(Q&R)) = (Q&(P&R))") by blast+
   370 lemma conj_assoc: "((P&Q)&R) = (P&(Q&R))" by blast
   371 
   372 lemma disj_comms:
   373  (disj_commute: "(P|Q) = (Q|P)" and
   374   disj_left_commute: "(P|(Q|R)) = (Q|(P|R))") by blast+
   375 lemma disj_assoc: "((P|Q)|R) = (P|(Q|R))" by blast
   376 
   377 lemma conj_disj_distribL: "(P&(Q|R)) = (P&Q | P&R)" by blast
   378 lemma conj_disj_distribR: "((P|Q)&R) = (P&R | Q&R)" by blast
   379 
   380 lemma disj_conj_distribL: "(P|(Q&R)) = ((P|Q) & (P|R))" by blast
   381 lemma disj_conj_distribR: "((P&Q)|R) = ((P|R) & (Q|R))" by blast
   382 
   383 lemma imp_conjR: "(P --> (Q&R)) = ((P-->Q) & (P-->R))" by blast
   384 lemma imp_conjL: "((P&Q) -->R)  = (P --> (Q --> R))" by blast
   385 lemma imp_disjL: "((P|Q) --> R) = ((P-->R)&(Q-->R))" by blast
   386 
   387 text {* These two are specialized, but @{text imp_disj_not1} is useful in @{text "Auth/Yahalom"}. *}
   388 lemma imp_disj_not1: "(P --> Q | R) = (~Q --> P --> R)" by blast
   389 lemma imp_disj_not2: "(P --> Q | R) = (~R --> P --> Q)" by blast
   390 
   391 lemma imp_disj1: "((P-->Q)|R) = (P--> Q|R)" by blast
   392 lemma imp_disj2: "(Q|(P-->R)) = (P--> Q|R)" by blast
   393 
   394 lemma de_Morgan_disj: "(~(P | Q)) = (~P & ~Q)" by blast
   395 lemma de_Morgan_conj: "(~(P & Q)) = (~P | ~Q)" by blast
   396 lemma not_imp: "(~(P --> Q)) = (P & ~Q)" by blast
   397 lemma not_iff: "(P~=Q) = (P = (~Q))" by blast
   398 lemma disj_not1: "(~P | Q) = (P --> Q)" by blast
   399 lemma disj_not2: "(P | ~Q) = (Q --> P)"  -- {* changes orientation :-( *}
   400   by blast
   401 lemma imp_conv_disj: "(P --> Q) = ((~P) | Q)" by blast
   402 
   403 lemma iff_conv_conj_imp: "(P = Q) = ((P --> Q) & (Q --> P))" by blast
   404 
   405 
   406 lemma cases_simp: "((P --> Q) & (~P --> Q)) = Q"
   407   -- {* Avoids duplication of subgoals after @{text split_if}, when the true and false *}
   408   -- {* cases boil down to the same thing. *}
   409   by blast
   410 
   411 lemma not_all: "(~ (! x. P(x))) = (? x.~P(x))" by blast
   412 lemma imp_all: "((! x. P x) --> Q) = (? x. P x --> Q)" by blast
   413 lemma not_ex: "(~ (? x. P(x))) = (! x.~P(x))" by blast
   414 lemma imp_ex: "((? x. P x) --> Q) = (! x. P x --> Q)" by blast
   415 
   416 lemma ex_disj_distrib: "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))" by blast
   417 lemma all_conj_distrib: "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))" by blast
   418 
   419 text {*
   420   \medskip The @{text "&"} congruence rule: not included by default!
   421   May slow rewrite proofs down by as much as 50\% *}
   422 
   423 lemma conj_cong:
   424     "(P = P') ==> (P' ==> (Q = Q')) ==> ((P & Q) = (P' & Q'))"
   425   by rules
   426 
   427 lemma rev_conj_cong:
   428     "(Q = Q') ==> (Q' ==> (P = P')) ==> ((P & Q) = (P' & Q'))"
   429   by rules
   430 
   431 text {* The @{text "|"} congruence rule: not included by default! *}
   432 
   433 lemma disj_cong:
   434     "(P = P') ==> (~P' ==> (Q = Q')) ==> ((P | Q) = (P' | Q'))"
   435   by blast
   436 
   437 lemma eq_sym_conv: "(x = y) = (y = x)"
   438   by rules
   439 
   440 
   441 text {* \medskip if-then-else rules *}
   442 
   443 lemma if_True: "(if True then x else y) = x"
   444   by (unfold if_def) blast
   445 
   446 lemma if_False: "(if False then x else y) = y"
   447   by (unfold if_def) blast
   448 
   449 lemma if_P: "P ==> (if P then x else y) = x"
   450   by (unfold if_def) blast
   451 
   452 lemma if_not_P: "~P ==> (if P then x else y) = y"
   453   by (unfold if_def) blast
   454 
   455 lemma split_if: "P (if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))"
   456   apply (rule case_split [of Q])
   457    apply (subst if_P)
   458     prefer 3 apply (subst if_not_P)
   459      apply blast+
   460   done
   461 
   462 lemma split_if_asm: "P (if Q then x else y) = (~((Q & ~P x) | (~Q & ~P y)))"
   463   apply (subst split_if)
   464   apply blast
   465   done
   466 
   467 lemmas if_splits = split_if split_if_asm
   468 
   469 lemma if_def2: "(if Q then x else y) = ((Q --> x) & (~ Q --> y))"
   470   by (rule split_if)
   471 
   472 lemma if_cancel: "(if c then x else x) = x"
   473   apply (subst split_if)
   474   apply blast
   475   done
   476 
   477 lemma if_eq_cancel: "(if x = y then y else x) = x"
   478   apply (subst split_if)
   479   apply blast
   480   done
   481 
   482 lemma if_bool_eq_conj: "(if P then Q else R) = ((P-->Q) & (~P-->R))"
   483   -- {* This form is useful for expanding @{text if}s on the RIGHT of the @{text "==>"} symbol. *}
   484   by (rule split_if)
   485 
   486 lemma if_bool_eq_disj: "(if P then Q else R) = ((P&Q) | (~P&R))"
   487   -- {* And this form is useful for expanding @{text if}s on the LEFT. *}
   488   apply (subst split_if)
   489   apply blast
   490   done
   491 
   492 lemma Eq_TrueI: "P ==> P == True" by (unfold atomize_eq) blast
   493 lemma Eq_FalseI: "~P ==> P == False" by (unfold atomize_eq) blast
   494 
   495 use "simpdata.ML"
   496 setup Simplifier.setup
   497 setup "Simplifier.method_setup Splitter.split_modifiers" setup simpsetup
   498 setup Splitter.setup setup Clasimp.setup
   499 
   500 
   501 subsubsection {* Generic cases and induction *}
   502 
   503 constdefs
   504   induct_forall :: "('a => bool) => bool"
   505   "induct_forall P == \<forall>x. P x"
   506   induct_implies :: "bool => bool => bool"
   507   "induct_implies A B == A --> B"
   508   induct_equal :: "'a => 'a => bool"
   509   "induct_equal x y == x = y"
   510   induct_conj :: "bool => bool => bool"
   511   "induct_conj A B == A & B"
   512 
   513 lemma induct_forall_eq: "(!!x. P x) == Trueprop (induct_forall (\<lambda>x. P x))"
   514   by (simp only: atomize_all induct_forall_def)
   515 
   516 lemma induct_implies_eq: "(A ==> B) == Trueprop (induct_implies A B)"
   517   by (simp only: atomize_imp induct_implies_def)
   518 
   519 lemma induct_equal_eq: "(x == y) == Trueprop (induct_equal x y)"
   520   by (simp only: atomize_eq induct_equal_def)
   521 
   522 lemma induct_forall_conj: "induct_forall (\<lambda>x. induct_conj (A x) (B x)) =
   523     induct_conj (induct_forall A) (induct_forall B)"
   524   by (unfold induct_forall_def induct_conj_def) rules
   525 
   526 lemma induct_implies_conj: "induct_implies C (induct_conj A B) =
   527     induct_conj (induct_implies C A) (induct_implies C B)"
   528   by (unfold induct_implies_def induct_conj_def) rules
   529 
   530 lemma induct_conj_curry: "(induct_conj A B ==> C) == (A ==> B ==> C)"
   531   by (simp only: atomize_imp atomize_eq induct_conj_def) (rules intro: equal_intr_rule)
   532 
   533 lemma induct_impliesI: "(A ==> B) ==> induct_implies A B"
   534   by (simp add: induct_implies_def)
   535 
   536 lemmas induct_atomize = atomize_conj induct_forall_eq induct_implies_eq induct_equal_eq
   537 lemmas induct_rulify1 [symmetric, standard] = induct_forall_eq induct_implies_eq induct_equal_eq
   538 lemmas induct_rulify2 = induct_forall_def induct_implies_def induct_equal_def induct_conj_def
   539 lemmas induct_conj = induct_forall_conj induct_implies_conj induct_conj_curry
   540 
   541 hide const induct_forall induct_implies induct_equal induct_conj
   542 
   543 
   544 text {* Method setup. *}
   545 
   546 ML {*
   547   structure InductMethod = InductMethodFun
   548   (struct
   549     val dest_concls = HOLogic.dest_concls;
   550     val cases_default = thm "case_split";
   551     val local_impI = thm "induct_impliesI";
   552     val conjI = thm "conjI";
   553     val atomize = thms "induct_atomize";
   554     val rulify1 = thms "induct_rulify1";
   555     val rulify2 = thms "induct_rulify2";
   556     val localize = [Thm.symmetric (thm "induct_implies_def")];
   557   end);
   558 *}
   559 
   560 setup InductMethod.setup
   561 
   562 
   563 subsection {* Order signatures and orders *}
   564 
   565 axclass
   566   ord < type
   567 
   568 syntax
   569   "op <"        :: "['a::ord, 'a] => bool"             ("op <")
   570   "op <="       :: "['a::ord, 'a] => bool"             ("op <=")
   571 
   572 global
   573 
   574 consts
   575   "op <"        :: "['a::ord, 'a] => bool"             ("(_/ < _)"  [50, 51] 50)
   576   "op <="       :: "['a::ord, 'a] => bool"             ("(_/ <= _)" [50, 51] 50)
   577 
   578 local
   579 
   580 syntax (xsymbols)
   581   "op <="       :: "['a::ord, 'a] => bool"             ("op \<le>")
   582   "op <="       :: "['a::ord, 'a] => bool"             ("(_/ \<le> _)"  [50, 51] 50)
   583 
   584 (*Tell blast about overloading of < and <= to reduce the risk of
   585   its applying a rule for the wrong type*)
   586 ML {*
   587 Blast.overloaded ("op <" , domain_type);
   588 Blast.overloaded ("op <=", domain_type);
   589 *}
   590 
   591 
   592 subsubsection {* Monotonicity *}
   593 
   594 constdefs
   595   mono :: "['a::ord => 'b::ord] => bool"
   596   "mono f == ALL A B. A <= B --> f A <= f B"
   597 
   598 lemma monoI [intro?]: "(!!A B. A <= B ==> f A <= f B) ==> mono f"
   599   by (unfold mono_def) rules
   600 
   601 lemma monoD [dest?]: "mono f ==> A <= B ==> f A <= f B"
   602   by (unfold mono_def) rules
   603 
   604 constdefs
   605   min :: "['a::ord, 'a] => 'a"
   606   "min a b == (if a <= b then a else b)"
   607   max :: "['a::ord, 'a] => 'a"
   608   "max a b == (if a <= b then b else a)"
   609 
   610 lemma min_leastL: "(!!x. least <= x) ==> min least x = least"
   611   by (simp add: min_def)
   612 
   613 lemma min_of_mono:
   614     "ALL x y. (f x <= f y) = (x <= y) ==> min (f m) (f n) = f (min m n)"
   615   by (simp add: min_def)
   616 
   617 lemma max_leastL: "(!!x. least <= x) ==> max least x = x"
   618   by (simp add: max_def)
   619 
   620 lemma max_of_mono:
   621     "ALL x y. (f x <= f y) = (x <= y) ==> max (f m) (f n) = f (max m n)"
   622   by (simp add: max_def)
   623 
   624 
   625 subsubsection "Orders"
   626 
   627 axclass order < ord
   628   order_refl [iff]: "x <= x"
   629   order_trans: "x <= y ==> y <= z ==> x <= z"
   630   order_antisym: "x <= y ==> y <= x ==> x = y"
   631   order_less_le: "(x < y) = (x <= y & x ~= y)"
   632 
   633 
   634 text {* Reflexivity. *}
   635 
   636 lemma order_eq_refl: "!!x::'a::order. x = y ==> x <= y"
   637     -- {* This form is useful with the classical reasoner. *}
   638   apply (erule ssubst)
   639   apply (rule order_refl)
   640   done
   641 
   642 lemma order_less_irrefl [simp]: "~ x < (x::'a::order)"
   643   by (simp add: order_less_le)
   644 
   645 lemma order_le_less: "((x::'a::order) <= y) = (x < y | x = y)"
   646     -- {* NOT suitable for iff, since it can cause PROOF FAILED. *}
   647   apply (simp add: order_less_le)
   648   apply blast
   649   done
   650 
   651 lemmas order_le_imp_less_or_eq = order_le_less [THEN iffD1, standard]
   652 
   653 lemma order_less_imp_le: "!!x::'a::order. x < y ==> x <= y"
   654   by (simp add: order_less_le)
   655 
   656 
   657 text {* Asymmetry. *}
   658 
   659 lemma order_less_not_sym: "(x::'a::order) < y ==> ~ (y < x)"
   660   by (simp add: order_less_le order_antisym)
   661 
   662 lemma order_less_asym: "x < (y::'a::order) ==> (~P ==> y < x) ==> P"
   663   apply (drule order_less_not_sym)
   664   apply (erule contrapos_np)
   665   apply simp
   666   done
   667 
   668 
   669 text {* Transitivity. *}
   670 
   671 lemma order_less_trans: "!!x::'a::order. [| x < y; y < z |] ==> x < z"
   672   apply (simp add: order_less_le)
   673   apply (blast intro: order_trans order_antisym)
   674   done
   675 
   676 lemma order_le_less_trans: "!!x::'a::order. [| x <= y; y < z |] ==> x < z"
   677   apply (simp add: order_less_le)
   678   apply (blast intro: order_trans order_antisym)
   679   done
   680 
   681 lemma order_less_le_trans: "!!x::'a::order. [| x < y; y <= z |] ==> x < z"
   682   apply (simp add: order_less_le)
   683   apply (blast intro: order_trans order_antisym)
   684   done
   685 
   686 
   687 text {* Useful for simplification, but too risky to include by default. *}
   688 
   689 lemma order_less_imp_not_less: "(x::'a::order) < y ==>  (~ y < x) = True"
   690   by (blast elim: order_less_asym)
   691 
   692 lemma order_less_imp_triv: "(x::'a::order) < y ==>  (y < x --> P) = True"
   693   by (blast elim: order_less_asym)
   694 
   695 lemma order_less_imp_not_eq: "(x::'a::order) < y ==>  (x = y) = False"
   696   by auto
   697 
   698 lemma order_less_imp_not_eq2: "(x::'a::order) < y ==>  (y = x) = False"
   699   by auto
   700 
   701 
   702 text {* Other operators. *}
   703 
   704 lemma min_leastR: "(!!x::'a::order. least <= x) ==> min x least = least"
   705   apply (simp add: min_def)
   706   apply (blast intro: order_antisym)
   707   done
   708 
   709 lemma max_leastR: "(!!x::'a::order. least <= x) ==> max x least = x"
   710   apply (simp add: max_def)
   711   apply (blast intro: order_antisym)
   712   done
   713 
   714 
   715 subsubsection {* Least value operator *}
   716 
   717 constdefs
   718   Least :: "('a::ord => bool) => 'a"               (binder "LEAST " 10)
   719   "Least P == THE x. P x & (ALL y. P y --> x <= y)"
   720     -- {* We can no longer use LeastM because the latter requires Hilbert-AC. *}
   721 
   722 lemma LeastI2:
   723   "[| P (x::'a::order);
   724       !!y. P y ==> x <= y;
   725       !!x. [| P x; ALL y. P y --> x \<le> y |] ==> Q x |]
   726    ==> Q (Least P)"
   727   apply (unfold Least_def)
   728   apply (rule theI2)
   729     apply (blast intro: order_antisym)+
   730   done
   731 
   732 lemma Least_equality:
   733     "[| P (k::'a::order); !!x. P x ==> k <= x |] ==> (LEAST x. P x) = k"
   734   apply (simp add: Least_def)
   735   apply (rule the_equality)
   736   apply (auto intro!: order_antisym)
   737   done
   738 
   739 
   740 subsubsection "Linear / total orders"
   741 
   742 axclass linorder < order
   743   linorder_linear: "x <= y | y <= x"
   744 
   745 lemma linorder_less_linear: "!!x::'a::linorder. x<y | x=y | y<x"
   746   apply (simp add: order_less_le)
   747   apply (insert linorder_linear)
   748   apply blast
   749   done
   750 
   751 lemma linorder_cases [case_names less equal greater]:
   752     "((x::'a::linorder) < y ==> P) ==> (x = y ==> P) ==> (y < x ==> P) ==> P"
   753   apply (insert linorder_less_linear)
   754   apply blast
   755   done
   756 
   757 lemma linorder_not_less: "!!x::'a::linorder. (~ x < y) = (y <= x)"
   758   apply (simp add: order_less_le)
   759   apply (insert linorder_linear)
   760   apply (blast intro: order_antisym)
   761   done
   762 
   763 lemma linorder_not_le: "!!x::'a::linorder. (~ x <= y) = (y < x)"
   764   apply (simp add: order_less_le)
   765   apply (insert linorder_linear)
   766   apply (blast intro: order_antisym)
   767   done
   768 
   769 lemma linorder_neq_iff: "!!x::'a::linorder. (x ~= y) = (x<y | y<x)"
   770   apply (cut_tac x = x and y = y in linorder_less_linear)
   771   apply auto
   772   done
   773 
   774 lemma linorder_neqE: "x ~= (y::'a::linorder) ==> (x < y ==> R) ==> (y < x ==> R) ==> R"
   775   apply (simp add: linorder_neq_iff)
   776   apply blast
   777   done
   778 
   779 
   780 subsubsection "Min and max on (linear) orders"
   781 
   782 lemma min_same [simp]: "min (x::'a::order) x = x"
   783   by (simp add: min_def)
   784 
   785 lemma max_same [simp]: "max (x::'a::order) x = x"
   786   by (simp add: max_def)
   787 
   788 lemma le_max_iff_disj: "!!z::'a::linorder. (z <= max x y) = (z <= x | z <= y)"
   789   apply (simp add: max_def)
   790   apply (insert linorder_linear)
   791   apply (blast intro: order_trans)
   792   done
   793 
   794 lemma le_maxI1: "(x::'a::linorder) <= max x y"
   795   by (simp add: le_max_iff_disj)
   796 
   797 lemma le_maxI2: "(y::'a::linorder) <= max x y"
   798     -- {* CANNOT use with @{text "[intro!]"} because blast will give PROOF FAILED. *}
   799   by (simp add: le_max_iff_disj)
   800 
   801 lemma less_max_iff_disj: "!!z::'a::linorder. (z < max x y) = (z < x | z < y)"
   802   apply (simp add: max_def order_le_less)
   803   apply (insert linorder_less_linear)
   804   apply (blast intro: order_less_trans)
   805   done
   806 
   807 lemma max_le_iff_conj [simp]:
   808     "!!z::'a::linorder. (max x y <= z) = (x <= z & y <= z)"
   809   apply (simp add: max_def)
   810   apply (insert linorder_linear)
   811   apply (blast intro: order_trans)
   812   done
   813 
   814 lemma max_less_iff_conj [simp]:
   815     "!!z::'a::linorder. (max x y < z) = (x < z & y < z)"
   816   apply (simp add: order_le_less max_def)
   817   apply (insert linorder_less_linear)
   818   apply (blast intro: order_less_trans)
   819   done
   820 
   821 lemma le_min_iff_conj [simp]:
   822     "!!z::'a::linorder. (z <= min x y) = (z <= x & z <= y)"
   823     -- {* @{text "[iff]"} screws up a Q{text blast} in MiniML *}
   824   apply (simp add: min_def)
   825   apply (insert linorder_linear)
   826   apply (blast intro: order_trans)
   827   done
   828 
   829 lemma min_less_iff_conj [simp]:
   830     "!!z::'a::linorder. (z < min x y) = (z < x & z < y)"
   831   apply (simp add: order_le_less min_def)
   832   apply (insert linorder_less_linear)
   833   apply (blast intro: order_less_trans)
   834   done
   835 
   836 lemma min_le_iff_disj: "!!z::'a::linorder. (min x y <= z) = (x <= z | y <= z)"
   837   apply (simp add: min_def)
   838   apply (insert linorder_linear)
   839   apply (blast intro: order_trans)
   840   done
   841 
   842 lemma min_less_iff_disj: "!!z::'a::linorder. (min x y < z) = (x < z | y < z)"
   843   apply (simp add: min_def order_le_less)
   844   apply (insert linorder_less_linear)
   845   apply (blast intro: order_less_trans)
   846   done
   847 
   848 lemma split_min:
   849     "P (min (i::'a::linorder) j) = ((i <= j --> P(i)) & (~ i <= j --> P(j)))"
   850   by (simp add: min_def)
   851 
   852 lemma split_max:
   853     "P (max (i::'a::linorder) j) = ((i <= j --> P(j)) & (~ i <= j --> P(i)))"
   854   by (simp add: max_def)
   855 
   856 
   857 subsubsection "Bounded quantifiers"
   858 
   859 syntax
   860   "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3ALL _<_./ _)"  [0, 0, 10] 10)
   861   "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3EX _<_./ _)"  [0, 0, 10] 10)
   862   "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3ALL _<=_./ _)" [0, 0, 10] 10)
   863   "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3EX _<=_./ _)" [0, 0, 10] 10)
   864 
   865 syntax (xsymbols)
   866   "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
   867   "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
   868   "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
   869   "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
   870 
   871 syntax (HOL)
   872   "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3! _<_./ _)"  [0, 0, 10] 10)
   873   "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3? _<_./ _)"  [0, 0, 10] 10)
   874   "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3! _<=_./ _)" [0, 0, 10] 10)
   875   "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3? _<=_./ _)" [0, 0, 10] 10)
   876 
   877 translations
   878  "ALL x<y. P"   =>  "ALL x. x < y --> P"
   879  "EX x<y. P"    =>  "EX x. x < y  & P"
   880  "ALL x<=y. P"  =>  "ALL x. x <= y --> P"
   881  "EX x<=y. P"   =>  "EX x. x <= y & P"
   882 
   883 end