src/HOL/HOL.thy
 author paulson Fri May 14 16:53:15 2004 +0200 (2004-05-14) changeset 14749 9ccfd0f59e11 parent 14690 f61ea8bfa81e child 14854 61bdf2ae4dc5 permissions -rw-r--r--
new atomize theorem
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_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
106   Not           :: "bool => bool"                        ("\<not> _"  40)
107   "op &"        :: "[bool, bool] => bool"                (infixr "\<and>" 35)
108   "op |"        :: "[bool, bool] => bool"                (infixr "\<or>" 30)
109   "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
110   "ALL "        :: "[idts, bool] => bool"                ("(3\<forall>_./ _)" [0, 10] 10)
111   "EX "         :: "[idts, bool] => bool"                ("(3\<exists>_./ _)" [0, 10] 10)
112   "EX! "        :: "[idts, bool] => bool"                ("(3\<exists>!_./ _)" [0, 10] 10)
114 syntax (HOL)
115   "ALL "        :: "[idts, bool] => bool"                ("(3! _./ _)" [0, 10] 10)
116   "EX "         :: "[idts, bool] => bool"                ("(3? _./ _)" [0, 10] 10)
117   "EX! "        :: "[idts, bool] => bool"                ("(3?! _./ _)" [0, 10] 10)
120 subsubsection {* Axioms and basic definitions *}
122 axioms
123   eq_reflection: "(x=y) ==> (x==y)"
125   refl:         "t = (t::'a)"
126   subst:        "[| s = t; P(s) |] ==> P(t::'a)"
128   ext:          "(!!x::'a. (f x ::'b) = g x) ==> (%x. f x) = (%x. g x)"
129     -- {* Extensionality is built into the meta-logic, and this rule expresses *}
130     -- {* a related property.  It is an eta-expanded version of the traditional *}
131     -- {* rule, and similar to the ABS rule of HOL *}
133   the_eq_trivial: "(THE x. x = a) = (a::'a)"
135   impI:         "(P ==> Q) ==> P-->Q"
136   mp:           "[| P-->Q;  P |] ==> Q"
138 defs
139   True_def:     "True      == ((%x::bool. x) = (%x. x))"
140   All_def:      "All(P)    == (P = (%x. True))"
141   Ex_def:       "Ex(P)     == !Q. (!x. P x --> Q) --> Q"
142   False_def:    "False     == (!P. P)"
143   not_def:      "~ P       == P-->False"
144   and_def:      "P & Q     == !R. (P-->Q-->R) --> R"
145   or_def:       "P | Q     == !R. (P-->R) --> (Q-->R) --> R"
146   Ex1_def:      "Ex1(P)    == ? x. P(x) & (! y. P(y) --> y=x)"
148 axioms
149   iff:          "(P-->Q) --> (Q-->P) --> (P=Q)"
150   True_or_False:  "(P=True) | (P=False)"
152 defs
153   Let_def:      "Let s f == f(s)"
154   if_def:       "If P x y == THE z::'a. (P=True --> z=x) & (P=False --> z=y)"
156 finalconsts
157   "op ="
158   "op -->"
159   The
160   arbitrary
162 subsubsection {* Generic algebraic operations *}
164 axclass zero < type
165 axclass one < type
166 axclass plus < type
167 axclass minus < type
168 axclass times < type
169 axclass inverse < type
171 global
173 consts
174   "0"           :: "'a::zero"                       ("0")
175   "1"           :: "'a::one"                        ("1")
176   "+"           :: "['a::plus, 'a]  => 'a"          (infixl 65)
177   -             :: "['a::minus, 'a] => 'a"          (infixl 65)
178   uminus        :: "['a::minus] => 'a"              ("- _"  80)
179   *             :: "['a::times, 'a] => 'a"          (infixl 70)
181 syntax
182   "_index1"  :: index    ("\<^sub>1")
183 translations
184   (index) "\<^sub>1" => (index) "\<^bsub>\<struct>\<^esub>"
186 local
188 typed_print_translation {*
189   let
190     fun tr' c = (c, fn show_sorts => fn T => fn ts =>
191       if T = dummyT orelse not (! show_types) andalso can Term.dest_Type T then raise Match
192       else Syntax.const Syntax.constrainC \$ Syntax.const c \$ Syntax.term_of_typ show_sorts T);
193   in [tr' "0", tr' "1"] end;
194 *} -- {* show types that are presumably too general *}
197 consts
198   abs           :: "'a::minus => 'a"
199   inverse       :: "'a::inverse => 'a"
200   divide        :: "['a::inverse, 'a] => 'a"        (infixl "'/" 70)
202 syntax (xsymbols)
203   abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
204 syntax (HTML output)
205   abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
208 subsection {* Theory and package setup *}
210 subsubsection {* Basic lemmas *}
212 use "HOL_lemmas.ML"
213 theorems case_split = case_split_thm [case_names True False]
216 subsubsection {* Intuitionistic Reasoning *}
218 lemma impE':
219   assumes 1: "P --> Q"
220     and 2: "Q ==> R"
221     and 3: "P --> Q ==> P"
222   shows R
223 proof -
224   from 3 and 1 have P .
225   with 1 have Q by (rule impE)
226   with 2 show R .
227 qed
229 lemma allE':
230   assumes 1: "ALL x. P x"
231     and 2: "P x ==> ALL x. P x ==> Q"
232   shows Q
233 proof -
234   from 1 have "P x" by (rule spec)
235   from this and 1 show Q by (rule 2)
236 qed
238 lemma notE':
239   assumes 1: "~ P"
240     and 2: "~ P ==> P"
241   shows R
242 proof -
243   from 2 and 1 have P .
244   with 1 show R by (rule notE)
245 qed
247 lemmas [CPure.elim!] = disjE iffE FalseE conjE exE
248   and [CPure.intro!] = iffI conjI impI TrueI notI allI refl
249   and [CPure.elim 2] = allE notE' impE'
250   and [CPure.intro] = exI disjI2 disjI1
252 lemmas [trans] = trans
253   and [sym] = sym not_sym
254   and [CPure.elim?] = iffD1 iffD2 impE
257 subsubsection {* Atomizing meta-level connectives *}
259 lemma atomize_all [atomize]: "(!!x. P x) == Trueprop (ALL x. P x)"
260 proof
261   assume "!!x. P x"
262   show "ALL x. P x" by (rule allI)
263 next
264   assume "ALL x. P x"
265   thus "!!x. P x" by (rule allE)
266 qed
268 lemma atomize_imp [atomize]: "(A ==> B) == Trueprop (A --> B)"
269 proof
270   assume r: "A ==> B"
271   show "A --> B" by (rule impI) (rule r)
272 next
273   assume "A --> B" and A
274   thus B by (rule mp)
275 qed
277 lemma atomize_not: "(A ==> False) == Trueprop (~A)"
278 proof
279   assume r: "A ==> False"
280   show "~A" by (rule notI) (rule r)
281 next
282   assume "~A" and A
283   thus False by (rule notE)
284 qed
286 lemma atomize_eq [atomize]: "(x == y) == Trueprop (x = y)"
287 proof
288   assume "x == y"
289   show "x = y" by (unfold prems) (rule refl)
290 next
291   assume "x = y"
292   thus "x == y" by (rule eq_reflection)
293 qed
295 lemma atomize_conj [atomize]:
296   "(!!C. (A ==> B ==> PROP C) ==> PROP C) == Trueprop (A & B)"
297 proof
298   assume "!!C. (A ==> B ==> PROP C) ==> PROP C"
299   show "A & B" by (rule conjI)
300 next
301   fix C
302   assume "A & B"
303   assume "A ==> B ==> PROP C"
304   thus "PROP C"
305   proof this
306     show A by (rule conjunct1)
307     show B by (rule conjunct2)
308   qed
309 qed
311 lemmas [symmetric, rulify] = atomize_all atomize_imp
314 subsubsection {* Classical Reasoner setup *}
317 setup hypsubst_setup
319 ML_setup {*
320   Context.>> (ContextRules.addSWrapper (fn tac => hyp_subst_tac' ORELSE' tac));
321 *}
323 setup Classical.setup
324 setup clasetup
326 lemmas [intro?] = ext
327   and [elim?] = ex1_implies_ex
329 use "blastdata.ML"
330 setup Blast.setup
333 subsubsection {* Simplifier setup *}
335 lemma meta_eq_to_obj_eq: "x == y ==> x = y"
336 proof -
337   assume r: "x == y"
338   show "x = y" by (unfold r) (rule refl)
339 qed
341 lemma eta_contract_eq: "(%s. f s) = f" ..
343 lemma simp_thms:
344   shows not_not: "(~ ~ P) = P"
345   and
346     "(P ~= Q) = (P = (~Q))"
347     "(P | ~P) = True"    "(~P | P) = True"
348     "((~P) = (~Q)) = (P=Q)"
349     "(x = x) = True"
350     "(~True) = False"  "(~False) = True"
351     "(~P) ~= P"  "P ~= (~P)"
352     "(True=P) = P"  "(P=True) = P"  "(False=P) = (~P)"  "(P=False) = (~P)"
353     "(True --> P) = P"  "(False --> P) = True"
354     "(P --> True) = True"  "(P --> P) = True"
355     "(P --> False) = (~P)"  "(P --> ~P) = (~P)"
356     "(P & True) = P"  "(True & P) = P"
357     "(P & False) = False"  "(False & P) = False"
358     "(P & P) = P"  "(P & (P & Q)) = (P & Q)"
359     "(P & ~P) = False"    "(~P & P) = False"
360     "(P | True) = True"  "(True | P) = True"
361     "(P | False) = P"  "(False | P) = P"
362     "(P | P) = P"  "(P | (P | Q)) = (P | Q)" and
363     "(ALL x. P) = P"  "(EX x. P) = P"  "EX x. x=t"  "EX x. t=x"
364     -- {* needed for the one-point-rule quantifier simplification procs *}
365     -- {* essential for termination!! *} and
366     "!!P. (EX x. x=t & P(x)) = P(t)"
367     "!!P. (EX x. t=x & P(x)) = P(t)"
368     "!!P. (ALL x. x=t --> P(x)) = P(t)"
369     "!!P. (ALL x. t=x --> P(x)) = P(t)"
370   by (blast, blast, blast, blast, blast, rules+)
372 lemma imp_cong: "(P = P') ==> (P' ==> (Q = Q')) ==> ((P --> Q) = (P' --> Q'))"
373   by rules
375 lemma ex_simps:
376   "!!P Q. (EX x. P x & Q)   = ((EX x. P x) & Q)"
377   "!!P Q. (EX x. P & Q x)   = (P & (EX x. Q x))"
378   "!!P Q. (EX x. P x | Q)   = ((EX x. P x) | Q)"
379   "!!P Q. (EX x. P | Q x)   = (P | (EX x. Q x))"
380   "!!P Q. (EX x. P x --> Q) = ((ALL x. P x) --> Q)"
381   "!!P Q. (EX x. P --> Q x) = (P --> (EX x. Q x))"
382   -- {* Miniscoping: pushing in existential quantifiers. *}
383   by (rules | blast)+
385 lemma all_simps:
386   "!!P Q. (ALL x. P x & Q)   = ((ALL x. P x) & Q)"
387   "!!P Q. (ALL x. P & Q x)   = (P & (ALL x. Q x))"
388   "!!P Q. (ALL x. P x | Q)   = ((ALL x. P x) | Q)"
389   "!!P Q. (ALL x. P | Q x)   = (P | (ALL x. Q x))"
390   "!!P Q. (ALL x. P x --> Q) = ((EX x. P x) --> Q)"
391   "!!P Q. (ALL x. P --> Q x) = (P --> (ALL x. Q x))"
392   -- {* Miniscoping: pushing in universal quantifiers. *}
393   by (rules | blast)+
395 lemma disj_absorb: "(A | A) = A"
396   by blast
398 lemma disj_left_absorb: "(A | (A | B)) = (A | B)"
399   by blast
401 lemma conj_absorb: "(A & A) = A"
402   by blast
404 lemma conj_left_absorb: "(A & (A & B)) = (A & B)"
405   by blast
407 lemma eq_ac:
408   shows eq_commute: "(a=b) = (b=a)"
409     and eq_left_commute: "(P=(Q=R)) = (Q=(P=R))"
410     and eq_assoc: "((P=Q)=R) = (P=(Q=R))" by (rules, blast+)
411 lemma neq_commute: "(a~=b) = (b~=a)" by rules
413 lemma conj_comms:
414   shows conj_commute: "(P&Q) = (Q&P)"
415     and conj_left_commute: "(P&(Q&R)) = (Q&(P&R))" by rules+
416 lemma conj_assoc: "((P&Q)&R) = (P&(Q&R))" by rules
418 lemma disj_comms:
419   shows disj_commute: "(P|Q) = (Q|P)"
420     and disj_left_commute: "(P|(Q|R)) = (Q|(P|R))" by rules+
421 lemma disj_assoc: "((P|Q)|R) = (P|(Q|R))" by rules
423 lemma conj_disj_distribL: "(P&(Q|R)) = (P&Q | P&R)" by rules
424 lemma conj_disj_distribR: "((P|Q)&R) = (P&R | Q&R)" by rules
426 lemma disj_conj_distribL: "(P|(Q&R)) = ((P|Q) & (P|R))" by rules
427 lemma disj_conj_distribR: "((P&Q)|R) = ((P|R) & (Q|R))" by rules
429 lemma imp_conjR: "(P --> (Q&R)) = ((P-->Q) & (P-->R))" by rules
430 lemma imp_conjL: "((P&Q) -->R)  = (P --> (Q --> R))" by rules
431 lemma imp_disjL: "((P|Q) --> R) = ((P-->R)&(Q-->R))" by rules
433 text {* These two are specialized, but @{text imp_disj_not1} is useful in @{text "Auth/Yahalom"}. *}
434 lemma imp_disj_not1: "(P --> Q | R) = (~Q --> P --> R)" by blast
435 lemma imp_disj_not2: "(P --> Q | R) = (~R --> P --> Q)" by blast
437 lemma imp_disj1: "((P-->Q)|R) = (P--> Q|R)" by blast
438 lemma imp_disj2: "(Q|(P-->R)) = (P--> Q|R)" by blast
440 lemma de_Morgan_disj: "(~(P | Q)) = (~P & ~Q)" by rules
441 lemma de_Morgan_conj: "(~(P & Q)) = (~P | ~Q)" by blast
442 lemma not_imp: "(~(P --> Q)) = (P & ~Q)" by blast
443 lemma not_iff: "(P~=Q) = (P = (~Q))" by blast
444 lemma disj_not1: "(~P | Q) = (P --> Q)" by blast
445 lemma disj_not2: "(P | ~Q) = (Q --> P)"  -- {* changes orientation :-( *}
446   by blast
447 lemma imp_conv_disj: "(P --> Q) = ((~P) | Q)" by blast
449 lemma iff_conv_conj_imp: "(P = Q) = ((P --> Q) & (Q --> P))" by rules
452 lemma cases_simp: "((P --> Q) & (~P --> Q)) = Q"
453   -- {* Avoids duplication of subgoals after @{text split_if}, when the true and false *}
454   -- {* cases boil down to the same thing. *}
455   by blast
457 lemma not_all: "(~ (! x. P(x))) = (? x.~P(x))" by blast
458 lemma imp_all: "((! x. P x) --> Q) = (? x. P x --> Q)" by blast
459 lemma not_ex: "(~ (? x. P(x))) = (! x.~P(x))" by rules
460 lemma imp_ex: "((? x. P x) --> Q) = (! x. P x --> Q)" by rules
462 lemma ex_disj_distrib: "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))" by rules
463 lemma all_conj_distrib: "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))" by rules
465 text {*
466   \medskip The @{text "&"} congruence rule: not included by default!
467   May slow rewrite proofs down by as much as 50\% *}
469 lemma conj_cong:
470     "(P = P') ==> (P' ==> (Q = Q')) ==> ((P & Q) = (P' & Q'))"
471   by rules
473 lemma rev_conj_cong:
474     "(Q = Q') ==> (Q' ==> (P = P')) ==> ((P & Q) = (P' & Q'))"
475   by rules
477 text {* The @{text "|"} congruence rule: not included by default! *}
479 lemma disj_cong:
480     "(P = P') ==> (~P' ==> (Q = Q')) ==> ((P | Q) = (P' | Q'))"
481   by blast
483 lemma eq_sym_conv: "(x = y) = (y = x)"
484   by rules
487 text {* \medskip if-then-else rules *}
489 lemma if_True: "(if True then x else y) = x"
490   by (unfold if_def) blast
492 lemma if_False: "(if False then x else y) = y"
493   by (unfold if_def) blast
495 lemma if_P: "P ==> (if P then x else y) = x"
496   by (unfold if_def) blast
498 lemma if_not_P: "~P ==> (if P then x else y) = y"
499   by (unfold if_def) blast
501 lemma split_if: "P (if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))"
502   apply (rule case_split [of Q])
503    apply (subst if_P)
504     prefer 3 apply (subst if_not_P, blast+)
505   done
507 lemma split_if_asm: "P (if Q then x else y) = (~((Q & ~P x) | (~Q & ~P y)))"
508 by (subst split_if, blast)
510 lemmas if_splits = split_if split_if_asm
512 lemma if_def2: "(if Q then x else y) = ((Q --> x) & (~ Q --> y))"
513   by (rule split_if)
515 lemma if_cancel: "(if c then x else x) = x"
516 by (subst split_if, blast)
518 lemma if_eq_cancel: "(if x = y then y else x) = x"
519 by (subst split_if, blast)
521 lemma if_bool_eq_conj: "(if P then Q else R) = ((P-->Q) & (~P-->R))"
522   -- {* This form is useful for expanding @{text if}s on the RIGHT of the @{text "==>"} symbol. *}
523   by (rule split_if)
525 lemma if_bool_eq_disj: "(if P then Q else R) = ((P&Q) | (~P&R))"
526   -- {* And this form is useful for expanding @{text if}s on the LEFT. *}
527   apply (subst split_if, blast)
528   done
530 lemma Eq_TrueI: "P ==> P == True" by (unfold atomize_eq) rules
531 lemma Eq_FalseI: "~P ==> P == False" by (unfold atomize_eq) rules
533 subsubsection {* Actual Installation of the Simplifier *}
535 use "simpdata.ML"
536 setup Simplifier.setup
537 setup "Simplifier.method_setup Splitter.split_modifiers" setup simpsetup
538 setup Splitter.setup setup Clasimp.setup
540 declare disj_absorb [simp] conj_absorb [simp]
542 lemma ex1_eq[iff]: "EX! x. x = t" "EX! x. t = x"
543 by blast+
545 theorem choice_eq: "(ALL x. EX! y. P x y) = (EX! f. ALL x. P x (f x))"
546   apply (rule iffI)
547   apply (rule_tac a = "%x. THE y. P x y" in ex1I)
548   apply (fast dest!: theI')
549   apply (fast intro: ext the1_equality [symmetric])
550   apply (erule ex1E)
551   apply (rule allI)
552   apply (rule ex1I)
553   apply (erule spec)
554   apply (erule_tac x = "%z. if z = x then y else f z" in allE)
555   apply (erule impE)
556   apply (rule allI)
557   apply (rule_tac P = "xa = x" in case_split_thm)
558   apply (drule_tac  x = x in fun_cong, simp_all)
559   done
561 text{*Needs only HOL-lemmas:*}
562 lemma mk_left_commute:
563   assumes a: "\<And>x y z. f (f x y) z = f x (f y z)" and
564           c: "\<And>x y. f x y = f y x"
565   shows "f x (f y z) = f y (f x z)"
566 by(rule trans[OF trans[OF c a] arg_cong[OF c, of "f y"]])
569 subsubsection {* Generic cases and induction *}
571 constdefs
572   induct_forall :: "('a => bool) => bool"
573   "induct_forall P == \<forall>x. P x"
574   induct_implies :: "bool => bool => bool"
575   "induct_implies A B == A --> B"
576   induct_equal :: "'a => 'a => bool"
577   "induct_equal x y == x = y"
578   induct_conj :: "bool => bool => bool"
579   "induct_conj A B == A & B"
581 lemma induct_forall_eq: "(!!x. P x) == Trueprop (induct_forall (\<lambda>x. P x))"
582   by (simp only: atomize_all induct_forall_def)
584 lemma induct_implies_eq: "(A ==> B) == Trueprop (induct_implies A B)"
585   by (simp only: atomize_imp induct_implies_def)
587 lemma induct_equal_eq: "(x == y) == Trueprop (induct_equal x y)"
588   by (simp only: atomize_eq induct_equal_def)
590 lemma induct_forall_conj: "induct_forall (\<lambda>x. induct_conj (A x) (B x)) =
591     induct_conj (induct_forall A) (induct_forall B)"
592   by (unfold induct_forall_def induct_conj_def) rules
594 lemma induct_implies_conj: "induct_implies C (induct_conj A B) =
595     induct_conj (induct_implies C A) (induct_implies C B)"
596   by (unfold induct_implies_def induct_conj_def) rules
598 lemma induct_conj_curry: "(induct_conj A B ==> PROP C) == (A ==> B ==> PROP C)"
599 proof
600   assume r: "induct_conj A B ==> PROP C" and A B
601   show "PROP C" by (rule r) (simp! add: induct_conj_def)
602 next
603   assume r: "A ==> B ==> PROP C" and "induct_conj A B"
604   show "PROP C" by (rule r) (simp! add: induct_conj_def)+
605 qed
607 lemma induct_impliesI: "(A ==> B) ==> induct_implies A B"
608   by (simp add: induct_implies_def)
610 lemmas induct_atomize = atomize_conj induct_forall_eq induct_implies_eq induct_equal_eq
611 lemmas induct_rulify1 [symmetric, standard] = induct_forall_eq induct_implies_eq induct_equal_eq
612 lemmas induct_rulify2 = induct_forall_def induct_implies_def induct_equal_def induct_conj_def
613 lemmas induct_conj = induct_forall_conj induct_implies_conj induct_conj_curry
615 hide const induct_forall induct_implies induct_equal induct_conj
618 text {* Method setup. *}
620 ML {*
621   structure InductMethod = InductMethodFun
622   (struct
623     val dest_concls = HOLogic.dest_concls;
624     val cases_default = thm "case_split";
625     val local_impI = thm "induct_impliesI";
626     val conjI = thm "conjI";
627     val atomize = thms "induct_atomize";
628     val rulify1 = thms "induct_rulify1";
629     val rulify2 = thms "induct_rulify2";
630     val localize = [Thm.symmetric (thm "induct_implies_def")];
631   end);
632 *}
634 setup InductMethod.setup
637 subsection {* Order signatures and orders *}
639 axclass
640   ord < type
642 syntax
643   "op <"        :: "['a::ord, 'a] => bool"             ("op <")
644   "op <="       :: "['a::ord, 'a] => bool"             ("op <=")
646 global
648 consts
649   "op <"        :: "['a::ord, 'a] => bool"             ("(_/ < _)"  [50, 51] 50)
650   "op <="       :: "['a::ord, 'a] => bool"             ("(_/ <= _)" [50, 51] 50)
652 local
654 syntax (xsymbols)
655   "op <="       :: "['a::ord, 'a] => bool"             ("op \<le>")
656   "op <="       :: "['a::ord, 'a] => bool"             ("(_/ \<le> _)"  [50, 51] 50)
658 syntax (HTML output)
659   "op <="       :: "['a::ord, 'a] => bool"             ("op \<le>")
660   "op <="       :: "['a::ord, 'a] => bool"             ("(_/ \<le> _)"  [50, 51] 50)
663 lemma Not_eq_iff: "((~P) = (~Q)) = (P = Q)"
664 by blast
666 subsubsection {* Monotonicity *}
668 locale mono =
669   fixes f
670   assumes mono: "A <= B ==> f A <= f B"
672 lemmas monoI [intro?] = mono.intro
673   and monoD [dest?] = mono.mono
675 constdefs
676   min :: "['a::ord, 'a] => 'a"
677   "min a b == (if a <= b then a else b)"
678   max :: "['a::ord, 'a] => 'a"
679   "max a b == (if a <= b then b else a)"
681 lemma min_leastL: "(!!x. least <= x) ==> min least x = least"
682   by (simp add: min_def)
684 lemma min_of_mono:
685     "ALL x y. (f x <= f y) = (x <= y) ==> min (f m) (f n) = f (min m n)"
686   by (simp add: min_def)
688 lemma max_leastL: "(!!x. least <= x) ==> max least x = x"
689   by (simp add: max_def)
691 lemma max_of_mono:
692     "ALL x y. (f x <= f y) = (x <= y) ==> max (f m) (f n) = f (max m n)"
693   by (simp add: max_def)
696 subsubsection "Orders"
698 axclass order < ord
699   order_refl [iff]: "x <= x"
700   order_trans: "x <= y ==> y <= z ==> x <= z"
701   order_antisym: "x <= y ==> y <= x ==> x = y"
702   order_less_le: "(x < y) = (x <= y & x ~= y)"
705 text {* Reflexivity. *}
707 lemma order_eq_refl: "!!x::'a::order. x = y ==> x <= y"
708     -- {* This form is useful with the classical reasoner. *}
709   apply (erule ssubst)
710   apply (rule order_refl)
711   done
713 lemma order_less_irrefl [iff]: "~ x < (x::'a::order)"
714   by (simp add: order_less_le)
716 lemma order_le_less: "((x::'a::order) <= y) = (x < y | x = y)"
717     -- {* NOT suitable for iff, since it can cause PROOF FAILED. *}
718   apply (simp add: order_less_le, blast)
719   done
721 lemmas order_le_imp_less_or_eq = order_le_less [THEN iffD1, standard]
723 lemma order_less_imp_le: "!!x::'a::order. x < y ==> x <= y"
724   by (simp add: order_less_le)
727 text {* Asymmetry. *}
729 lemma order_less_not_sym: "(x::'a::order) < y ==> ~ (y < x)"
730   by (simp add: order_less_le order_antisym)
732 lemma order_less_asym: "x < (y::'a::order) ==> (~P ==> y < x) ==> P"
733   apply (drule order_less_not_sym)
734   apply (erule contrapos_np, simp)
735   done
737 lemma order_eq_iff: "!!x::'a::order. (x = y) = (x \<le> y & y \<le> x)"
738 by (blast intro: order_antisym)
741 text {* Transitivity. *}
743 lemma order_less_trans: "!!x::'a::order. [| x < y; y < z |] ==> x < z"
744   apply (simp add: order_less_le)
745   apply (blast intro: order_trans order_antisym)
746   done
748 lemma order_le_less_trans: "!!x::'a::order. [| x <= y; y < z |] ==> x < z"
749   apply (simp add: order_less_le)
750   apply (blast intro: order_trans order_antisym)
751   done
753 lemma order_less_le_trans: "!!x::'a::order. [| x < y; y <= z |] ==> x < z"
754   apply (simp add: order_less_le)
755   apply (blast intro: order_trans order_antisym)
756   done
759 text {* Useful for simplification, but too risky to include by default. *}
761 lemma order_less_imp_not_less: "(x::'a::order) < y ==>  (~ y < x) = True"
762   by (blast elim: order_less_asym)
764 lemma order_less_imp_triv: "(x::'a::order) < y ==>  (y < x --> P) = True"
765   by (blast elim: order_less_asym)
767 lemma order_less_imp_not_eq: "(x::'a::order) < y ==>  (x = y) = False"
768   by auto
770 lemma order_less_imp_not_eq2: "(x::'a::order) < y ==>  (y = x) = False"
771   by auto
774 text {* Other operators. *}
776 lemma min_leastR: "(!!x::'a::order. least <= x) ==> min x least = least"
777   apply (simp add: min_def)
778   apply (blast intro: order_antisym)
779   done
781 lemma max_leastR: "(!!x::'a::order. least <= x) ==> max x least = x"
782   apply (simp add: max_def)
783   apply (blast intro: order_antisym)
784   done
787 subsubsection {* Least value operator *}
789 constdefs
790   Least :: "('a::ord => bool) => 'a"               (binder "LEAST " 10)
791   "Least P == THE x. P x & (ALL y. P y --> x <= y)"
792     -- {* We can no longer use LeastM because the latter requires Hilbert-AC. *}
794 lemma LeastI2:
795   "[| P (x::'a::order);
796       !!y. P y ==> x <= y;
797       !!x. [| P x; ALL y. P y --> x \<le> y |] ==> Q x |]
798    ==> Q (Least P)"
799   apply (unfold Least_def)
800   apply (rule theI2)
801     apply (blast intro: order_antisym)+
802   done
804 lemma Least_equality:
805     "[| P (k::'a::order); !!x. P x ==> k <= x |] ==> (LEAST x. P x) = k"
806   apply (simp add: Least_def)
807   apply (rule the_equality)
808   apply (auto intro!: order_antisym)
809   done
812 subsubsection "Linear / total orders"
814 axclass linorder < order
815   linorder_linear: "x <= y | y <= x"
817 lemma linorder_less_linear: "!!x::'a::linorder. x<y | x=y | y<x"
818   apply (simp add: order_less_le)
819   apply (insert linorder_linear, blast)
820   done
822 lemma linorder_le_cases [case_names le ge]:
823     "((x::'a::linorder) \<le> y ==> P) ==> (y \<le> x ==> P) ==> P"
824   by (insert linorder_linear, blast)
826 lemma linorder_cases [case_names less equal greater]:
827     "((x::'a::linorder) < y ==> P) ==> (x = y ==> P) ==> (y < x ==> P) ==> P"
828   by (insert linorder_less_linear, blast)
830 lemma linorder_not_less: "!!x::'a::linorder. (~ x < y) = (y <= x)"
831   apply (simp add: order_less_le)
832   apply (insert linorder_linear)
833   apply (blast intro: order_antisym)
834   done
836 lemma linorder_not_le: "!!x::'a::linorder. (~ x <= y) = (y < x)"
837   apply (simp add: order_less_le)
838   apply (insert linorder_linear)
839   apply (blast intro: order_antisym)
840   done
842 lemma linorder_neq_iff: "!!x::'a::linorder. (x ~= y) = (x<y | y<x)"
843 by (cut_tac x = x and y = y in linorder_less_linear, auto)
845 lemma linorder_neqE: "x ~= (y::'a::linorder) ==> (x < y ==> R) ==> (y < x ==> R) ==> R"
846 by (simp add: linorder_neq_iff, blast)
849 subsubsection "Min and max on (linear) orders"
851 lemma min_same [simp]: "min (x::'a::order) x = x"
852   by (simp add: min_def)
854 lemma max_same [simp]: "max (x::'a::order) x = x"
855   by (simp add: max_def)
857 lemma le_max_iff_disj: "!!z::'a::linorder. (z <= max x y) = (z <= x | z <= y)"
858   apply (simp add: max_def)
859   apply (insert linorder_linear)
860   apply (blast intro: order_trans)
861   done
863 lemma le_maxI1: "(x::'a::linorder) <= max x y"
864   by (simp add: le_max_iff_disj)
866 lemma le_maxI2: "(y::'a::linorder) <= max x y"
867     -- {* CANNOT use with @{text "[intro!]"} because blast will give PROOF FAILED. *}
868   by (simp add: le_max_iff_disj)
870 lemma less_max_iff_disj: "!!z::'a::linorder. (z < max x y) = (z < x | z < y)"
871   apply (simp add: max_def order_le_less)
872   apply (insert linorder_less_linear)
873   apply (blast intro: order_less_trans)
874   done
876 lemma max_le_iff_conj [simp]:
877     "!!z::'a::linorder. (max x y <= z) = (x <= z & y <= z)"
878   apply (simp add: max_def)
879   apply (insert linorder_linear)
880   apply (blast intro: order_trans)
881   done
883 lemma max_less_iff_conj [simp]:
884     "!!z::'a::linorder. (max x y < z) = (x < z & y < z)"
885   apply (simp add: order_le_less max_def)
886   apply (insert linorder_less_linear)
887   apply (blast intro: order_less_trans)
888   done
890 lemma le_min_iff_conj [simp]:
891     "!!z::'a::linorder. (z <= min x y) = (z <= x & z <= y)"
892     -- {* @{text "[iff]"} screws up a @{text blast} in MiniML *}
893   apply (simp add: min_def)
894   apply (insert linorder_linear)
895   apply (blast intro: order_trans)
896   done
898 lemma min_less_iff_conj [simp]:
899     "!!z::'a::linorder. (z < min x y) = (z < x & z < y)"
900   apply (simp add: order_le_less min_def)
901   apply (insert linorder_less_linear)
902   apply (blast intro: order_less_trans)
903   done
905 lemma min_le_iff_disj: "!!z::'a::linorder. (min x y <= z) = (x <= z | y <= z)"
906   apply (simp add: min_def)
907   apply (insert linorder_linear)
908   apply (blast intro: order_trans)
909   done
911 lemma min_less_iff_disj: "!!z::'a::linorder. (min x y < z) = (x < z | y < z)"
912   apply (simp add: min_def order_le_less)
913   apply (insert linorder_less_linear)
914   apply (blast intro: order_less_trans)
915   done
917 lemma max_assoc: "!!x::'a::linorder. max (max x y) z = max x (max y z)"
919 apply(rule conjI)
920 apply(blast intro:order_trans)
922 apply(blast dest: order_less_trans order_le_less_trans)
923 done
925 lemma max_commute: "!!x::'a::linorder. max x y = max y x"
927 apply(rule conjI)
928 apply(blast intro:order_antisym)
930 apply(blast dest: order_less_trans)
931 done
933 lemmas max_ac = max_assoc max_commute
934                 mk_left_commute[of max,OF max_assoc max_commute]
936 lemma min_assoc: "!!x::'a::linorder. min (min x y) z = min x (min y z)"
938 apply(rule conjI)
939 apply(blast intro:order_trans)
941 apply(blast dest: order_less_trans order_le_less_trans)
942 done
944 lemma min_commute: "!!x::'a::linorder. min x y = min y x"
946 apply(rule conjI)
947 apply(blast intro:order_antisym)
949 apply(blast dest: order_less_trans)
950 done
952 lemmas min_ac = min_assoc min_commute
953                 mk_left_commute[of min,OF min_assoc min_commute]
955 lemma split_min:
956     "P (min (i::'a::linorder) j) = ((i <= j --> P(i)) & (~ i <= j --> P(j)))"
957   by (simp add: min_def)
959 lemma split_max:
960     "P (max (i::'a::linorder) j) = ((i <= j --> P(j)) & (~ i <= j --> P(i)))"
961   by (simp add: max_def)
964 subsubsection {* Transitivity rules for calculational reasoning *}
967 lemma order_neq_le_trans: "a ~= b ==> (a::'a::order) <= b ==> a < b"
968   by (simp add: order_less_le)
970 lemma order_le_neq_trans: "(a::'a::order) <= b ==> a ~= b ==> a < b"
971   by (simp add: order_less_le)
973 lemma order_less_asym': "(a::'a::order) < b ==> b < a ==> P"
974   by (rule order_less_asym)
977 subsubsection {* Setup of transitivity reasoner as Solver *}
979 lemma less_imp_neq: "[| (x::'a::order) < y |] ==> x ~= y"
980   by (erule contrapos_pn, erule subst, rule order_less_irrefl)
982 lemma eq_neq_eq_imp_neq: "[| x = a ; a ~= b; b = y |] ==> x ~= y"
983   by (erule subst, erule ssubst, assumption)
985 ML_setup {*
987 structure Trans_Tac = Trans_Tac_Fun (
988   struct
989     val less_reflE = thm "order_less_irrefl" RS thm "notE";
990     val le_refl = thm "order_refl";
991     val less_imp_le = thm "order_less_imp_le";
992     val not_lessI = thm "linorder_not_less" RS thm "iffD2";
993     val not_leI = thm "linorder_not_le" RS thm "iffD2";
994     val not_lessD = thm "linorder_not_less" RS thm "iffD1";
995     val not_leD = thm "linorder_not_le" RS thm "iffD1";
996     val eqI = thm "order_antisym";
997     val eqD1 = thm "order_eq_refl";
998     val eqD2 = thm "sym" RS thm "order_eq_refl";
999     val less_trans = thm "order_less_trans";
1000     val less_le_trans = thm "order_less_le_trans";
1001     val le_less_trans = thm "order_le_less_trans";
1002     val le_trans = thm "order_trans";
1003     val le_neq_trans = thm "order_le_neq_trans";
1004     val neq_le_trans = thm "order_neq_le_trans";
1005     val less_imp_neq = thm "less_imp_neq";
1006     val eq_neq_eq_imp_neq = thm "eq_neq_eq_imp_neq";
1008     fun decomp_gen sort sign (Trueprop \$ t) =
1009       let fun of_sort t = Sign.of_sort sign (type_of t, sort)
1010       fun dec (Const ("Not", _) \$ t) = (
1011               case dec t of
1012                 None => None
1013               | Some (t1, rel, t2) => Some (t1, "~" ^ rel, t2))
1014             | dec (Const ("op =",  _) \$ t1 \$ t2) =
1015                 if of_sort t1
1016                 then Some (t1, "=", t2)
1017                 else None
1018             | dec (Const ("op <=",  _) \$ t1 \$ t2) =
1019                 if of_sort t1
1020                 then Some (t1, "<=", t2)
1021                 else None
1022             | dec (Const ("op <",  _) \$ t1 \$ t2) =
1023                 if of_sort t1
1024                 then Some (t1, "<", t2)
1025                 else None
1026             | dec _ = None
1027       in dec t end;
1029     val decomp_part = decomp_gen ["HOL.order"];
1030     val decomp_lin = decomp_gen ["HOL.linorder"];
1032   end);  (* struct *)
1034 simpset_ref() := simpset ()
1035     addSolver (mk_solver "Trans_linear" (fn _ => Trans_Tac.linear_tac))
1036     addSolver (mk_solver "Trans_partial" (fn _ => Trans_Tac.partial_tac));
1037   (* Adding the transitivity reasoners also as safe solvers showed a slight
1038      speed up, but the reasoning strength appears to be not higher (at least
1039      no breaking of additional proofs in the entire HOL distribution, as
1040      of 5 March 2004, was observed). *)
1041 *}
1043 (* Optional methods
1045 method_setup trans_partial =
1046   {* Method.no_args (Method.SIMPLE_METHOD' HEADGOAL (trans_tac_partial)) *}
1047   {* simple transitivity reasoner *}
1048 method_setup trans_linear =
1049   {* Method.no_args (Method.SIMPLE_METHOD' HEADGOAL (trans_tac_linear)) *}
1050   {* simple transitivity reasoner *}
1051 *)
1053 (*
1054 declare order.order_refl [simp del] order_less_irrefl [simp del]
1055 *)
1057 subsubsection "Bounded quantifiers"
1059 syntax
1060   "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3ALL _<_./ _)"  [0, 0, 10] 10)
1061   "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3EX _<_./ _)"  [0, 0, 10] 10)
1062   "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3ALL _<=_./ _)" [0, 0, 10] 10)
1063   "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3EX _<=_./ _)" [0, 0, 10] 10)
1065 syntax (xsymbols)
1066   "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
1067   "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
1068   "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
1069   "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
1071 syntax (HOL)
1072   "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3! _<_./ _)"  [0, 0, 10] 10)
1073   "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3? _<_./ _)"  [0, 0, 10] 10)
1074   "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3! _<=_./ _)" [0, 0, 10] 10)
1075   "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3? _<=_./ _)" [0, 0, 10] 10)
1077 syntax (HTML output)
1078   "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
1079   "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
1080   "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
1081   "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
1083 translations
1084  "ALL x<y. P"   =>  "ALL x. x < y --> P"
1085  "EX x<y. P"    =>  "EX x. x < y  & P"
1086  "ALL x<=y. P"  =>  "ALL x. x <= y --> P"
1087  "EX x<=y. P"   =>  "EX x. x <= y & P"
1089 print_translation {*
1090 let
1091   fun all_tr' [Const ("_bound",_) \$ Free (v,_),
1092                Const("op -->",_) \$ (Const ("op <",_) \$ (Const ("_bound",_) \$ Free (v',_)) \$ n ) \$ P] =
1093   (if v=v' then Syntax.const "_lessAll" \$ Syntax.mark_bound v' \$ n \$ P else raise Match)
1095   | all_tr' [Const ("_bound",_) \$ Free (v,_),
1096                Const("op -->",_) \$ (Const ("op <=",_) \$ (Const ("_bound",_) \$ Free (v',_)) \$ n ) \$ P] =
1097   (if v=v' then Syntax.const "_leAll" \$ Syntax.mark_bound v' \$ n \$ P else raise Match);
1099   fun ex_tr' [Const ("_bound",_) \$ Free (v,_),
1100                Const("op &",_) \$ (Const ("op <",_) \$ (Const ("_bound",_) \$ Free (v',_)) \$ n ) \$ P] =
1101   (if v=v' then Syntax.const "_lessEx" \$ Syntax.mark_bound v' \$ n \$ P else raise Match)
1103   | ex_tr' [Const ("_bound",_) \$ Free (v,_),
1104                Const("op &",_) \$ (Const ("op <=",_) \$ (Const ("_bound",_) \$ Free (v',_)) \$ n ) \$ P] =
1105   (if v=v' then Syntax.const "_leEx" \$ Syntax.mark_bound v' \$ n \$ P else raise Match)
1106 in
1107 [("ALL ", all_tr'), ("EX ", ex_tr')]
1108 end
1109 *}
1111 end