src/HOL/HOL.thy
 author nipkow Sun Dec 22 15:02:40 2002 +0100 (2002-12-22) changeset 13764 3e180bf68496 parent 13763 f94b569cd610 child 14201 7ad7ab89c402 permissions -rw-r--r--
removed some problems with print translations
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 *)
7 header {* The basis of Higher-Order Logic *}
9 theory HOL = CPure
10 files ("HOL_lemmas.ML") ("cladata.ML") ("blastdata.ML") ("simpdata.ML"):
13 subsection {* Primitive logic *}
15 subsubsection {* Core syntax *}
17 classes type < logic
18 defaultsort type
20 global
22 typedecl bool
24 arities
25   bool :: type
26   fun :: (type, type) type
28 judgment
29   Trueprop      :: "bool => prop"                   ("(_)" 5)
31 consts
32   Not           :: "bool => bool"                   ("~ _"  40)
33   True          :: bool
34   False         :: bool
35   If            :: "[bool, 'a, 'a] => 'a"           ("(if (_)/ then (_)/ else (_))" 10)
36   arbitrary     :: 'a
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"
44   "="           :: "['a, 'a] => bool"               (infixl 50)
45   &             :: "[bool, bool] => bool"           (infixr 35)
46   "|"           :: "[bool, bool] => bool"           (infixr 30)
47   -->           :: "[bool, bool] => bool"           (infixr 25)
49 local
52 subsubsection {* Additional concrete syntax *}
54 nonterminals
55   letbinds  letbind
56   case_syn  cases_syn
58 syntax
59   "_not_equal"  :: "['a, 'a] => bool"                    (infixl "~=" 50)
60   "_The"        :: "[pttrn, bool] => 'a"                 ("(3THE _./ _)" [0, 10] 10)
62   "_bind"       :: "[pttrn, 'a] => letbind"              ("(2_ =/ _)" 10)
63   ""            :: "letbind => letbinds"                 ("_")
64   "_binds"      :: "[letbind, letbinds] => letbinds"     ("_;/ _")
65   "_Let"        :: "[letbinds, 'a] => 'a"                ("(let (_)/ in (_))" 10)
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"  ("_/ | _")
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)"
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 *}
85 syntax (output)
86   "="           :: "['a, 'a] => bool"                    (infix 50)
87   "_not_equal"  :: "['a, 'a] => bool"                    (infix "~=" 50)
89 syntax (xsymbols)
90   Not           :: "bool => bool"                        ("\<not> _"  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> _")*)
101 syntax (xsymbols output)
102   "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
104 syntax (HTML output)
105   Not           :: "bool => bool"                        ("\<not> _"  40)
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)
113 subsubsection {* Axioms and basic definitions *}
115 axioms
116   eq_reflection: "(x=y) ==> (x==y)"
118   refl:         "t = (t::'a)"
119   subst:        "[| s = t; P(s) |] ==> P(t::'a)"
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 *}
126   the_eq_trivial: "(THE x. x = a) = (a::'a)"
128   impI:         "(P ==> Q) ==> P-->Q"
129   mp:           "[| P-->Q;  P |] ==> Q"
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)"
141 axioms
142   iff:          "(P-->Q) --> (Q-->P) --> (P=Q)"
143   True_or_False:  "(P=True) | (P=False)"
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)"
149   arbitrary_def:  "False ==> arbitrary == (THE x. False)"
150     -- {* @{term arbitrary} is completely unspecified, but is made to appear as a
151     definition syntactically *}
154 subsubsection {* Generic algebraic operations *}
156 axclass zero < type
157 axclass one < type
158 axclass plus < type
159 axclass minus < type
160 axclass times < type
161 axclass inverse < type
163 global
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"              ("- _"  80)
171   *             :: "['a::times, 'a] => 'a"          (infixl 70)
173 syntax
174   "_index1"  :: index    ("\<^sub>1")
175 translations
176   (index) "\<^sub>1" == "_index 1"
178 local
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 *}
189 consts
190   abs           :: "'a::minus => 'a"
191   inverse       :: "'a::inverse => 'a"
192   divide        :: "['a::inverse, 'a] => 'a"        (infixl "'/" 70)
194 syntax (xsymbols)
195   abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
196 syntax (HTML output)
197   abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
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"
205 subsection {* Theory and package setup *}
207 subsubsection {* Basic lemmas *}
209 use "HOL_lemmas.ML"
210 theorems case_split = case_split_thm [case_names True False]
213 subsubsection {* Intuitionistic Reasoning *}
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
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
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
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
249 lemmas [trans] = trans
250   and [sym] = sym not_sym
251   and [CPure.elim?] = iffD1 iffD2 impE
254 subsubsection {* Atomizing meta-level connectives *}
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
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
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
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
299 lemmas [symmetric, rulify] = atomize_all atomize_imp
302 subsubsection {* Classical Reasoner setup *}
305 setup hypsubst_setup
307 ML_setup {*
308   Context.>> (ContextRules.addSWrapper (fn tac => hyp_subst_tac' ORELSE' tac));
309 *}
311 setup Classical.setup
312 setup clasetup
314 lemmas [intro?] = ext
315   and [elim?] = ex1_implies_ex
317 use "blastdata.ML"
318 setup Blast.setup
321 subsubsection {* Simplifier setup *}
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
329 lemma eta_contract_eq: "(%s. f s) = f" ..
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+)
360 lemma imp_cong: "(P = P') ==> (P' ==> (Q = Q')) ==> ((P --> Q) = (P' --> Q'))"
361   by rules
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)+
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)+
383 lemma eq_ac:
384   shows eq_commute: "(a=b) = (b=a)"
385     and eq_left_commute: "(P=(Q=R)) = (Q=(P=R))"
386     and eq_assoc: "((P=Q)=R) = (P=(Q=R))" by (rules, blast+)
387 lemma neq_commute: "(a~=b) = (b~=a)" by rules
389 lemma conj_comms:
390   shows conj_commute: "(P&Q) = (Q&P)"
391     and conj_left_commute: "(P&(Q&R)) = (Q&(P&R))" by rules+
392 lemma conj_assoc: "((P&Q)&R) = (P&(Q&R))" by rules
394 lemma disj_comms:
395   shows disj_commute: "(P|Q) = (Q|P)"
396     and disj_left_commute: "(P|(Q|R)) = (Q|(P|R))" by rules+
397 lemma disj_assoc: "((P|Q)|R) = (P|(Q|R))" by rules
399 lemma conj_disj_distribL: "(P&(Q|R)) = (P&Q | P&R)" by rules
400 lemma conj_disj_distribR: "((P|Q)&R) = (P&R | Q&R)" by rules
402 lemma disj_conj_distribL: "(P|(Q&R)) = ((P|Q) & (P|R))" by rules
403 lemma disj_conj_distribR: "((P&Q)|R) = ((P|R) & (Q|R))" by rules
405 lemma imp_conjR: "(P --> (Q&R)) = ((P-->Q) & (P-->R))" by rules
406 lemma imp_conjL: "((P&Q) -->R)  = (P --> (Q --> R))" by rules
407 lemma imp_disjL: "((P|Q) --> R) = ((P-->R)&(Q-->R))" by rules
409 text {* These two are specialized, but @{text imp_disj_not1} is useful in @{text "Auth/Yahalom"}. *}
410 lemma imp_disj_not1: "(P --> Q | R) = (~Q --> P --> R)" by blast
411 lemma imp_disj_not2: "(P --> Q | R) = (~R --> P --> Q)" by blast
413 lemma imp_disj1: "((P-->Q)|R) = (P--> Q|R)" by blast
414 lemma imp_disj2: "(Q|(P-->R)) = (P--> Q|R)" by blast
416 lemma de_Morgan_disj: "(~(P | Q)) = (~P & ~Q)" by rules
417 lemma de_Morgan_conj: "(~(P & Q)) = (~P | ~Q)" by blast
418 lemma not_imp: "(~(P --> Q)) = (P & ~Q)" by blast
419 lemma not_iff: "(P~=Q) = (P = (~Q))" by blast
420 lemma disj_not1: "(~P | Q) = (P --> Q)" by blast
421 lemma disj_not2: "(P | ~Q) = (Q --> P)"  -- {* changes orientation :-( *}
422   by blast
423 lemma imp_conv_disj: "(P --> Q) = ((~P) | Q)" by blast
425 lemma iff_conv_conj_imp: "(P = Q) = ((P --> Q) & (Q --> P))" by rules
428 lemma cases_simp: "((P --> Q) & (~P --> Q)) = Q"
429   -- {* Avoids duplication of subgoals after @{text split_if}, when the true and false *}
430   -- {* cases boil down to the same thing. *}
431   by blast
433 lemma not_all: "(~ (! x. P(x))) = (? x.~P(x))" by blast
434 lemma imp_all: "((! x. P x) --> Q) = (? x. P x --> Q)" by blast
435 lemma not_ex: "(~ (? x. P(x))) = (! x.~P(x))" by rules
436 lemma imp_ex: "((? x. P x) --> Q) = (! x. P x --> Q)" by rules
438 lemma ex_disj_distrib: "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))" by rules
439 lemma all_conj_distrib: "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))" by rules
441 text {*
442   \medskip The @{text "&"} congruence rule: not included by default!
443   May slow rewrite proofs down by as much as 50\% *}
445 lemma conj_cong:
446     "(P = P') ==> (P' ==> (Q = Q')) ==> ((P & Q) = (P' & Q'))"
447   by rules
449 lemma rev_conj_cong:
450     "(Q = Q') ==> (Q' ==> (P = P')) ==> ((P & Q) = (P' & Q'))"
451   by rules
453 text {* The @{text "|"} congruence rule: not included by default! *}
455 lemma disj_cong:
456     "(P = P') ==> (~P' ==> (Q = Q')) ==> ((P | Q) = (P' | Q'))"
457   by blast
459 lemma eq_sym_conv: "(x = y) = (y = x)"
460   by rules
463 text {* \medskip if-then-else rules *}
465 lemma if_True: "(if True then x else y) = x"
466   by (unfold if_def) blast
468 lemma if_False: "(if False then x else y) = y"
469   by (unfold if_def) blast
471 lemma if_P: "P ==> (if P then x else y) = x"
472   by (unfold if_def) blast
474 lemma if_not_P: "~P ==> (if P then x else y) = y"
475   by (unfold if_def) blast
477 lemma split_if: "P (if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))"
478   apply (rule case_split [of Q])
479    apply (subst if_P)
480     prefer 3 apply (subst if_not_P)
481      apply blast+
482   done
484 lemma split_if_asm: "P (if Q then x else y) = (~((Q & ~P x) | (~Q & ~P y)))"
485   apply (subst split_if)
486   apply blast
487   done
489 lemmas if_splits = split_if split_if_asm
491 lemma if_def2: "(if Q then x else y) = ((Q --> x) & (~ Q --> y))"
492   by (rule split_if)
494 lemma if_cancel: "(if c then x else x) = x"
495   apply (subst split_if)
496   apply blast
497   done
499 lemma if_eq_cancel: "(if x = y then y else x) = x"
500   apply (subst split_if)
501   apply blast
502   done
504 lemma if_bool_eq_conj: "(if P then Q else R) = ((P-->Q) & (~P-->R))"
505   -- {* This form is useful for expanding @{text if}s on the RIGHT of the @{text "==>"} symbol. *}
506   by (rule split_if)
508 lemma if_bool_eq_disj: "(if P then Q else R) = ((P&Q) | (~P&R))"
509   -- {* And this form is useful for expanding @{text if}s on the LEFT. *}
510   apply (subst split_if)
511   apply blast
512   done
514 lemma Eq_TrueI: "P ==> P == True" by (unfold atomize_eq) rules
515 lemma Eq_FalseI: "~P ==> P == False" by (unfold atomize_eq) rules
517 use "simpdata.ML"
518 setup Simplifier.setup
519 setup "Simplifier.method_setup Splitter.split_modifiers" setup simpsetup
520 setup Splitter.setup setup Clasimp.setup
522 lemma ex1_eq[iff]: "EX! x. x = t" "EX! x. t = x"
523 by blast+
525 theorem choice_eq: "(ALL x. EX! y. P x y) = (EX! f. ALL x. P x (f x))"
526   apply (rule iffI)
527   apply (rule_tac a = "%x. THE y. P x y" in ex1I)
528   apply (fast dest!: theI')
529   apply (fast intro: ext the1_equality [symmetric])
530   apply (erule ex1E)
531   apply (rule allI)
532   apply (rule ex1I)
533   apply (erule spec)
534   apply (rule ccontr)
535   apply (erule_tac x = "%z. if z = x then y else f z" in allE)
536   apply (erule impE)
537   apply (rule allI)
538   apply (rule_tac P = "xa = x" in case_split_thm)
539   apply (drule_tac  x = x in fun_cong)
540   apply simp_all
541   done
543 text{*Needs only HOL-lemmas:*}
544 lemma mk_left_commute:
545   assumes a: "\<And>x y z. f (f x y) z = f x (f y z)" and
546           c: "\<And>x y. f x y = f y x"
547   shows "f x (f y z) = f y (f x z)"
548 by(rule trans[OF trans[OF c a] arg_cong[OF c, of "f y"]])
551 subsubsection {* Generic cases and induction *}
553 constdefs
554   induct_forall :: "('a => bool) => bool"
555   "induct_forall P == \<forall>x. P x"
556   induct_implies :: "bool => bool => bool"
557   "induct_implies A B == A --> B"
558   induct_equal :: "'a => 'a => bool"
559   "induct_equal x y == x = y"
560   induct_conj :: "bool => bool => bool"
561   "induct_conj A B == A & B"
563 lemma induct_forall_eq: "(!!x. P x) == Trueprop (induct_forall (\<lambda>x. P x))"
564   by (simp only: atomize_all induct_forall_def)
566 lemma induct_implies_eq: "(A ==> B) == Trueprop (induct_implies A B)"
567   by (simp only: atomize_imp induct_implies_def)
569 lemma induct_equal_eq: "(x == y) == Trueprop (induct_equal x y)"
570   by (simp only: atomize_eq induct_equal_def)
572 lemma induct_forall_conj: "induct_forall (\<lambda>x. induct_conj (A x) (B x)) =
573     induct_conj (induct_forall A) (induct_forall B)"
574   by (unfold induct_forall_def induct_conj_def) rules
576 lemma induct_implies_conj: "induct_implies C (induct_conj A B) =
577     induct_conj (induct_implies C A) (induct_implies C B)"
578   by (unfold induct_implies_def induct_conj_def) rules
580 lemma induct_conj_curry: "(induct_conj A B ==> PROP C) == (A ==> B ==> PROP C)"
581 proof
582   assume r: "induct_conj A B ==> PROP C" and A B
583   show "PROP C" by (rule r) (simp! add: induct_conj_def)
584 next
585   assume r: "A ==> B ==> PROP C" and "induct_conj A B"
586   show "PROP C" by (rule r) (simp! add: induct_conj_def)+
587 qed
589 lemma induct_impliesI: "(A ==> B) ==> induct_implies A B"
590   by (simp add: induct_implies_def)
592 lemmas induct_atomize = atomize_conj induct_forall_eq induct_implies_eq induct_equal_eq
593 lemmas induct_rulify1 [symmetric, standard] = induct_forall_eq induct_implies_eq induct_equal_eq
594 lemmas induct_rulify2 = induct_forall_def induct_implies_def induct_equal_def induct_conj_def
595 lemmas induct_conj = induct_forall_conj induct_implies_conj induct_conj_curry
597 hide const induct_forall induct_implies induct_equal induct_conj
600 text {* Method setup. *}
602 ML {*
603   structure InductMethod = InductMethodFun
604   (struct
605     val dest_concls = HOLogic.dest_concls;
606     val cases_default = thm "case_split";
607     val local_impI = thm "induct_impliesI";
608     val conjI = thm "conjI";
609     val atomize = thms "induct_atomize";
610     val rulify1 = thms "induct_rulify1";
611     val rulify2 = thms "induct_rulify2";
612     val localize = [Thm.symmetric (thm "induct_implies_def")];
613   end);
614 *}
616 setup InductMethod.setup
619 subsection {* Order signatures and orders *}
621 axclass
622   ord < type
624 syntax
625   "op <"        :: "['a::ord, 'a] => bool"             ("op <")
626   "op <="       :: "['a::ord, 'a] => bool"             ("op <=")
628 global
630 consts
631   "op <"        :: "['a::ord, 'a] => bool"             ("(_/ < _)"  [50, 51] 50)
632   "op <="       :: "['a::ord, 'a] => bool"             ("(_/ <= _)" [50, 51] 50)
634 local
636 syntax (xsymbols)
637   "op <="       :: "['a::ord, 'a] => bool"             ("op \<le>")
638   "op <="       :: "['a::ord, 'a] => bool"             ("(_/ \<le> _)"  [50, 51] 50)
641 subsubsection {* Monotonicity *}
643 locale mono =
644   fixes f
645   assumes mono: "A <= B ==> f A <= f B"
647 lemmas monoI [intro?] = mono.intro
648   and monoD [dest?] = mono.mono
650 constdefs
651   min :: "['a::ord, 'a] => 'a"
652   "min a b == (if a <= b then a else b)"
653   max :: "['a::ord, 'a] => 'a"
654   "max a b == (if a <= b then b else a)"
656 lemma min_leastL: "(!!x. least <= x) ==> min least x = least"
657   by (simp add: min_def)
659 lemma min_of_mono:
660     "ALL x y. (f x <= f y) = (x <= y) ==> min (f m) (f n) = f (min m n)"
661   by (simp add: min_def)
663 lemma max_leastL: "(!!x. least <= x) ==> max least x = x"
664   by (simp add: max_def)
666 lemma max_of_mono:
667     "ALL x y. (f x <= f y) = (x <= y) ==> max (f m) (f n) = f (max m n)"
668   by (simp add: max_def)
671 subsubsection "Orders"
673 axclass order < ord
674   order_refl [iff]: "x <= x"
675   order_trans: "x <= y ==> y <= z ==> x <= z"
676   order_antisym: "x <= y ==> y <= x ==> x = y"
677   order_less_le: "(x < y) = (x <= y & x ~= y)"
680 text {* Reflexivity. *}
682 lemma order_eq_refl: "!!x::'a::order. x = y ==> x <= y"
683     -- {* This form is useful with the classical reasoner. *}
684   apply (erule ssubst)
685   apply (rule order_refl)
686   done
688 lemma order_less_irrefl [iff]: "~ x < (x::'a::order)"
689   by (simp add: order_less_le)
691 lemma order_le_less: "((x::'a::order) <= y) = (x < y | x = y)"
692     -- {* NOT suitable for iff, since it can cause PROOF FAILED. *}
693   apply (simp add: order_less_le)
694   apply blast
695   done
697 lemmas order_le_imp_less_or_eq = order_le_less [THEN iffD1, standard]
699 lemma order_less_imp_le: "!!x::'a::order. x < y ==> x <= y"
700   by (simp add: order_less_le)
703 text {* Asymmetry. *}
705 lemma order_less_not_sym: "(x::'a::order) < y ==> ~ (y < x)"
706   by (simp add: order_less_le order_antisym)
708 lemma order_less_asym: "x < (y::'a::order) ==> (~P ==> y < x) ==> P"
709   apply (drule order_less_not_sym)
710   apply (erule contrapos_np)
711   apply simp
712   done
715 text {* Transitivity. *}
717 lemma order_less_trans: "!!x::'a::order. [| x < y; y < z |] ==> x < z"
718   apply (simp add: order_less_le)
719   apply (blast intro: order_trans order_antisym)
720   done
722 lemma order_le_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
727 lemma order_less_le_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
733 text {* Useful for simplification, but too risky to include by default. *}
735 lemma order_less_imp_not_less: "(x::'a::order) < y ==>  (~ y < x) = True"
736   by (blast elim: order_less_asym)
738 lemma order_less_imp_triv: "(x::'a::order) < y ==>  (y < x --> P) = True"
739   by (blast elim: order_less_asym)
741 lemma order_less_imp_not_eq: "(x::'a::order) < y ==>  (x = y) = False"
742   by auto
744 lemma order_less_imp_not_eq2: "(x::'a::order) < y ==>  (y = x) = False"
745   by auto
748 text {* Other operators. *}
750 lemma min_leastR: "(!!x::'a::order. least <= x) ==> min x least = least"
751   apply (simp add: min_def)
752   apply (blast intro: order_antisym)
753   done
755 lemma max_leastR: "(!!x::'a::order. least <= x) ==> max x least = x"
756   apply (simp add: max_def)
757   apply (blast intro: order_antisym)
758   done
761 subsubsection {* Least value operator *}
763 constdefs
764   Least :: "('a::ord => bool) => 'a"               (binder "LEAST " 10)
765   "Least P == THE x. P x & (ALL y. P y --> x <= y)"
766     -- {* We can no longer use LeastM because the latter requires Hilbert-AC. *}
768 lemma LeastI2:
769   "[| P (x::'a::order);
770       !!y. P y ==> x <= y;
771       !!x. [| P x; ALL y. P y --> x \<le> y |] ==> Q x |]
772    ==> Q (Least P)"
773   apply (unfold Least_def)
774   apply (rule theI2)
775     apply (blast intro: order_antisym)+
776   done
778 lemma Least_equality:
779     "[| P (k::'a::order); !!x. P x ==> k <= x |] ==> (LEAST x. P x) = k"
780   apply (simp add: Least_def)
781   apply (rule the_equality)
782   apply (auto intro!: order_antisym)
783   done
786 subsubsection "Linear / total orders"
788 axclass linorder < order
789   linorder_linear: "x <= y | y <= x"
791 lemma linorder_less_linear: "!!x::'a::linorder. x<y | x=y | y<x"
792   apply (simp add: order_less_le)
793   apply (insert linorder_linear)
794   apply blast
795   done
797 lemma linorder_cases [case_names less equal greater]:
798     "((x::'a::linorder) < y ==> P) ==> (x = y ==> P) ==> (y < x ==> P) ==> P"
799   apply (insert linorder_less_linear)
800   apply blast
801   done
803 lemma linorder_not_less: "!!x::'a::linorder. (~ x < y) = (y <= x)"
804   apply (simp add: order_less_le)
805   apply (insert linorder_linear)
806   apply (blast intro: order_antisym)
807   done
809 lemma linorder_not_le: "!!x::'a::linorder. (~ x <= y) = (y < x)"
810   apply (simp add: order_less_le)
811   apply (insert linorder_linear)
812   apply (blast intro: order_antisym)
813   done
815 lemma linorder_neq_iff: "!!x::'a::linorder. (x ~= y) = (x<y | y<x)"
816   apply (cut_tac x = x and y = y in linorder_less_linear)
817   apply auto
818   done
820 lemma linorder_neqE: "x ~= (y::'a::linorder) ==> (x < y ==> R) ==> (y < x ==> R) ==> R"
821   apply (simp add: linorder_neq_iff)
822   apply blast
823   done
826 subsubsection "Min and max on (linear) orders"
828 lemma min_same [simp]: "min (x::'a::order) x = x"
829   by (simp add: min_def)
831 lemma max_same [simp]: "max (x::'a::order) x = x"
832   by (simp add: max_def)
834 lemma le_max_iff_disj: "!!z::'a::linorder. (z <= max x y) = (z <= x | z <= y)"
835   apply (simp add: max_def)
836   apply (insert linorder_linear)
837   apply (blast intro: order_trans)
838   done
840 lemma le_maxI1: "(x::'a::linorder) <= max x y"
841   by (simp add: le_max_iff_disj)
843 lemma le_maxI2: "(y::'a::linorder) <= max x y"
844     -- {* CANNOT use with @{text "[intro!]"} because blast will give PROOF FAILED. *}
845   by (simp add: le_max_iff_disj)
847 lemma less_max_iff_disj: "!!z::'a::linorder. (z < max x y) = (z < x | z < y)"
848   apply (simp add: max_def order_le_less)
849   apply (insert linorder_less_linear)
850   apply (blast intro: order_less_trans)
851   done
853 lemma max_le_iff_conj [simp]:
854     "!!z::'a::linorder. (max x y <= z) = (x <= z & y <= z)"
855   apply (simp add: max_def)
856   apply (insert linorder_linear)
857   apply (blast intro: order_trans)
858   done
860 lemma max_less_iff_conj [simp]:
861     "!!z::'a::linorder. (max x y < z) = (x < z & y < z)"
862   apply (simp add: order_le_less max_def)
863   apply (insert linorder_less_linear)
864   apply (blast intro: order_less_trans)
865   done
867 lemma le_min_iff_conj [simp]:
868     "!!z::'a::linorder. (z <= min x y) = (z <= x & z <= y)"
869     -- {* @{text "[iff]"} screws up a @{text blast} in MiniML *}
870   apply (simp add: min_def)
871   apply (insert linorder_linear)
872   apply (blast intro: order_trans)
873   done
875 lemma min_less_iff_conj [simp]:
876     "!!z::'a::linorder. (z < min x y) = (z < x & z < y)"
877   apply (simp add: order_le_less min_def)
878   apply (insert linorder_less_linear)
879   apply (blast intro: order_less_trans)
880   done
882 lemma min_le_iff_disj: "!!z::'a::linorder. (min x y <= z) = (x <= z | y <= z)"
883   apply (simp add: min_def)
884   apply (insert linorder_linear)
885   apply (blast intro: order_trans)
886   done
888 lemma min_less_iff_disj: "!!z::'a::linorder. (min x y < z) = (x < z | y < z)"
889   apply (simp add: min_def order_le_less)
890   apply (insert linorder_less_linear)
891   apply (blast intro: order_less_trans)
892   done
894 lemma max_assoc: "!!x::'a::linorder. max (max x y) z = max x (max y z)"
896 apply(rule conjI)
897 apply(blast intro:order_trans)
899 apply(blast dest: order_less_trans order_le_less_trans)
900 done
902 lemma max_commute: "!!x::'a::linorder. max x y = max y x"
904 apply(rule conjI)
905 apply(blast intro:order_antisym)
907 apply(blast dest: order_less_trans)
908 done
910 lemmas max_ac = max_assoc max_commute
911                 mk_left_commute[of max,OF max_assoc max_commute]
913 lemma min_assoc: "!!x::'a::linorder. min (min x y) z = min x (min y z)"
915 apply(rule conjI)
916 apply(blast intro:order_trans)
918 apply(blast dest: order_less_trans order_le_less_trans)
919 done
921 lemma min_commute: "!!x::'a::linorder. min x y = min y x"
923 apply(rule conjI)
924 apply(blast intro:order_antisym)
926 apply(blast dest: order_less_trans)
927 done
929 lemmas min_ac = min_assoc min_commute
930                 mk_left_commute[of min,OF min_assoc min_commute]
932 lemma split_min:
933     "P (min (i::'a::linorder) j) = ((i <= j --> P(i)) & (~ i <= j --> P(j)))"
934   by (simp add: min_def)
936 lemma split_max:
937     "P (max (i::'a::linorder) j) = ((i <= j --> P(j)) & (~ i <= j --> P(i)))"
938   by (simp add: max_def)
941 subsubsection "Bounded quantifiers"
943 syntax
944   "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3ALL _<_./ _)"  [0, 0, 10] 10)
945   "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3EX _<_./ _)"  [0, 0, 10] 10)
946   "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3ALL _<=_./ _)" [0, 0, 10] 10)
947   "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3EX _<=_./ _)" [0, 0, 10] 10)
949 syntax (xsymbols)
950   "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
951   "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
952   "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
953   "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
955 syntax (HOL)
956   "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3! _<_./ _)"  [0, 0, 10] 10)
957   "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3? _<_./ _)"  [0, 0, 10] 10)
958   "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3! _<=_./ _)" [0, 0, 10] 10)
959   "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3? _<=_./ _)" [0, 0, 10] 10)
961 translations
962  "ALL x<y. P"   =>  "ALL x. x < y --> P"
963  "EX x<y. P"    =>  "EX x. x < y  & P"
964  "ALL x<=y. P"  =>  "ALL x. x <= y --> P"
965  "EX x<=y. P"   =>  "EX x. x <= y & P"
967 end