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