src/HOL/HOL.thy
 author kleing Mon Jun 21 10:25:57 2004 +0200 (2004-06-21) changeset 14981 e73f8140af78 parent 14854 61bdf2ae4dc5 child 15079 2ef899e4526d permissions -rw-r--r--
Merged in license change from Isabelle2004
1 (*  Title:      HOL/HOL.thy
2     ID:         \$Id\$
3     Author:     Tobias Nipkow, Markus Wenzel, and Larry Paulson
4 *)
6 header {* The basis of Higher-Order Logic *}
8 theory HOL = CPure
9 files ("HOL_lemmas.ML") ("cladata.ML") ("blastdata.ML") ("simpdata.ML"):
12 subsection {* Primitive logic *}
14 subsubsection {* Core syntax *}
16 classes type
17 defaultsort type
19 global
21 typedecl bool
23 arities
24   bool :: type
25   fun :: (type, type) type
27 judgment
28   Trueprop      :: "bool => prop"                   ("(_)" 5)
30 consts
31   Not           :: "bool => bool"                   ("~ _"  40)
32   True          :: bool
33   False         :: bool
34   If            :: "[bool, 'a, 'a] => 'a"           ("(if (_)/ then (_)/ else (_))" 10)
35   arbitrary     :: 'a
37   The           :: "('a => bool) => 'a"
38   All           :: "('a => bool) => bool"           (binder "ALL " 10)
39   Ex            :: "('a => bool) => bool"           (binder "EX " 10)
40   Ex1           :: "('a => bool) => bool"           (binder "EX! " 10)
41   Let           :: "['a, 'a => 'b] => 'b"
43   "="           :: "['a, 'a] => bool"               (infixl 50)
44   &             :: "[bool, bool] => bool"           (infixr 35)
45   "|"           :: "[bool, bool] => bool"           (infixr 30)
46   -->           :: "[bool, bool] => bool"           (infixr 25)
48 local
51 subsubsection {* Additional concrete syntax *}
53 nonterminals
54   letbinds  letbind
55   case_syn  cases_syn
57 syntax
58   "_not_equal"  :: "['a, 'a] => bool"                    (infixl "~=" 50)
59   "_The"        :: "[pttrn, bool] => 'a"                 ("(3THE _./ _)" [0, 10] 10)
61   "_bind"       :: "[pttrn, 'a] => letbind"              ("(2_ =/ _)" 10)
62   ""            :: "letbind => letbinds"                 ("_")
63   "_binds"      :: "[letbind, letbinds] => letbinds"     ("_;/ _")
64   "_Let"        :: "[letbinds, 'a] => 'a"                ("(let (_)/ in (_))" 10)
66   "_case_syntax":: "['a, cases_syn] => 'b"               ("(case _ of/ _)" 10)
67   "_case1"      :: "['a, 'b] => case_syn"                ("(2_ =>/ _)" 10)
68   ""            :: "case_syn => cases_syn"               ("_")
69   "_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ | _")
71 translations
72   "x ~= y"                == "~ (x = y)"
73   "THE x. P"              == "The (%x. P)"
74   "_Let (_binds b bs) e"  == "_Let b (_Let bs e)"
75   "let x = a in e"        == "Let a (%x. e)"
77 print_translation {*
78 (* To avoid eta-contraction of body: *)
79 [("The", fn [Abs abs] =>
80      let val (x,t) = atomic_abs_tr' abs
81      in Syntax.const "_The" \$ x \$ t end)]
82 *}
84 syntax (output)
85   "="           :: "['a, 'a] => bool"                    (infix 50)
86   "_not_equal"  :: "['a, 'a] => bool"                    (infix "~=" 50)
88 syntax (xsymbols)
89   Not           :: "bool => bool"                        ("\<not> _"  40)
90   "op &"        :: "[bool, bool] => bool"                (infixr "\<and>" 35)
91   "op |"        :: "[bool, bool] => bool"                (infixr "\<or>" 30)
92   "op -->"      :: "[bool, bool] => bool"                (infixr "\<longrightarrow>" 25)
93   "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
94   "ALL "        :: "[idts, bool] => bool"                ("(3\<forall>_./ _)" [0, 10] 10)
95   "EX "         :: "[idts, bool] => bool"                ("(3\<exists>_./ _)" [0, 10] 10)
96   "EX! "        :: "[idts, bool] => bool"                ("(3\<exists>!_./ _)" [0, 10] 10)
97   "_case1"      :: "['a, 'b] => case_syn"                ("(2_ \<Rightarrow>/ _)" 10)
98 (*"_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ \<orelse> _")*)
100 syntax (xsymbols output)
101   "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
103 syntax (HTML output)
104   "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
105   Not           :: "bool => bool"                        ("\<not> _"  40)
106   "op &"        :: "[bool, bool] => bool"                (infixr "\<and>" 35)
107   "op |"        :: "[bool, bool] => bool"                (infixr "\<or>" 30)
108   "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
109   "ALL "        :: "[idts, bool] => bool"                ("(3\<forall>_./ _)" [0, 10] 10)
110   "EX "         :: "[idts, bool] => bool"                ("(3\<exists>_./ _)" [0, 10] 10)
111   "EX! "        :: "[idts, bool] => bool"                ("(3\<exists>!_./ _)" [0, 10] 10)
113 syntax (HOL)
114   "ALL "        :: "[idts, bool] => bool"                ("(3! _./ _)" [0, 10] 10)
115   "EX "         :: "[idts, bool] => bool"                ("(3? _./ _)" [0, 10] 10)
116   "EX! "        :: "[idts, bool] => bool"                ("(3?! _./ _)" [0, 10] 10)
119 subsubsection {* Axioms and basic definitions *}
121 axioms
122   eq_reflection: "(x=y) ==> (x==y)"
124   refl:         "t = (t::'a)"
125   subst:        "[| s = t; P(s) |] ==> P(t::'a)"
127   ext:          "(!!x::'a. (f x ::'b) = g x) ==> (%x. f x) = (%x. g x)"
128     -- {* Extensionality is built into the meta-logic, and this rule expresses *}
129     -- {* a related property.  It is an eta-expanded version of the traditional *}
130     -- {* rule, and similar to the ABS rule of HOL *}
132   the_eq_trivial: "(THE x. x = a) = (a::'a)"
134   impI:         "(P ==> Q) ==> P-->Q"
135   mp:           "[| P-->Q;  P |] ==> Q"
137 defs
138   True_def:     "True      == ((%x::bool. x) = (%x. x))"
139   All_def:      "All(P)    == (P = (%x. True))"
140   Ex_def:       "Ex(P)     == !Q. (!x. P x --> Q) --> Q"
141   False_def:    "False     == (!P. P)"
142   not_def:      "~ P       == P-->False"
143   and_def:      "P & Q     == !R. (P-->Q-->R) --> R"
144   or_def:       "P | Q     == !R. (P-->R) --> (Q-->R) --> R"
145   Ex1_def:      "Ex1(P)    == ? x. P(x) & (! y. P(y) --> y=x)"
147 axioms
148   iff:          "(P-->Q) --> (Q-->P) --> (P=Q)"
149   True_or_False:  "(P=True) | (P=False)"
151 defs
152   Let_def:      "Let s f == f(s)"
153   if_def:       "If P x y == THE z::'a. (P=True --> z=x) & (P=False --> z=y)"
155 finalconsts
156   "op ="
157   "op -->"
158   The
159   arbitrary
161 subsubsection {* Generic algebraic operations *}
163 axclass zero < type
164 axclass one < type
165 axclass plus < type
166 axclass minus < type
167 axclass times < type
168 axclass inverse < type
170 global
172 consts
173   "0"           :: "'a::zero"                       ("0")
174   "1"           :: "'a::one"                        ("1")
175   "+"           :: "['a::plus, 'a]  => 'a"          (infixl 65)
176   -             :: "['a::minus, 'a] => 'a"          (infixl 65)
177   uminus        :: "['a::minus] => 'a"              ("- _"  80)
178   *             :: "['a::times, 'a] => 'a"          (infixl 70)
180 syntax
181   "_index1"  :: index    ("\<^sub>1")
182 translations
183   (index) "\<^sub>1" => (index) "\<^bsub>\<struct>\<^esub>"
185 local
187 typed_print_translation {*
188   let
189     fun tr' c = (c, fn show_sorts => fn T => fn ts =>
190       if T = dummyT orelse not (! show_types) andalso can Term.dest_Type T then raise Match
191       else Syntax.const Syntax.constrainC \$ Syntax.const c \$ Syntax.term_of_typ show_sorts T);
192   in [tr' "0", tr' "1"] end;
193 *} -- {* show types that are presumably too general *}
196 consts
197   abs           :: "'a::minus => 'a"
198   inverse       :: "'a::inverse => 'a"
199   divide        :: "['a::inverse, 'a] => 'a"        (infixl "'/" 70)
201 syntax (xsymbols)
202   abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
203 syntax (HTML output)
204   abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
207 subsection {* Theory and package setup *}
209 subsubsection {* Basic lemmas *}
211 use "HOL_lemmas.ML"
212 theorems case_split = case_split_thm [case_names True False]
215 subsubsection {* Intuitionistic Reasoning *}
217 lemma impE':
218   assumes 1: "P --> Q"
219     and 2: "Q ==> R"
220     and 3: "P --> Q ==> P"
221   shows R
222 proof -
223   from 3 and 1 have P .
224   with 1 have Q by (rule impE)
225   with 2 show R .
226 qed
228 lemma allE':
229   assumes 1: "ALL x. P x"
230     and 2: "P x ==> ALL x. P x ==> Q"
231   shows Q
232 proof -
233   from 1 have "P x" by (rule spec)
234   from this and 1 show Q by (rule 2)
235 qed
237 lemma notE':
238   assumes 1: "~ P"
239     and 2: "~ P ==> P"
240   shows R
241 proof -
242   from 2 and 1 have P .
243   with 1 show R by (rule notE)
244 qed
246 lemmas [CPure.elim!] = disjE iffE FalseE conjE exE
247   and [CPure.intro!] = iffI conjI impI TrueI notI allI refl
248   and [CPure.elim 2] = allE notE' impE'
249   and [CPure.intro] = exI disjI2 disjI1
251 lemmas [trans] = trans
252   and [sym] = sym not_sym
253   and [CPure.elim?] = iffD1 iffD2 impE
256 subsubsection {* Atomizing meta-level connectives *}
258 lemma atomize_all [atomize]: "(!!x. P x) == Trueprop (ALL x. P x)"
259 proof
260   assume "!!x. P x"
261   show "ALL x. P x" by (rule allI)
262 next
263   assume "ALL x. P x"
264   thus "!!x. P x" by (rule allE)
265 qed
267 lemma atomize_imp [atomize]: "(A ==> B) == Trueprop (A --> B)"
268 proof
269   assume r: "A ==> B"
270   show "A --> B" by (rule impI) (rule r)
271 next
272   assume "A --> B" and A
273   thus B by (rule mp)
274 qed
276 lemma atomize_not: "(A ==> False) == Trueprop (~A)"
277 proof
278   assume r: "A ==> False"
279   show "~A" by (rule notI) (rule r)
280 next
281   assume "~A" and A
282   thus False by (rule notE)
283 qed
285 lemma atomize_eq [atomize]: "(x == y) == Trueprop (x = y)"
286 proof
287   assume "x == y"
288   show "x = y" by (unfold prems) (rule refl)
289 next
290   assume "x = y"
291   thus "x == y" by (rule eq_reflection)
292 qed
294 lemma atomize_conj [atomize]:
295   "(!!C. (A ==> B ==> PROP C) ==> PROP C) == Trueprop (A & B)"
296 proof
297   assume "!!C. (A ==> B ==> PROP C) ==> PROP C"
298   show "A & B" by (rule conjI)
299 next
300   fix C
301   assume "A & B"
302   assume "A ==> B ==> PROP C"
303   thus "PROP C"
304   proof this
305     show A by (rule conjunct1)
306     show B by (rule conjunct2)
307   qed
308 qed
310 lemmas [symmetric, rulify] = atomize_all atomize_imp
313 subsubsection {* Classical Reasoner setup *}
316 setup hypsubst_setup
318 ML_setup {*
319   Context.>> (ContextRules.addSWrapper (fn tac => hyp_subst_tac' ORELSE' tac));
320 *}
322 setup Classical.setup
323 setup clasetup
325 lemmas [intro?] = ext
326   and [elim?] = ex1_implies_ex
328 use "blastdata.ML"
329 setup Blast.setup
332 subsubsection {* Simplifier setup *}
334 lemma meta_eq_to_obj_eq: "x == y ==> x = y"
335 proof -
336   assume r: "x == y"
337   show "x = y" by (unfold r) (rule refl)
338 qed
340 lemma eta_contract_eq: "(%s. f s) = f" ..
342 lemma simp_thms:
343   shows not_not: "(~ ~ P) = P"
344   and
345     "(P ~= Q) = (P = (~Q))"
346     "(P | ~P) = True"    "(~P | P) = True"
347     "((~P) = (~Q)) = (P=Q)"
348     "(x = x) = True"
349     "(~True) = False"  "(~False) = True"
350     "(~P) ~= P"  "P ~= (~P)"
351     "(True=P) = P"  "(P=True) = P"  "(False=P) = (~P)"  "(P=False) = (~P)"
352     "(True --> P) = P"  "(False --> P) = True"
353     "(P --> True) = True"  "(P --> P) = True"
354     "(P --> False) = (~P)"  "(P --> ~P) = (~P)"
355     "(P & True) = P"  "(True & P) = P"
356     "(P & False) = False"  "(False & P) = False"
357     "(P & P) = P"  "(P & (P & Q)) = (P & Q)"
358     "(P & ~P) = False"    "(~P & P) = False"
359     "(P | True) = True"  "(True | P) = True"
360     "(P | False) = P"  "(False | P) = P"
361     "(P | P) = P"  "(P | (P | Q)) = (P | Q)" and
362     "(ALL x. P) = P"  "(EX x. P) = P"  "EX x. x=t"  "EX x. t=x"
363     -- {* needed for the one-point-rule quantifier simplification procs *}
364     -- {* essential for termination!! *} and
365     "!!P. (EX x. x=t & P(x)) = P(t)"
366     "!!P. (EX x. t=x & P(x)) = P(t)"
367     "!!P. (ALL x. x=t --> P(x)) = P(t)"
368     "!!P. (ALL x. t=x --> P(x)) = P(t)"
369   by (blast, blast, blast, blast, blast, rules+)
371 lemma imp_cong: "(P = P') ==> (P' ==> (Q = Q')) ==> ((P --> Q) = (P' --> Q'))"
372   by rules
374 lemma ex_simps:
375   "!!P Q. (EX x. P x & Q)   = ((EX x. P x) & Q)"
376   "!!P Q. (EX x. P & Q x)   = (P & (EX x. Q x))"
377   "!!P Q. (EX x. P x | Q)   = ((EX x. P x) | Q)"
378   "!!P Q. (EX x. P | Q x)   = (P | (EX x. Q x))"
379   "!!P Q. (EX x. P x --> Q) = ((ALL x. P x) --> Q)"
380   "!!P Q. (EX x. P --> Q x) = (P --> (EX x. Q x))"
381   -- {* Miniscoping: pushing in existential quantifiers. *}
382   by (rules | blast)+
384 lemma all_simps:
385   "!!P Q. (ALL x. P x & Q)   = ((ALL x. P x) & Q)"
386   "!!P Q. (ALL x. P & Q x)   = (P & (ALL x. Q x))"
387   "!!P Q. (ALL x. P x | Q)   = ((ALL x. P x) | Q)"
388   "!!P Q. (ALL x. P | Q x)   = (P | (ALL x. Q x))"
389   "!!P Q. (ALL x. P x --> Q) = ((EX x. P x) --> Q)"
390   "!!P Q. (ALL x. P --> Q x) = (P --> (ALL x. Q x))"
391   -- {* Miniscoping: pushing in universal quantifiers. *}
392   by (rules | blast)+
394 lemma disj_absorb: "(A | A) = A"
395   by blast
397 lemma disj_left_absorb: "(A | (A | B)) = (A | B)"
398   by blast
400 lemma conj_absorb: "(A & A) = A"
401   by blast
403 lemma conj_left_absorb: "(A & (A & B)) = (A & B)"
404   by blast
406 lemma eq_ac:
407   shows eq_commute: "(a=b) = (b=a)"
408     and eq_left_commute: "(P=(Q=R)) = (Q=(P=R))"
409     and eq_assoc: "((P=Q)=R) = (P=(Q=R))" by (rules, blast+)
410 lemma neq_commute: "(a~=b) = (b~=a)" by rules
412 lemma conj_comms:
413   shows conj_commute: "(P&Q) = (Q&P)"
414     and conj_left_commute: "(P&(Q&R)) = (Q&(P&R))" by rules+
415 lemma conj_assoc: "((P&Q)&R) = (P&(Q&R))" by rules
417 lemma disj_comms:
418   shows disj_commute: "(P|Q) = (Q|P)"
419     and disj_left_commute: "(P|(Q|R)) = (Q|(P|R))" by rules+
420 lemma disj_assoc: "((P|Q)|R) = (P|(Q|R))" by rules
422 lemma conj_disj_distribL: "(P&(Q|R)) = (P&Q | P&R)" by rules
423 lemma conj_disj_distribR: "((P|Q)&R) = (P&R | Q&R)" by rules
425 lemma disj_conj_distribL: "(P|(Q&R)) = ((P|Q) & (P|R))" by rules
426 lemma disj_conj_distribR: "((P&Q)|R) = ((P|R) & (Q|R))" by rules
428 lemma imp_conjR: "(P --> (Q&R)) = ((P-->Q) & (P-->R))" by rules
429 lemma imp_conjL: "((P&Q) -->R)  = (P --> (Q --> R))" by rules
430 lemma imp_disjL: "((P|Q) --> R) = ((P-->R)&(Q-->R))" by rules
432 text {* These two are specialized, but @{text imp_disj_not1} is useful in @{text "Auth/Yahalom"}. *}
433 lemma imp_disj_not1: "(P --> Q | R) = (~Q --> P --> R)" by blast
434 lemma imp_disj_not2: "(P --> Q | R) = (~R --> P --> Q)" by blast
436 lemma imp_disj1: "((P-->Q)|R) = (P--> Q|R)" by blast
437 lemma imp_disj2: "(Q|(P-->R)) = (P--> Q|R)" by blast
439 lemma de_Morgan_disj: "(~(P | Q)) = (~P & ~Q)" by rules
440 lemma de_Morgan_conj: "(~(P & Q)) = (~P | ~Q)" by blast
441 lemma not_imp: "(~(P --> Q)) = (P & ~Q)" by blast
442 lemma not_iff: "(P~=Q) = (P = (~Q))" by blast
443 lemma disj_not1: "(~P | Q) = (P --> Q)" by blast
444 lemma disj_not2: "(P | ~Q) = (Q --> P)"  -- {* changes orientation :-( *}
445   by blast
446 lemma imp_conv_disj: "(P --> Q) = ((~P) | Q)" by blast
448 lemma iff_conv_conj_imp: "(P = Q) = ((P --> Q) & (Q --> P))" by rules
451 lemma cases_simp: "((P --> Q) & (~P --> Q)) = Q"
452   -- {* Avoids duplication of subgoals after @{text split_if}, when the true and false *}
453   -- {* cases boil down to the same thing. *}
454   by blast
456 lemma not_all: "(~ (! x. P(x))) = (? x.~P(x))" by blast
457 lemma imp_all: "((! x. P x) --> Q) = (? x. P x --> Q)" by blast
458 lemma not_ex: "(~ (? x. P(x))) = (! x.~P(x))" by rules
459 lemma imp_ex: "((? x. P x) --> Q) = (! x. P x --> Q)" by rules
461 lemma ex_disj_distrib: "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))" by rules
462 lemma all_conj_distrib: "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))" by rules
464 text {*
465   \medskip The @{text "&"} congruence rule: not included by default!
466   May slow rewrite proofs down by as much as 50\% *}
468 lemma conj_cong:
469     "(P = P') ==> (P' ==> (Q = Q')) ==> ((P & Q) = (P' & Q'))"
470   by rules
472 lemma rev_conj_cong:
473     "(Q = Q') ==> (Q' ==> (P = P')) ==> ((P & Q) = (P' & Q'))"
474   by rules
476 text {* The @{text "|"} congruence rule: not included by default! *}
478 lemma disj_cong:
479     "(P = P') ==> (~P' ==> (Q = Q')) ==> ((P | Q) = (P' | Q'))"
480   by blast
482 lemma eq_sym_conv: "(x = y) = (y = x)"
483   by rules
486 text {* \medskip if-then-else rules *}
488 lemma if_True: "(if True then x else y) = x"
489   by (unfold if_def) blast
491 lemma if_False: "(if False then x else y) = y"
492   by (unfold if_def) blast
494 lemma if_P: "P ==> (if P then x else y) = x"
495   by (unfold if_def) blast
497 lemma if_not_P: "~P ==> (if P then x else y) = y"
498   by (unfold if_def) blast
500 lemma split_if: "P (if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))"
501   apply (rule case_split [of Q])
502    apply (subst if_P)
503     prefer 3 apply (subst if_not_P, blast+)
504   done
506 lemma split_if_asm: "P (if Q then x else y) = (~((Q & ~P x) | (~Q & ~P y)))"
507 by (subst split_if, blast)
509 lemmas if_splits = split_if split_if_asm
511 lemma if_def2: "(if Q then x else y) = ((Q --> x) & (~ Q --> y))"
512   by (rule split_if)
514 lemma if_cancel: "(if c then x else x) = x"
515 by (subst split_if, blast)
517 lemma if_eq_cancel: "(if x = y then y else x) = x"
518 by (subst split_if, blast)
520 lemma if_bool_eq_conj: "(if P then Q else R) = ((P-->Q) & (~P-->R))"
521   -- {* This form is useful for expanding @{text if}s on the RIGHT of the @{text "==>"} symbol. *}
522   by (rule split_if)
524 lemma if_bool_eq_disj: "(if P then Q else R) = ((P&Q) | (~P&R))"
525   -- {* And this form is useful for expanding @{text if}s on the LEFT. *}
526   apply (subst split_if, blast)
527   done
529 lemma Eq_TrueI: "P ==> P == True" by (unfold atomize_eq) rules
530 lemma Eq_FalseI: "~P ==> P == False" by (unfold atomize_eq) rules
532 subsubsection {* Actual Installation of the Simplifier *}
534 use "simpdata.ML"
535 setup Simplifier.setup
536 setup "Simplifier.method_setup Splitter.split_modifiers" setup simpsetup
537 setup Splitter.setup setup Clasimp.setup
539 declare disj_absorb [simp] conj_absorb [simp]
541 lemma ex1_eq[iff]: "EX! x. x = t" "EX! x. t = x"
542 by blast+
544 theorem choice_eq: "(ALL x. EX! y. P x y) = (EX! f. ALL x. P x (f x))"
545   apply (rule iffI)
546   apply (rule_tac a = "%x. THE y. P x y" in ex1I)
547   apply (fast dest!: theI')
548   apply (fast intro: ext the1_equality [symmetric])
549   apply (erule ex1E)
550   apply (rule allI)
551   apply (rule ex1I)
552   apply (erule spec)
553   apply (erule_tac x = "%z. if z = x then y else f z" in allE)
554   apply (erule impE)
555   apply (rule allI)
556   apply (rule_tac P = "xa = x" in case_split_thm)
557   apply (drule_tac  x = x in fun_cong, simp_all)
558   done
560 text{*Needs only HOL-lemmas:*}
561 lemma mk_left_commute:
562   assumes a: "\<And>x y z. f (f x y) z = f x (f y z)" and
563           c: "\<And>x y. f x y = f y x"
564   shows "f x (f y z) = f y (f x z)"
565 by(rule trans[OF trans[OF c a] arg_cong[OF c, of "f y"]])
568 subsubsection {* Generic cases and induction *}
570 constdefs
571   induct_forall :: "('a => bool) => bool"
572   "induct_forall P == \<forall>x. P x"
573   induct_implies :: "bool => bool => bool"
574   "induct_implies A B == A --> B"
575   induct_equal :: "'a => 'a => bool"
576   "induct_equal x y == x = y"
577   induct_conj :: "bool => bool => bool"
578   "induct_conj A B == A & B"
580 lemma induct_forall_eq: "(!!x. P x) == Trueprop (induct_forall (\<lambda>x. P x))"
581   by (simp only: atomize_all induct_forall_def)
583 lemma induct_implies_eq: "(A ==> B) == Trueprop (induct_implies A B)"
584   by (simp only: atomize_imp induct_implies_def)
586 lemma induct_equal_eq: "(x == y) == Trueprop (induct_equal x y)"
587   by (simp only: atomize_eq induct_equal_def)
589 lemma induct_forall_conj: "induct_forall (\<lambda>x. induct_conj (A x) (B x)) =
590     induct_conj (induct_forall A) (induct_forall B)"
591   by (unfold induct_forall_def induct_conj_def) rules
593 lemma induct_implies_conj: "induct_implies C (induct_conj A B) =
594     induct_conj (induct_implies C A) (induct_implies C B)"
595   by (unfold induct_implies_def induct_conj_def) rules
597 lemma induct_conj_curry: "(induct_conj A B ==> PROP C) == (A ==> B ==> PROP C)"
598 proof
599   assume r: "induct_conj A B ==> PROP C" and A B
600   show "PROP C" by (rule r) (simp! add: induct_conj_def)
601 next
602   assume r: "A ==> B ==> PROP C" and "induct_conj A B"
603   show "PROP C" by (rule r) (simp! add: induct_conj_def)+
604 qed
606 lemma induct_impliesI: "(A ==> B) ==> induct_implies A B"
607   by (simp add: induct_implies_def)
609 lemmas induct_atomize = atomize_conj induct_forall_eq induct_implies_eq induct_equal_eq
610 lemmas induct_rulify1 [symmetric, standard] = induct_forall_eq induct_implies_eq induct_equal_eq
611 lemmas induct_rulify2 = induct_forall_def induct_implies_def induct_equal_def induct_conj_def
612 lemmas induct_conj = induct_forall_conj induct_implies_conj induct_conj_curry
614 hide const induct_forall induct_implies induct_equal induct_conj
617 text {* Method setup. *}
619 ML {*
620   structure InductMethod = InductMethodFun
621   (struct
622     val dest_concls = HOLogic.dest_concls;
623     val cases_default = thm "case_split";
624     val local_impI = thm "induct_impliesI";
625     val conjI = thm "conjI";
626     val atomize = thms "induct_atomize";
627     val rulify1 = thms "induct_rulify1";
628     val rulify2 = thms "induct_rulify2";
629     val localize = [Thm.symmetric (thm "induct_implies_def")];
630   end);
631 *}
633 setup InductMethod.setup
636 subsection {* Order signatures and orders *}
638 axclass
639   ord < type
641 syntax
642   "op <"        :: "['a::ord, 'a] => bool"             ("op <")
643   "op <="       :: "['a::ord, 'a] => bool"             ("op <=")
645 global
647 consts
648   "op <"        :: "['a::ord, 'a] => bool"             ("(_/ < _)"  [50, 51] 50)
649   "op <="       :: "['a::ord, 'a] => bool"             ("(_/ <= _)" [50, 51] 50)
651 local
653 syntax (xsymbols)
654   "op <="       :: "['a::ord, 'a] => bool"             ("op \<le>")
655   "op <="       :: "['a::ord, 'a] => bool"             ("(_/ \<le> _)"  [50, 51] 50)
657 syntax (HTML output)
658   "op <="       :: "['a::ord, 'a] => bool"             ("op \<le>")
659   "op <="       :: "['a::ord, 'a] => bool"             ("(_/ \<le> _)"  [50, 51] 50)
662 lemma Not_eq_iff: "((~P) = (~Q)) = (P = Q)"
663 by blast
665 subsubsection {* Monotonicity *}
667 locale mono =
668   fixes f
669   assumes mono: "A <= B ==> f A <= f B"
671 lemmas monoI [intro?] = mono.intro
672   and monoD [dest?] = mono.mono
674 constdefs
675   min :: "['a::ord, 'a] => 'a"
676   "min a b == (if a <= b then a else b)"
677   max :: "['a::ord, 'a] => 'a"
678   "max a b == (if a <= b then b else a)"
680 lemma min_leastL: "(!!x. least <= x) ==> min least x = least"
681   by (simp add: min_def)
683 lemma min_of_mono:
684     "ALL x y. (f x <= f y) = (x <= y) ==> min (f m) (f n) = f (min m n)"
685   by (simp add: min_def)
687 lemma max_leastL: "(!!x. least <= x) ==> max least x = x"
688   by (simp add: max_def)
690 lemma max_of_mono:
691     "ALL x y. (f x <= f y) = (x <= y) ==> max (f m) (f n) = f (max m n)"
692   by (simp add: max_def)
695 subsubsection "Orders"
697 axclass order < ord
698   order_refl [iff]: "x <= x"
699   order_trans: "x <= y ==> y <= z ==> x <= z"
700   order_antisym: "x <= y ==> y <= x ==> x = y"
701   order_less_le: "(x < y) = (x <= y & x ~= y)"
704 text {* Reflexivity. *}
706 lemma order_eq_refl: "!!x::'a::order. x = y ==> x <= y"
707     -- {* This form is useful with the classical reasoner. *}
708   apply (erule ssubst)
709   apply (rule order_refl)
710   done
712 lemma order_less_irrefl [iff]: "~ x < (x::'a::order)"
713   by (simp add: order_less_le)
715 lemma order_le_less: "((x::'a::order) <= y) = (x < y | x = y)"
716     -- {* NOT suitable for iff, since it can cause PROOF FAILED. *}
717   apply (simp add: order_less_le, blast)
718   done
720 lemmas order_le_imp_less_or_eq = order_le_less [THEN iffD1, standard]
722 lemma order_less_imp_le: "!!x::'a::order. x < y ==> x <= y"
723   by (simp add: order_less_le)
726 text {* Asymmetry. *}
728 lemma order_less_not_sym: "(x::'a::order) < y ==> ~ (y < x)"
729   by (simp add: order_less_le order_antisym)
731 lemma order_less_asym: "x < (y::'a::order) ==> (~P ==> y < x) ==> P"
732   apply (drule order_less_not_sym)
733   apply (erule contrapos_np, simp)
734   done
736 lemma order_eq_iff: "!!x::'a::order. (x = y) = (x \<le> y & y \<le> x)"
737 by (blast intro: order_antisym)
740 text {* Transitivity. *}
742 lemma order_less_trans: "!!x::'a::order. [| x < y; y < z |] ==> x < z"
743   apply (simp add: order_less_le)
744   apply (blast intro: order_trans order_antisym)
745   done
747 lemma order_le_less_trans: "!!x::'a::order. [| x <= y; y < z |] ==> x < z"
748   apply (simp add: order_less_le)
749   apply (blast intro: order_trans order_antisym)
750   done
752 lemma order_less_le_trans: "!!x::'a::order. [| x < y; y <= z |] ==> x < z"
753   apply (simp add: order_less_le)
754   apply (blast intro: order_trans order_antisym)
755   done
758 text {* Useful for simplification, but too risky to include by default. *}
760 lemma order_less_imp_not_less: "(x::'a::order) < y ==>  (~ y < x) = True"
761   by (blast elim: order_less_asym)
763 lemma order_less_imp_triv: "(x::'a::order) < y ==>  (y < x --> P) = True"
764   by (blast elim: order_less_asym)
766 lemma order_less_imp_not_eq: "(x::'a::order) < y ==>  (x = y) = False"
767   by auto
769 lemma order_less_imp_not_eq2: "(x::'a::order) < y ==>  (y = x) = False"
770   by auto
773 text {* Other operators. *}
775 lemma min_leastR: "(!!x::'a::order. least <= x) ==> min x least = least"
776   apply (simp add: min_def)
777   apply (blast intro: order_antisym)
778   done
780 lemma max_leastR: "(!!x::'a::order. least <= x) ==> max x least = x"
781   apply (simp add: max_def)
782   apply (blast intro: order_antisym)
783   done
786 subsubsection {* Least value operator *}
788 constdefs
789   Least :: "('a::ord => bool) => 'a"               (binder "LEAST " 10)
790   "Least P == THE x. P x & (ALL y. P y --> x <= y)"
791     -- {* We can no longer use LeastM because the latter requires Hilbert-AC. *}
793 lemma LeastI2:
794   "[| P (x::'a::order);
795       !!y. P y ==> x <= y;
796       !!x. [| P x; ALL y. P y --> x \<le> y |] ==> Q x |]
797    ==> Q (Least P)"
798   apply (unfold Least_def)
799   apply (rule theI2)
800     apply (blast intro: order_antisym)+
801   done
803 lemma Least_equality:
804     "[| P (k::'a::order); !!x. P x ==> k <= x |] ==> (LEAST x. P x) = k"
805   apply (simp add: Least_def)
806   apply (rule the_equality)
807   apply (auto intro!: order_antisym)
808   done
811 subsubsection "Linear / total orders"
813 axclass linorder < order
814   linorder_linear: "x <= y | y <= x"
816 lemma linorder_less_linear: "!!x::'a::linorder. x<y | x=y | y<x"
817   apply (simp add: order_less_le)
818   apply (insert linorder_linear, blast)
819   done
821 lemma linorder_le_cases [case_names le ge]:
822     "((x::'a::linorder) \<le> y ==> P) ==> (y \<le> x ==> P) ==> P"
823   by (insert linorder_linear, blast)
825 lemma linorder_cases [case_names less equal greater]:
826     "((x::'a::linorder) < y ==> P) ==> (x = y ==> P) ==> (y < x ==> P) ==> P"
827   by (insert linorder_less_linear, blast)
829 lemma linorder_not_less: "!!x::'a::linorder. (~ x < y) = (y <= x)"
830   apply (simp add: order_less_le)
831   apply (insert linorder_linear)
832   apply (blast intro: order_antisym)
833   done
835 lemma linorder_not_le: "!!x::'a::linorder. (~ x <= y) = (y < x)"
836   apply (simp add: order_less_le)
837   apply (insert linorder_linear)
838   apply (blast intro: order_antisym)
839   done
841 lemma linorder_neq_iff: "!!x::'a::linorder. (x ~= y) = (x<y | y<x)"
842 by (cut_tac x = x and y = y in linorder_less_linear, auto)
844 lemma linorder_neqE: "x ~= (y::'a::linorder) ==> (x < y ==> R) ==> (y < x ==> R) ==> R"
845 by (simp add: linorder_neq_iff, blast)
848 subsubsection "Min and max on (linear) orders"
850 lemma min_same [simp]: "min (x::'a::order) x = x"
851   by (simp add: min_def)
853 lemma max_same [simp]: "max (x::'a::order) x = x"
854   by (simp add: max_def)
856 lemma le_max_iff_disj: "!!z::'a::linorder. (z <= max x y) = (z <= x | z <= y)"
857   apply (simp add: max_def)
858   apply (insert linorder_linear)
859   apply (blast intro: order_trans)
860   done
862 lemma le_maxI1: "(x::'a::linorder) <= max x y"
863   by (simp add: le_max_iff_disj)
865 lemma le_maxI2: "(y::'a::linorder) <= max x y"
866     -- {* CANNOT use with @{text "[intro!]"} because blast will give PROOF FAILED. *}
867   by (simp add: le_max_iff_disj)
869 lemma less_max_iff_disj: "!!z::'a::linorder. (z < max x y) = (z < x | z < y)"
870   apply (simp add: max_def order_le_less)
871   apply (insert linorder_less_linear)
872   apply (blast intro: order_less_trans)
873   done
875 lemma max_le_iff_conj [simp]:
876     "!!z::'a::linorder. (max x y <= z) = (x <= z & y <= z)"
877   apply (simp add: max_def)
878   apply (insert linorder_linear)
879   apply (blast intro: order_trans)
880   done
882 lemma max_less_iff_conj [simp]:
883     "!!z::'a::linorder. (max x y < z) = (x < z & y < z)"
884   apply (simp add: order_le_less max_def)
885   apply (insert linorder_less_linear)
886   apply (blast intro: order_less_trans)
887   done
889 lemma le_min_iff_conj [simp]:
890     "!!z::'a::linorder. (z <= min x y) = (z <= x & z <= y)"
891     -- {* @{text "[iff]"} screws up a @{text blast} in MiniML *}
892   apply (simp add: min_def)
893   apply (insert linorder_linear)
894   apply (blast intro: order_trans)
895   done
897 lemma min_less_iff_conj [simp]:
898     "!!z::'a::linorder. (z < min x y) = (z < x & z < y)"
899   apply (simp add: order_le_less min_def)
900   apply (insert linorder_less_linear)
901   apply (blast intro: order_less_trans)
902   done
904 lemma min_le_iff_disj: "!!z::'a::linorder. (min x y <= z) = (x <= z | y <= z)"
905   apply (simp add: min_def)
906   apply (insert linorder_linear)
907   apply (blast intro: order_trans)
908   done
910 lemma min_less_iff_disj: "!!z::'a::linorder. (min x y < z) = (x < z | y < z)"
911   apply (simp add: min_def order_le_less)
912   apply (insert linorder_less_linear)
913   apply (blast intro: order_less_trans)
914   done
916 lemma max_assoc: "!!x::'a::linorder. max (max x y) z = max x (max y z)"
918 apply(rule conjI)
919 apply(blast intro:order_trans)
921 apply(blast dest: order_less_trans order_le_less_trans)
922 done
924 lemma max_commute: "!!x::'a::linorder. max x y = max y x"
926 apply(rule conjI)
927 apply(blast intro:order_antisym)
929 apply(blast dest: order_less_trans)
930 done
932 lemmas max_ac = max_assoc max_commute
933                 mk_left_commute[of max,OF max_assoc max_commute]
935 lemma min_assoc: "!!x::'a::linorder. min (min x y) z = min x (min y z)"
937 apply(rule conjI)
938 apply(blast intro:order_trans)
940 apply(blast dest: order_less_trans order_le_less_trans)
941 done
943 lemma min_commute: "!!x::'a::linorder. min x y = min y x"
945 apply(rule conjI)
946 apply(blast intro:order_antisym)
948 apply(blast dest: order_less_trans)
949 done
951 lemmas min_ac = min_assoc min_commute
952                 mk_left_commute[of min,OF min_assoc min_commute]
954 lemma split_min:
955     "P (min (i::'a::linorder) j) = ((i <= j --> P(i)) & (~ i <= j --> P(j)))"
956   by (simp add: min_def)
958 lemma split_max:
959     "P (max (i::'a::linorder) j) = ((i <= j --> P(j)) & (~ i <= j --> P(i)))"
960   by (simp add: max_def)
963 subsubsection {* Transitivity rules for calculational reasoning *}
966 lemma order_neq_le_trans: "a ~= b ==> (a::'a::order) <= b ==> a < b"
967   by (simp add: order_less_le)
969 lemma order_le_neq_trans: "(a::'a::order) <= b ==> a ~= b ==> a < b"
970   by (simp add: order_less_le)
972 lemma order_less_asym': "(a::'a::order) < b ==> b < a ==> P"
973   by (rule order_less_asym)
976 subsubsection {* Setup of transitivity reasoner as Solver *}
978 lemma less_imp_neq: "[| (x::'a::order) < y |] ==> x ~= y"
979   by (erule contrapos_pn, erule subst, rule order_less_irrefl)
981 lemma eq_neq_eq_imp_neq: "[| x = a ; a ~= b; b = y |] ==> x ~= y"
982   by (erule subst, erule ssubst, assumption)
984 ML_setup {*
986 structure Trans_Tac = Trans_Tac_Fun (
987   struct
988     val less_reflE = thm "order_less_irrefl" RS thm "notE";
989     val le_refl = thm "order_refl";
990     val less_imp_le = thm "order_less_imp_le";
991     val not_lessI = thm "linorder_not_less" RS thm "iffD2";
992     val not_leI = thm "linorder_not_le" RS thm "iffD2";
993     val not_lessD = thm "linorder_not_less" RS thm "iffD1";
994     val not_leD = thm "linorder_not_le" RS thm "iffD1";
995     val eqI = thm "order_antisym";
996     val eqD1 = thm "order_eq_refl";
997     val eqD2 = thm "sym" RS thm "order_eq_refl";
998     val less_trans = thm "order_less_trans";
999     val less_le_trans = thm "order_less_le_trans";
1000     val le_less_trans = thm "order_le_less_trans";
1001     val le_trans = thm "order_trans";
1002     val le_neq_trans = thm "order_le_neq_trans";
1003     val neq_le_trans = thm "order_neq_le_trans";
1004     val less_imp_neq = thm "less_imp_neq";
1005     val eq_neq_eq_imp_neq = thm "eq_neq_eq_imp_neq";
1007     fun decomp_gen sort sign (Trueprop \$ t) =
1008       let fun of_sort t = Sign.of_sort sign (type_of t, sort)
1009       fun dec (Const ("Not", _) \$ t) = (
1010               case dec t of
1011                 None => None
1012               | Some (t1, rel, t2) => Some (t1, "~" ^ rel, t2))
1013             | dec (Const ("op =",  _) \$ t1 \$ t2) =
1014                 if of_sort t1
1015                 then Some (t1, "=", t2)
1016                 else None
1017             | dec (Const ("op <=",  _) \$ t1 \$ t2) =
1018                 if of_sort t1
1019                 then Some (t1, "<=", t2)
1020                 else None
1021             | dec (Const ("op <",  _) \$ t1 \$ t2) =
1022                 if of_sort t1
1023                 then Some (t1, "<", t2)
1024                 else None
1025             | dec _ = None
1026       in dec t end;
1028     val decomp_part = decomp_gen ["HOL.order"];
1029     val decomp_lin = decomp_gen ["HOL.linorder"];
1031   end);  (* struct *)
1033 simpset_ref() := simpset ()
1034     addSolver (mk_solver "Trans_linear" (fn _ => Trans_Tac.linear_tac))
1035     addSolver (mk_solver "Trans_partial" (fn _ => Trans_Tac.partial_tac));
1036   (* Adding the transitivity reasoners also as safe solvers showed a slight
1037      speed up, but the reasoning strength appears to be not higher (at least
1038      no breaking of additional proofs in the entire HOL distribution, as
1039      of 5 March 2004, was observed). *)
1040 *}
1042 (* Optional methods
1044 method_setup trans_partial =
1045   {* Method.no_args (Method.SIMPLE_METHOD' HEADGOAL (trans_tac_partial)) *}
1046   {* simple transitivity reasoner *}
1047 method_setup trans_linear =
1048   {* Method.no_args (Method.SIMPLE_METHOD' HEADGOAL (trans_tac_linear)) *}
1049   {* simple transitivity reasoner *}
1050 *)
1052 (*
1053 declare order.order_refl [simp del] order_less_irrefl [simp del]
1054 *)
1056 subsubsection "Bounded quantifiers"
1058 syntax
1059   "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3ALL _<_./ _)"  [0, 0, 10] 10)
1060   "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3EX _<_./ _)"  [0, 0, 10] 10)
1061   "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3ALL _<=_./ _)" [0, 0, 10] 10)
1062   "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3EX _<=_./ _)" [0, 0, 10] 10)
1064 syntax (xsymbols)
1065   "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
1066   "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
1067   "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
1068   "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
1070 syntax (HOL)
1071   "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3! _<_./ _)"  [0, 0, 10] 10)
1072   "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3? _<_./ _)"  [0, 0, 10] 10)
1073   "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3! _<=_./ _)" [0, 0, 10] 10)
1074   "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3? _<=_./ _)" [0, 0, 10] 10)
1076 syntax (HTML output)
1077   "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
1078   "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
1079   "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
1080   "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
1082 translations
1083  "ALL x<y. P"   =>  "ALL x. x < y --> P"
1084  "EX x<y. P"    =>  "EX x. x < y  & P"
1085  "ALL x<=y. P"  =>  "ALL x. x <= y --> P"
1086  "EX x<=y. P"   =>  "EX x. x <= y & P"
1088 print_translation {*
1089 let
1090   fun all_tr' [Const ("_bound",_) \$ Free (v,_),
1091                Const("op -->",_) \$ (Const ("op <",_) \$ (Const ("_bound",_) \$ Free (v',_)) \$ n ) \$ P] =
1092   (if v=v' then Syntax.const "_lessAll" \$ Syntax.mark_bound v' \$ n \$ P else raise Match)
1094   | all_tr' [Const ("_bound",_) \$ Free (v,_),
1095                Const("op -->",_) \$ (Const ("op <=",_) \$ (Const ("_bound",_) \$ Free (v',_)) \$ n ) \$ P] =
1096   (if v=v' then Syntax.const "_leAll" \$ Syntax.mark_bound v' \$ n \$ P else raise Match);
1098   fun ex_tr' [Const ("_bound",_) \$ Free (v,_),
1099                Const("op &",_) \$ (Const ("op <",_) \$ (Const ("_bound",_) \$ Free (v',_)) \$ n ) \$ P] =
1100   (if v=v' then Syntax.const "_lessEx" \$ Syntax.mark_bound v' \$ n \$ P else raise Match)
1102   | ex_tr' [Const ("_bound",_) \$ Free (v,_),
1103                Const("op &",_) \$ (Const ("op <=",_) \$ (Const ("_bound",_) \$ Free (v',_)) \$ n ) \$ P] =
1104   (if v=v' then Syntax.const "_leEx" \$ Syntax.mark_bound v' \$ n \$ P else raise Match)
1105 in
1106 [("ALL ", all_tr'), ("EX ", ex_tr')]
1107 end
1108 *}
1110 end