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