src/HOL/HOL.thy
 author paulson Tue Dec 07 16:15:05 2004 +0100 (2004-12-07) changeset 15380 455cfa766dad parent 15363 885a40edcdba child 15411 1d195de59497 permissions -rw-r--r--
proof of subst by S Merz
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
9 imports CPure
10 files ("HOL_lemmas.ML") ("cladata.ML") ("blastdata.ML") ("simpdata.ML")
11       ("antisym_setup.ML")
12 begin
14 subsection {* Primitive logic *}
16 subsubsection {* Core syntax *}
18 classes type
19 defaultsort type
21 global
23 typedecl bool
25 arities
26   bool :: type
27   fun :: (type, type) type
29 judgment
30   Trueprop      :: "bool => prop"                   ("(_)" 5)
32 consts
33   Not           :: "bool => bool"                   ("~ _"  40)
34   True          :: bool
35   False         :: bool
36   If            :: "[bool, 'a, 'a] => 'a"           ("(if (_)/ then (_)/ else (_))" 10)
37   arbitrary     :: 'a
39   The           :: "('a => bool) => 'a"
40   All           :: "('a => bool) => bool"           (binder "ALL " 10)
41   Ex            :: "('a => bool) => bool"           (binder "EX " 10)
42   Ex1           :: "('a => bool) => bool"           (binder "EX! " 10)
43   Let           :: "['a, 'a => 'b] => 'b"
45   "="           :: "['a, 'a] => bool"               (infixl 50)
46   &             :: "[bool, bool] => bool"           (infixr 35)
47   "|"           :: "[bool, bool] => bool"           (infixr 30)
48   -->           :: "[bool, bool] => bool"           (infixr 25)
50 local
53 subsubsection {* Additional concrete syntax *}
55 nonterminals
56   letbinds  letbind
57   case_syn  cases_syn
59 syntax
60   "_not_equal"  :: "['a, 'a] => bool"                    (infixl "~=" 50)
61   "_The"        :: "[pttrn, bool] => 'a"                 ("(3THE _./ _)" [0, 10] 10)
63   "_bind"       :: "[pttrn, 'a] => letbind"              ("(2_ =/ _)" 10)
64   ""            :: "letbind => letbinds"                 ("_")
65   "_binds"      :: "[letbind, letbinds] => letbinds"     ("_;/ _")
66   "_Let"        :: "[letbinds, 'a] => 'a"                ("(let (_)/ in (_))" 10)
68   "_case_syntax":: "['a, cases_syn] => 'b"               ("(case _ of/ _)" 10)
69   "_case1"      :: "['a, 'b] => case_syn"                ("(2_ =>/ _)" 10)
70   ""            :: "case_syn => cases_syn"               ("_")
71   "_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ | _")
73 translations
74   "x ~= y"                == "~ (x = y)"
75   "THE x. P"              == "The (%x. P)"
76   "_Let (_binds b bs) e"  == "_Let b (_Let bs e)"
77   "let x = a in e"        == "Let a (%x. e)"
79 print_translation {*
80 (* To avoid eta-contraction of body: *)
81 [("The", fn [Abs abs] =>
82      let val (x,t) = atomic_abs_tr' abs
83      in Syntax.const "_The" \$ x \$ t end)]
84 *}
86 syntax (output)
87   "="           :: "['a, 'a] => bool"                    (infix 50)
88   "_not_equal"  :: "['a, 'a] => bool"                    (infix "~=" 50)
90 syntax (xsymbols)
91   Not           :: "bool => bool"                        ("\<not> _"  40)
92   "op &"        :: "[bool, bool] => bool"                (infixr "\<and>" 35)
93   "op |"        :: "[bool, bool] => bool"                (infixr "\<or>" 30)
94   "op -->"      :: "[bool, bool] => bool"                (infixr "\<longrightarrow>" 25)
95   "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
96   "ALL "        :: "[idts, bool] => bool"                ("(3\<forall>_./ _)" [0, 10] 10)
97   "EX "         :: "[idts, bool] => bool"                ("(3\<exists>_./ _)" [0, 10] 10)
98   "EX! "        :: "[idts, bool] => bool"                ("(3\<exists>!_./ _)" [0, 10] 10)
99   "_case1"      :: "['a, 'b] => case_syn"                ("(2_ \<Rightarrow>/ _)" 10)
100 (*"_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ \<orelse> _")*)
102 syntax (xsymbols output)
103   "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
105 syntax (HTML output)
106   "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
107   Not           :: "bool => bool"                        ("\<not> _"  40)
108   "op &"        :: "[bool, bool] => bool"                (infixr "\<and>" 35)
109   "op |"        :: "[bool, bool] => bool"                (infixr "\<or>" 30)
110   "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
111   "ALL "        :: "[idts, bool] => bool"                ("(3\<forall>_./ _)" [0, 10] 10)
112   "EX "         :: "[idts, bool] => bool"                ("(3\<exists>_./ _)" [0, 10] 10)
113   "EX! "        :: "[idts, bool] => bool"                ("(3\<exists>!_./ _)" [0, 10] 10)
115 syntax (HOL)
116   "ALL "        :: "[idts, bool] => bool"                ("(3! _./ _)" [0, 10] 10)
117   "EX "         :: "[idts, bool] => bool"                ("(3? _./ _)" [0, 10] 10)
118   "EX! "        :: "[idts, bool] => bool"                ("(3?! _./ _)" [0, 10] 10)
121 subsubsection {* Axioms and basic definitions *}
123 axioms
124   eq_reflection:  "(x=y) ==> (x==y)"
126   refl:           "t = (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"
139 text{*Thanks to Stephan Merz*}
140 theorem subst:
141   assumes eq: "s = t" and p: "P(s)"
142   shows "P(t::'a)"
143 proof -
144   from eq have meta: "s \<equiv> t"
145     by (rule eq_reflection)
146   from p show ?thesis
147     by (unfold meta)
148 qed
150 defs
151   True_def:     "True      == ((%x::bool. x) = (%x. x))"
152   All_def:      "All(P)    == (P = (%x. True))"
153   Ex_def:       "Ex(P)     == !Q. (!x. P x --> Q) --> Q"
154   False_def:    "False     == (!P. P)"
155   not_def:      "~ P       == P-->False"
156   and_def:      "P & Q     == !R. (P-->Q-->R) --> R"
157   or_def:       "P | Q     == !R. (P-->R) --> (Q-->R) --> R"
158   Ex1_def:      "Ex1(P)    == ? x. P(x) & (! y. P(y) --> y=x)"
160 axioms
161   iff:          "(P-->Q) --> (Q-->P) --> (P=Q)"
162   True_or_False:  "(P=True) | (P=False)"
164 defs
165   Let_def:      "Let s f == f(s)"
166   if_def:       "If P x y == THE z::'a. (P=True --> z=x) & (P=False --> z=y)"
168 finalconsts
169   "op ="
170   "op -->"
171   The
172   arbitrary
174 subsubsection {* Generic algebraic operations *}
176 axclass zero < type
177 axclass one < type
178 axclass plus < type
179 axclass minus < type
180 axclass times < type
181 axclass inverse < type
183 global
185 consts
186   "0"           :: "'a::zero"                       ("0")
187   "1"           :: "'a::one"                        ("1")
188   "+"           :: "['a::plus, 'a]  => 'a"          (infixl 65)
189   -             :: "['a::minus, 'a] => 'a"          (infixl 65)
190   uminus        :: "['a::minus] => 'a"              ("- _"  80)
191   *             :: "['a::times, 'a] => 'a"          (infixl 70)
193 syntax
194   "_index1"  :: index    ("\<^sub>1")
195 translations
196   (index) "\<^sub>1" => (index) "\<^bsub>\<struct>\<^esub>"
198 local
200 typed_print_translation {*
201   let
202     fun tr' c = (c, fn show_sorts => fn T => fn ts =>
203       if T = dummyT orelse not (! show_types) andalso can Term.dest_Type T then raise Match
204       else Syntax.const Syntax.constrainC \$ Syntax.const c \$ Syntax.term_of_typ show_sorts T);
205   in [tr' "0", tr' "1"] end;
206 *} -- {* show types that are presumably too general *}
209 consts
210   abs           :: "'a::minus => 'a"
211   inverse       :: "'a::inverse => 'a"
212   divide        :: "['a::inverse, 'a] => 'a"        (infixl "'/" 70)
214 syntax (xsymbols)
215   abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
216 syntax (HTML output)
217   abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
220 subsection {* Theory and package setup *}
222 subsubsection {* Basic lemmas *}
224 use "HOL_lemmas.ML"
225 theorems case_split = case_split_thm [case_names True False]
228 subsubsection {* Intuitionistic Reasoning *}
230 lemma impE':
231   assumes 1: "P --> Q"
232     and 2: "Q ==> R"
233     and 3: "P --> Q ==> P"
234   shows R
235 proof -
236   from 3 and 1 have P .
237   with 1 have Q by (rule impE)
238   with 2 show R .
239 qed
241 lemma allE':
242   assumes 1: "ALL x. P x"
243     and 2: "P x ==> ALL x. P x ==> Q"
244   shows Q
245 proof -
246   from 1 have "P x" by (rule spec)
247   from this and 1 show Q by (rule 2)
248 qed
250 lemma notE':
251   assumes 1: "~ P"
252     and 2: "~ P ==> P"
253   shows R
254 proof -
255   from 2 and 1 have P .
256   with 1 show R by (rule notE)
257 qed
259 lemmas [CPure.elim!] = disjE iffE FalseE conjE exE
260   and [CPure.intro!] = iffI conjI impI TrueI notI allI refl
261   and [CPure.elim 2] = allE notE' impE'
262   and [CPure.intro] = exI disjI2 disjI1
264 lemmas [trans] = trans
265   and [sym] = sym not_sym
266   and [CPure.elim?] = iffD1 iffD2 impE
269 subsubsection {* Atomizing meta-level connectives *}
271 lemma atomize_all [atomize]: "(!!x. P x) == Trueprop (ALL x. P x)"
272 proof
273   assume "!!x. P x"
274   show "ALL x. P x" by (rule allI)
275 next
276   assume "ALL x. P x"
277   thus "!!x. P x" by (rule allE)
278 qed
280 lemma atomize_imp [atomize]: "(A ==> B) == Trueprop (A --> B)"
281 proof
282   assume r: "A ==> B"
283   show "A --> B" by (rule impI) (rule r)
284 next
285   assume "A --> B" and A
286   thus B by (rule mp)
287 qed
289 lemma atomize_not: "(A ==> False) == Trueprop (~A)"
290 proof
291   assume r: "A ==> False"
292   show "~A" by (rule notI) (rule r)
293 next
294   assume "~A" and A
295   thus False by (rule notE)
296 qed
298 lemma atomize_eq [atomize]: "(x == y) == Trueprop (x = y)"
299 proof
300   assume "x == y"
301   show "x = y" by (unfold prems) (rule refl)
302 next
303   assume "x = y"
304   thus "x == y" by (rule eq_reflection)
305 qed
307 lemma atomize_conj [atomize]:
308   "(!!C. (A ==> B ==> PROP C) ==> PROP C) == Trueprop (A & B)"
309 proof
310   assume "!!C. (A ==> B ==> PROP C) ==> PROP C"
311   show "A & B" by (rule conjI)
312 next
313   fix C
314   assume "A & B"
315   assume "A ==> B ==> PROP C"
316   thus "PROP C"
317   proof this
318     show A by (rule conjunct1)
319     show B by (rule conjunct2)
320   qed
321 qed
323 lemmas [symmetric, rulify] = atomize_all atomize_imp
326 subsubsection {* Classical Reasoner setup *}
329 setup hypsubst_setup
331 ML_setup {*
332   Context.>> (ContextRules.addSWrapper (fn tac => hyp_subst_tac' ORELSE' tac));
333 *}
335 setup Classical.setup
336 setup clasetup
338 lemmas [intro?] = ext
339   and [elim?] = ex1_implies_ex
341 use "blastdata.ML"
342 setup Blast.setup
345 subsubsection {* Simplifier setup *}
347 lemma meta_eq_to_obj_eq: "x == y ==> x = y"
348 proof -
349   assume r: "x == y"
350   show "x = y" by (unfold r) (rule refl)
351 qed
353 lemma eta_contract_eq: "(%s. f s) = f" ..
355 lemma simp_thms:
356   shows not_not: "(~ ~ P) = P"
357   and Not_eq_iff: "((~P) = (~Q)) = (P = Q)"
358   and
359     "(P ~= Q) = (P = (~Q))"
360     "(P | ~P) = True"    "(~P | P) = True"
361     "(x = x) = True"
362     "(~True) = False"  "(~False) = True"
363     "(~P) ~= P"  "P ~= (~P)"
364     "(True=P) = P"  "(P=True) = P"  "(False=P) = (~P)"  "(P=False) = (~P)"
365     "(True --> P) = P"  "(False --> P) = True"
366     "(P --> True) = True"  "(P --> P) = True"
367     "(P --> False) = (~P)"  "(P --> ~P) = (~P)"
368     "(P & True) = P"  "(True & P) = P"
369     "(P & False) = False"  "(False & P) = False"
370     "(P & P) = P"  "(P & (P & Q)) = (P & Q)"
371     "(P & ~P) = False"    "(~P & P) = False"
372     "(P | True) = True"  "(True | P) = True"
373     "(P | False) = P"  "(False | P) = P"
374     "(P | P) = P"  "(P | (P | Q)) = (P | Q)" and
375     "(ALL x. P) = P"  "(EX x. P) = P"  "EX x. x=t"  "EX x. t=x"
376     -- {* needed for the one-point-rule quantifier simplification procs *}
377     -- {* essential for termination!! *} and
378     "!!P. (EX x. x=t & P(x)) = P(t)"
379     "!!P. (EX x. t=x & P(x)) = P(t)"
380     "!!P. (ALL x. x=t --> P(x)) = P(t)"
381     "!!P. (ALL x. t=x --> P(x)) = P(t)"
382   by (blast, blast, blast, blast, blast, rules+)
384 lemma imp_cong: "(P = P') ==> (P' ==> (Q = Q')) ==> ((P --> Q) = (P' --> Q'))"
385   by rules
387 lemma ex_simps:
388   "!!P Q. (EX x. P x & Q)   = ((EX x. P x) & Q)"
389   "!!P Q. (EX x. P & Q x)   = (P & (EX x. Q x))"
390   "!!P Q. (EX x. P x | Q)   = ((EX x. P x) | Q)"
391   "!!P Q. (EX x. P | Q x)   = (P | (EX x. Q x))"
392   "!!P Q. (EX x. P x --> Q) = ((ALL x. P x) --> Q)"
393   "!!P Q. (EX x. P --> Q x) = (P --> (EX x. Q x))"
394   -- {* Miniscoping: pushing in existential quantifiers. *}
395   by (rules | blast)+
397 lemma all_simps:
398   "!!P Q. (ALL x. P x & Q)   = ((ALL x. P x) & Q)"
399   "!!P Q. (ALL x. P & Q x)   = (P & (ALL x. Q x))"
400   "!!P Q. (ALL x. P x | Q)   = ((ALL x. P x) | Q)"
401   "!!P Q. (ALL x. P | Q x)   = (P | (ALL x. Q x))"
402   "!!P Q. (ALL x. P x --> Q) = ((EX x. P x) --> Q)"
403   "!!P Q. (ALL x. P --> Q x) = (P --> (ALL x. Q x))"
404   -- {* Miniscoping: pushing in universal quantifiers. *}
405   by (rules | blast)+
407 lemma disj_absorb: "(A | A) = A"
408   by blast
410 lemma disj_left_absorb: "(A | (A | B)) = (A | B)"
411   by blast
413 lemma conj_absorb: "(A & A) = A"
414   by blast
416 lemma conj_left_absorb: "(A & (A & B)) = (A & B)"
417   by blast
419 lemma eq_ac:
420   shows eq_commute: "(a=b) = (b=a)"
421     and eq_left_commute: "(P=(Q=R)) = (Q=(P=R))"
422     and eq_assoc: "((P=Q)=R) = (P=(Q=R))" by (rules, blast+)
423 lemma neq_commute: "(a~=b) = (b~=a)" by rules
425 lemma conj_comms:
426   shows conj_commute: "(P&Q) = (Q&P)"
427     and conj_left_commute: "(P&(Q&R)) = (Q&(P&R))" by rules+
428 lemma conj_assoc: "((P&Q)&R) = (P&(Q&R))" by rules
430 lemma disj_comms:
431   shows disj_commute: "(P|Q) = (Q|P)"
432     and disj_left_commute: "(P|(Q|R)) = (Q|(P|R))" by rules+
433 lemma disj_assoc: "((P|Q)|R) = (P|(Q|R))" by rules
435 lemma conj_disj_distribL: "(P&(Q|R)) = (P&Q | P&R)" by rules
436 lemma conj_disj_distribR: "((P|Q)&R) = (P&R | Q&R)" by rules
438 lemma disj_conj_distribL: "(P|(Q&R)) = ((P|Q) & (P|R))" by rules
439 lemma disj_conj_distribR: "((P&Q)|R) = ((P|R) & (Q|R))" by rules
441 lemma imp_conjR: "(P --> (Q&R)) = ((P-->Q) & (P-->R))" by rules
442 lemma imp_conjL: "((P&Q) -->R)  = (P --> (Q --> R))" by rules
443 lemma imp_disjL: "((P|Q) --> R) = ((P-->R)&(Q-->R))" by rules
445 text {* These two are specialized, but @{text imp_disj_not1} is useful in @{text "Auth/Yahalom"}. *}
446 lemma imp_disj_not1: "(P --> Q | R) = (~Q --> P --> R)" by blast
447 lemma imp_disj_not2: "(P --> Q | R) = (~R --> P --> Q)" by blast
449 lemma imp_disj1: "((P-->Q)|R) = (P--> Q|R)" by blast
450 lemma imp_disj2: "(Q|(P-->R)) = (P--> Q|R)" by blast
452 lemma de_Morgan_disj: "(~(P | Q)) = (~P & ~Q)" by rules
453 lemma de_Morgan_conj: "(~(P & Q)) = (~P | ~Q)" by blast
454 lemma not_imp: "(~(P --> Q)) = (P & ~Q)" by blast
455 lemma not_iff: "(P~=Q) = (P = (~Q))" by blast
456 lemma disj_not1: "(~P | Q) = (P --> Q)" by blast
457 lemma disj_not2: "(P | ~Q) = (Q --> P)"  -- {* changes orientation :-( *}
458   by blast
459 lemma imp_conv_disj: "(P --> Q) = ((~P) | Q)" by blast
461 lemma iff_conv_conj_imp: "(P = Q) = ((P --> Q) & (Q --> P))" by rules
464 lemma cases_simp: "((P --> Q) & (~P --> Q)) = Q"
465   -- {* Avoids duplication of subgoals after @{text split_if}, when the true and false *}
466   -- {* cases boil down to the same thing. *}
467   by blast
469 lemma not_all: "(~ (! x. P(x))) = (? x.~P(x))" by blast
470 lemma imp_all: "((! x. P x) --> Q) = (? x. P x --> Q)" by blast
471 lemma not_ex: "(~ (? x. P(x))) = (! x.~P(x))" by rules
472 lemma imp_ex: "((? x. P x) --> Q) = (! x. P x --> Q)" by rules
474 lemma ex_disj_distrib: "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))" by rules
475 lemma all_conj_distrib: "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))" by rules
477 text {*
478   \medskip The @{text "&"} congruence rule: not included by default!
479   May slow rewrite proofs down by as much as 50\% *}
481 lemma conj_cong:
482     "(P = P') ==> (P' ==> (Q = Q')) ==> ((P & Q) = (P' & Q'))"
483   by rules
485 lemma rev_conj_cong:
486     "(Q = Q') ==> (Q' ==> (P = P')) ==> ((P & Q) = (P' & Q'))"
487   by rules
489 text {* The @{text "|"} congruence rule: not included by default! *}
491 lemma disj_cong:
492     "(P = P') ==> (~P' ==> (Q = Q')) ==> ((P | Q) = (P' | Q'))"
493   by blast
495 lemma eq_sym_conv: "(x = y) = (y = x)"
496   by rules
499 text {* \medskip if-then-else rules *}
501 lemma if_True: "(if True then x else y) = x"
502   by (unfold if_def) blast
504 lemma if_False: "(if False then x else y) = y"
505   by (unfold if_def) blast
507 lemma if_P: "P ==> (if P then x else y) = x"
508   by (unfold if_def) blast
510 lemma if_not_P: "~P ==> (if P then x else y) = y"
511   by (unfold if_def) blast
513 lemma split_if: "P (if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))"
514   apply (rule case_split [of Q])
515    apply (subst if_P)
516     prefer 3 apply (subst if_not_P, blast+)
517   done
519 lemma split_if_asm: "P (if Q then x else y) = (~((Q & ~P x) | (~Q & ~P y)))"
520 by (subst split_if, blast)
522 lemmas if_splits = split_if split_if_asm
524 lemma if_def2: "(if Q then x else y) = ((Q --> x) & (~ Q --> y))"
525   by (rule split_if)
527 lemma if_cancel: "(if c then x else x) = x"
528 by (subst split_if, blast)
530 lemma if_eq_cancel: "(if x = y then y else x) = x"
531 by (subst split_if, blast)
533 lemma if_bool_eq_conj: "(if P then Q else R) = ((P-->Q) & (~P-->R))"
534   -- {* This form is useful for expanding @{text if}s on the RIGHT of the @{text "==>"} symbol. *}
535   by (rule split_if)
537 lemma if_bool_eq_disj: "(if P then Q else R) = ((P&Q) | (~P&R))"
538   -- {* And this form is useful for expanding @{text if}s on the LEFT. *}
539   apply (subst split_if, blast)
540   done
542 lemma Eq_TrueI: "P ==> P == True" by (unfold atomize_eq) rules
543 lemma Eq_FalseI: "~P ==> P == False" by (unfold atomize_eq) rules
545 subsubsection {* Actual Installation of the Simplifier *}
547 use "simpdata.ML"
548 setup Simplifier.setup
549 setup "Simplifier.method_setup Splitter.split_modifiers" setup simpsetup
550 setup Splitter.setup setup Clasimp.setup
552 declare disj_absorb [simp] conj_absorb [simp]
554 lemma ex1_eq[iff]: "EX! x. x = t" "EX! x. t = x"
555 by blast+
557 theorem choice_eq: "(ALL x. EX! y. P x y) = (EX! f. ALL x. P x (f x))"
558   apply (rule iffI)
559   apply (rule_tac a = "%x. THE y. P x y" in ex1I)
560   apply (fast dest!: theI')
561   apply (fast intro: ext the1_equality [symmetric])
562   apply (erule ex1E)
563   apply (rule allI)
564   apply (rule ex1I)
565   apply (erule spec)
566   apply (erule_tac x = "%z. if z = x then y else f z" in allE)
567   apply (erule impE)
568   apply (rule allI)
569   apply (rule_tac P = "xa = x" in case_split_thm)
570   apply (drule_tac  x = x in fun_cong, simp_all)
571   done
573 text{*Needs only HOL-lemmas:*}
574 lemma mk_left_commute:
575   assumes a: "\<And>x y z. f (f x y) z = f x (f y z)" and
576           c: "\<And>x y. f x y = f y x"
577   shows "f x (f y z) = f y (f x z)"
578 by(rule trans[OF trans[OF c a] arg_cong[OF c, of "f y"]])
581 subsubsection {* Generic cases and induction *}
583 constdefs
584   induct_forall :: "('a => bool) => bool"
585   "induct_forall P == \<forall>x. P x"
586   induct_implies :: "bool => bool => bool"
587   "induct_implies A B == A --> B"
588   induct_equal :: "'a => 'a => bool"
589   "induct_equal x y == x = y"
590   induct_conj :: "bool => bool => bool"
591   "induct_conj A B == A & B"
593 lemma induct_forall_eq: "(!!x. P x) == Trueprop (induct_forall (\<lambda>x. P x))"
594   by (simp only: atomize_all induct_forall_def)
596 lemma induct_implies_eq: "(A ==> B) == Trueprop (induct_implies A B)"
597   by (simp only: atomize_imp induct_implies_def)
599 lemma induct_equal_eq: "(x == y) == Trueprop (induct_equal x y)"
600   by (simp only: atomize_eq induct_equal_def)
602 lemma induct_forall_conj: "induct_forall (\<lambda>x. induct_conj (A x) (B x)) =
603     induct_conj (induct_forall A) (induct_forall B)"
604   by (unfold induct_forall_def induct_conj_def) rules
606 lemma induct_implies_conj: "induct_implies C (induct_conj A B) =
607     induct_conj (induct_implies C A) (induct_implies C B)"
608   by (unfold induct_implies_def induct_conj_def) rules
610 lemma induct_conj_curry: "(induct_conj A B ==> PROP C) == (A ==> B ==> PROP C)"
611 proof
612   assume r: "induct_conj A B ==> PROP C" and A B
613   show "PROP C" by (rule r) (simp! add: induct_conj_def)
614 next
615   assume r: "A ==> B ==> PROP C" and "induct_conj A B"
616   show "PROP C" by (rule r) (simp! add: induct_conj_def)+
617 qed
619 lemma induct_impliesI: "(A ==> B) ==> induct_implies A B"
620   by (simp add: induct_implies_def)
622 lemmas induct_atomize = atomize_conj induct_forall_eq induct_implies_eq induct_equal_eq
623 lemmas induct_rulify1 [symmetric, standard] = induct_forall_eq induct_implies_eq induct_equal_eq
624 lemmas induct_rulify2 = induct_forall_def induct_implies_def induct_equal_def induct_conj_def
625 lemmas induct_conj = induct_forall_conj induct_implies_conj induct_conj_curry
627 hide const induct_forall induct_implies induct_equal induct_conj
630 text {* Method setup. *}
632 ML {*
633   structure InductMethod = InductMethodFun
634   (struct
635     val dest_concls = HOLogic.dest_concls;
636     val cases_default = thm "case_split";
637     val local_impI = thm "induct_impliesI";
638     val conjI = thm "conjI";
639     val atomize = thms "induct_atomize";
640     val rulify1 = thms "induct_rulify1";
641     val rulify2 = thms "induct_rulify2";
642     val localize = [Thm.symmetric (thm "induct_implies_def")];
643   end);
644 *}
646 setup InductMethod.setup
649 subsection {* Order signatures and orders *}
651 axclass
652   ord < type
654 syntax
655   "op <"        :: "['a::ord, 'a] => bool"             ("op <")
656   "op <="       :: "['a::ord, 'a] => bool"             ("op <=")
658 global
660 consts
661   "op <"        :: "['a::ord, 'a] => bool"             ("(_/ < _)"  [50, 51] 50)
662   "op <="       :: "['a::ord, 'a] => bool"             ("(_/ <= _)" [50, 51] 50)
664 local
666 syntax (xsymbols)
667   "op <="       :: "['a::ord, 'a] => bool"             ("op \<le>")
668   "op <="       :: "['a::ord, 'a] => bool"             ("(_/ \<le> _)"  [50, 51] 50)
670 syntax (HTML output)
671   "op <="       :: "['a::ord, 'a] => bool"             ("op \<le>")
672   "op <="       :: "['a::ord, 'a] => bool"             ("(_/ \<le> _)"  [50, 51] 50)
674 text{* Syntactic sugar: *}
676 consts
677   "_gt" :: "'a::ord => 'a => bool"             (infixl ">" 50)
678   "_ge" :: "'a::ord => 'a => bool"             (infixl ">=" 50)
679 translations
680   "x > y"  => "y < x"
681   "x >= y" => "y <= x"
683 syntax (xsymbols)
684   "_ge"       :: "'a::ord => 'a => bool"             (infixl "\<ge>" 50)
686 syntax (HTML output)
687   "_ge"       :: "['a::ord, 'a] => bool"             (infixl "\<ge>" 50)
690 subsubsection {* Monotonicity *}
692 locale mono =
693   fixes f
694   assumes mono: "A <= B ==> f A <= f B"
696 lemmas monoI [intro?] = mono.intro
697   and monoD [dest?] = mono.mono
699 constdefs
700   min :: "['a::ord, 'a] => 'a"
701   "min a b == (if a <= b then a else b)"
702   max :: "['a::ord, 'a] => 'a"
703   "max a b == (if a <= b then b else a)"
705 lemma min_leastL: "(!!x. least <= x) ==> min least x = least"
706   by (simp add: min_def)
708 lemma min_of_mono:
709     "ALL x y. (f x <= f y) = (x <= y) ==> min (f m) (f n) = f (min m n)"
710   by (simp add: min_def)
712 lemma max_leastL: "(!!x. least <= x) ==> max least x = x"
713   by (simp add: max_def)
715 lemma max_of_mono:
716     "ALL x y. (f x <= f y) = (x <= y) ==> max (f m) (f n) = f (max m n)"
717   by (simp add: max_def)
720 subsubsection "Orders"
722 axclass order < ord
723   order_refl [iff]: "x <= x"
724   order_trans: "x <= y ==> y <= z ==> x <= z"
725   order_antisym: "x <= y ==> y <= x ==> x = y"
726   order_less_le: "(x < y) = (x <= y & x ~= y)"
729 text {* Reflexivity. *}
731 lemma order_eq_refl: "!!x::'a::order. x = y ==> x <= y"
732     -- {* This form is useful with the classical reasoner. *}
733   apply (erule ssubst)
734   apply (rule order_refl)
735   done
737 lemma order_less_irrefl [iff]: "~ x < (x::'a::order)"
738   by (simp add: order_less_le)
740 lemma order_le_less: "((x::'a::order) <= y) = (x < y | x = y)"
741     -- {* NOT suitable for iff, since it can cause PROOF FAILED. *}
742   apply (simp add: order_less_le, blast)
743   done
745 lemmas order_le_imp_less_or_eq = order_le_less [THEN iffD1, standard]
747 lemma order_less_imp_le: "!!x::'a::order. x < y ==> x <= y"
748   by (simp add: order_less_le)
751 text {* Asymmetry. *}
753 lemma order_less_not_sym: "(x::'a::order) < y ==> ~ (y < x)"
754   by (simp add: order_less_le order_antisym)
756 lemma order_less_asym: "x < (y::'a::order) ==> (~P ==> y < x) ==> P"
757   apply (drule order_less_not_sym)
758   apply (erule contrapos_np, simp)
759   done
761 lemma order_eq_iff: "!!x::'a::order. (x = y) = (x \<le> y & y \<le> x)"
762 by (blast intro: order_antisym)
764 lemma order_antisym_conv: "(y::'a::order) <= x ==> (x <= y) = (x = y)"
765 by(blast intro:order_antisym)
767 text {* Transitivity. *}
769 lemma order_less_trans: "!!x::'a::order. [| x < y; y < z |] ==> x < z"
770   apply (simp add: order_less_le)
771   apply (blast intro: order_trans order_antisym)
772   done
774 lemma order_le_less_trans: "!!x::'a::order. [| x <= y; y < z |] ==> x < z"
775   apply (simp add: order_less_le)
776   apply (blast intro: order_trans order_antisym)
777   done
779 lemma order_less_le_trans: "!!x::'a::order. [| x < y; y <= z |] ==> x < z"
780   apply (simp add: order_less_le)
781   apply (blast intro: order_trans order_antisym)
782   done
785 text {* Useful for simplification, but too risky to include by default. *}
787 lemma order_less_imp_not_less: "(x::'a::order) < y ==>  (~ y < x) = True"
788   by (blast elim: order_less_asym)
790 lemma order_less_imp_triv: "(x::'a::order) < y ==>  (y < x --> P) = True"
791   by (blast elim: order_less_asym)
793 lemma order_less_imp_not_eq: "(x::'a::order) < y ==>  (x = y) = False"
794   by auto
796 lemma order_less_imp_not_eq2: "(x::'a::order) < y ==>  (y = x) = False"
797   by auto
800 text {* Other operators. *}
802 lemma min_leastR: "(!!x::'a::order. least <= x) ==> min x least = least"
803   apply (simp add: min_def)
804   apply (blast intro: order_antisym)
805   done
807 lemma max_leastR: "(!!x::'a::order. least <= x) ==> max x least = x"
808   apply (simp add: max_def)
809   apply (blast intro: order_antisym)
810   done
813 subsubsection {* Least value operator *}
815 constdefs
816   Least :: "('a::ord => bool) => 'a"               (binder "LEAST " 10)
817   "Least P == THE x. P x & (ALL y. P y --> x <= y)"
818     -- {* We can no longer use LeastM because the latter requires Hilbert-AC. *}
820 lemma LeastI2:
821   "[| P (x::'a::order);
822       !!y. P y ==> x <= y;
823       !!x. [| P x; ALL y. P y --> x \<le> y |] ==> Q x |]
824    ==> Q (Least P)"
825   apply (unfold Least_def)
826   apply (rule theI2)
827     apply (blast intro: order_antisym)+
828   done
830 lemma Least_equality:
831     "[| P (k::'a::order); !!x. P x ==> k <= x |] ==> (LEAST x. P x) = k"
832   apply (simp add: Least_def)
833   apply (rule the_equality)
834   apply (auto intro!: order_antisym)
835   done
838 subsubsection "Linear / total orders"
840 axclass linorder < order
841   linorder_linear: "x <= y | y <= x"
843 lemma linorder_less_linear: "!!x::'a::linorder. x<y | x=y | y<x"
844   apply (simp add: order_less_le)
845   apply (insert linorder_linear, blast)
846   done
848 lemma linorder_le_less_linear: "!!x::'a::linorder. x\<le>y | y<x"
849   by (simp add: order_le_less linorder_less_linear)
851 lemma linorder_le_cases [case_names le ge]:
852     "((x::'a::linorder) \<le> y ==> P) ==> (y \<le> x ==> P) ==> P"
853   by (insert linorder_linear, blast)
855 lemma linorder_cases [case_names less equal greater]:
856     "((x::'a::linorder) < y ==> P) ==> (x = y ==> P) ==> (y < x ==> P) ==> P"
857   by (insert linorder_less_linear, blast)
859 lemma linorder_not_less: "!!x::'a::linorder. (~ x < y) = (y <= x)"
860   apply (simp add: order_less_le)
861   apply (insert linorder_linear)
862   apply (blast intro: order_antisym)
863   done
865 lemma linorder_not_le: "!!x::'a::linorder. (~ x <= y) = (y < x)"
866   apply (simp add: order_less_le)
867   apply (insert linorder_linear)
868   apply (blast intro: order_antisym)
869   done
871 lemma linorder_neq_iff: "!!x::'a::linorder. (x ~= y) = (x<y | y<x)"
872 by (cut_tac x = x and y = y in linorder_less_linear, auto)
874 lemma linorder_neqE: "x ~= (y::'a::linorder) ==> (x < y ==> R) ==> (y < x ==> R) ==> R"
875 by (simp add: linorder_neq_iff, blast)
877 lemma linorder_antisym_conv1: "~ (x::'a::linorder) < y ==> (x <= y) = (x = y)"
878 by(blast intro:order_antisym dest:linorder_not_less[THEN iffD1])
880 lemma linorder_antisym_conv2: "(x::'a::linorder) <= y ==> (~ x < y) = (x = y)"
881 by(blast intro:order_antisym dest:linorder_not_less[THEN iffD1])
883 lemma linorder_antisym_conv3: "~ (y::'a::linorder) < x ==> (~ x < y) = (x = y)"
884 by(blast intro:order_antisym dest:linorder_not_less[THEN iffD1])
886 use "antisym_setup.ML";
887 setup antisym_setup
889 subsubsection "Min and max on (linear) orders"
891 lemma min_same [simp]: "min (x::'a::order) x = x"
892   by (simp add: min_def)
894 lemma max_same [simp]: "max (x::'a::order) x = x"
895   by (simp add: max_def)
897 lemma le_max_iff_disj: "!!z::'a::linorder. (z <= max x y) = (z <= x | z <= y)"
898   apply (simp add: max_def)
899   apply (insert linorder_linear)
900   apply (blast intro: order_trans)
901   done
903 lemma le_maxI1: "(x::'a::linorder) <= max x y"
904   by (simp add: le_max_iff_disj)
906 lemma le_maxI2: "(y::'a::linorder) <= max x y"
907     -- {* CANNOT use with @{text "[intro!]"} because blast will give PROOF FAILED. *}
908   by (simp add: le_max_iff_disj)
910 lemma less_max_iff_disj: "!!z::'a::linorder. (z < max x y) = (z < x | z < y)"
911   apply (simp add: max_def order_le_less)
912   apply (insert linorder_less_linear)
913   apply (blast intro: order_less_trans)
914   done
916 lemma max_le_iff_conj [simp]:
917     "!!z::'a::linorder. (max x y <= z) = (x <= z & y <= z)"
918   apply (simp add: max_def)
919   apply (insert linorder_linear)
920   apply (blast intro: order_trans)
921   done
923 lemma max_less_iff_conj [simp]:
924     "!!z::'a::linorder. (max x y < z) = (x < z & y < z)"
925   apply (simp add: order_le_less max_def)
926   apply (insert linorder_less_linear)
927   apply (blast intro: order_less_trans)
928   done
930 lemma le_min_iff_conj [simp]:
931     "!!z::'a::linorder. (z <= min x y) = (z <= x & z <= y)"
932     -- {* @{text "[iff]"} screws up a @{text blast} in MiniML *}
933   apply (simp add: min_def)
934   apply (insert linorder_linear)
935   apply (blast intro: order_trans)
936   done
938 lemma min_less_iff_conj [simp]:
939     "!!z::'a::linorder. (z < min x y) = (z < x & z < y)"
940   apply (simp add: order_le_less min_def)
941   apply (insert linorder_less_linear)
942   apply (blast intro: order_less_trans)
943   done
945 lemma min_le_iff_disj: "!!z::'a::linorder. (min x y <= z) = (x <= z | y <= z)"
946   apply (simp add: min_def)
947   apply (insert linorder_linear)
948   apply (blast intro: order_trans)
949   done
951 lemma min_less_iff_disj: "!!z::'a::linorder. (min x y < z) = (x < z | y < z)"
952   apply (simp add: min_def order_le_less)
953   apply (insert linorder_less_linear)
954   apply (blast intro: order_less_trans)
955   done
957 lemma max_assoc: "!!x::'a::linorder. max (max x y) z = max x (max y z)"
959 apply(rule conjI)
960 apply(blast intro:order_trans)
962 apply(blast dest: order_less_trans order_le_less_trans)
963 done
965 lemma max_commute: "!!x::'a::linorder. max x y = max y x"
968 apply(blast dest: order_less_trans)
969 done
971 lemmas max_ac = max_assoc max_commute
972                 mk_left_commute[of max,OF max_assoc max_commute]
974 lemma min_assoc: "!!x::'a::linorder. min (min x y) z = min x (min y z)"
976 apply(rule conjI)
977 apply(blast intro:order_trans)
979 apply(blast dest: order_less_trans order_le_less_trans)
980 done
982 lemma min_commute: "!!x::'a::linorder. min x y = min y x"
985 apply(blast dest: order_less_trans)
986 done
988 lemmas min_ac = min_assoc min_commute
989                 mk_left_commute[of min,OF min_assoc min_commute]
991 lemma split_min:
992     "P (min (i::'a::linorder) j) = ((i <= j --> P(i)) & (~ i <= j --> P(j)))"
993   by (simp add: min_def)
995 lemma split_max:
996     "P (max (i::'a::linorder) j) = ((i <= j --> P(j)) & (~ i <= j --> P(i)))"
997   by (simp add: max_def)
1000 subsubsection {* Transitivity rules for calculational reasoning *}
1003 lemma order_neq_le_trans: "a ~= b ==> (a::'a::order) <= b ==> a < b"
1004   by (simp add: order_less_le)
1006 lemma order_le_neq_trans: "(a::'a::order) <= b ==> a ~= b ==> a < b"
1007   by (simp add: order_less_le)
1009 lemma order_less_asym': "(a::'a::order) < b ==> b < a ==> P"
1010   by (rule order_less_asym)
1013 subsubsection {* Setup of transitivity reasoner as Solver *}
1015 lemma less_imp_neq: "[| (x::'a::order) < y |] ==> x ~= y"
1016   by (erule contrapos_pn, erule subst, rule order_less_irrefl)
1018 lemma eq_neq_eq_imp_neq: "[| x = a ; a ~= b; b = y |] ==> x ~= y"
1019   by (erule subst, erule ssubst, assumption)
1021 ML_setup {*
1023 (* The setting up of Quasi_Tac serves as a demo.  Since there is no
1024    class for quasi orders, the tactics Quasi_Tac.trans_tac and
1025    Quasi_Tac.quasi_tac are not of much use. *)
1027 fun decomp_gen sort sign (Trueprop \$ t) =
1028   let fun of_sort t = Sign.of_sort sign (type_of t, sort)
1029   fun dec (Const ("Not", _) \$ t) = (
1030 	  case dec t of
1031 	    None => None
1032 	  | Some (t1, rel, t2) => Some (t1, "~" ^ rel, t2))
1033 	| dec (Const ("op =",  _) \$ t1 \$ t2) =
1034 	    if of_sort t1
1035 	    then Some (t1, "=", t2)
1036 	    else None
1037 	| dec (Const ("op <=",  _) \$ t1 \$ t2) =
1038 	    if of_sort t1
1039 	    then Some (t1, "<=", t2)
1040 	    else None
1041 	| dec (Const ("op <",  _) \$ t1 \$ t2) =
1042 	    if of_sort t1
1043 	    then Some (t1, "<", t2)
1044 	    else None
1045 	| dec _ = None
1046   in dec t end;
1048 structure Quasi_Tac = Quasi_Tac_Fun (
1049   struct
1050     val le_trans = thm "order_trans";
1051     val le_refl = thm "order_refl";
1052     val eqD1 = thm "order_eq_refl";
1053     val eqD2 = thm "sym" RS thm "order_eq_refl";
1054     val less_reflE = thm "order_less_irrefl" RS thm "notE";
1055     val less_imp_le = thm "order_less_imp_le";
1056     val le_neq_trans = thm "order_le_neq_trans";
1057     val neq_le_trans = thm "order_neq_le_trans";
1058     val less_imp_neq = thm "less_imp_neq";
1059     val decomp_trans = decomp_gen ["HOL.order"];
1060     val decomp_quasi = decomp_gen ["HOL.order"];
1062   end);  (* struct *)
1064 structure Order_Tac = Order_Tac_Fun (
1065   struct
1066     val less_reflE = thm "order_less_irrefl" RS thm "notE";
1067     val le_refl = thm "order_refl";
1068     val less_imp_le = thm "order_less_imp_le";
1069     val not_lessI = thm "linorder_not_less" RS thm "iffD2";
1070     val not_leI = thm "linorder_not_le" RS thm "iffD2";
1071     val not_lessD = thm "linorder_not_less" RS thm "iffD1";
1072     val not_leD = thm "linorder_not_le" RS thm "iffD1";
1073     val eqI = thm "order_antisym";
1074     val eqD1 = thm "order_eq_refl";
1075     val eqD2 = thm "sym" RS thm "order_eq_refl";
1076     val less_trans = thm "order_less_trans";
1077     val less_le_trans = thm "order_less_le_trans";
1078     val le_less_trans = thm "order_le_less_trans";
1079     val le_trans = thm "order_trans";
1080     val le_neq_trans = thm "order_le_neq_trans";
1081     val neq_le_trans = thm "order_neq_le_trans";
1082     val less_imp_neq = thm "less_imp_neq";
1083     val eq_neq_eq_imp_neq = thm "eq_neq_eq_imp_neq";
1084     val decomp_part = decomp_gen ["HOL.order"];
1085     val decomp_lin = decomp_gen ["HOL.linorder"];
1087   end);  (* struct *)
1089 simpset_ref() := simpset ()
1090     addSolver (mk_solver "Trans_linear" (fn _ => Order_Tac.linear_tac))
1091     addSolver (mk_solver "Trans_partial" (fn _ => Order_Tac.partial_tac));
1092   (* Adding the transitivity reasoners also as safe solvers showed a slight
1093      speed up, but the reasoning strength appears to be not higher (at least
1094      no breaking of additional proofs in the entire HOL distribution, as
1095      of 5 March 2004, was observed). *)
1096 *}
1098 (* Optional setup of methods *)
1100 (*
1101 method_setup trans_partial =
1102   {* Method.no_args (Method.SIMPLE_METHOD' HEADGOAL (Order_Tac.partial_tac)) *}
1103   {* transitivity reasoner for partial orders *}
1104 method_setup trans_linear =
1105   {* Method.no_args (Method.SIMPLE_METHOD' HEADGOAL (Order_Tac.linear_tac)) *}
1106   {* transitivity reasoner for linear orders *}
1107 *)
1109 (*
1110 declare order.order_refl [simp del] order_less_irrefl [simp del]
1112 can currently not be removed, abel_cancel relies on it.
1113 *)
1115 subsubsection "Bounded quantifiers"
1117 syntax
1118   "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3ALL _<_./ _)"  [0, 0, 10] 10)
1119   "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3EX _<_./ _)"  [0, 0, 10] 10)
1120   "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3ALL _<=_./ _)" [0, 0, 10] 10)
1121   "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3EX _<=_./ _)" [0, 0, 10] 10)
1123   "_gtAll" :: "[idt, 'a, bool] => bool"   ("(3ALL _>_./ _)"  [0, 0, 10] 10)
1124   "_gtEx"  :: "[idt, 'a, bool] => bool"   ("(3EX _>_./ _)"  [0, 0, 10] 10)
1125   "_geAll"   :: "[idt, 'a, bool] => bool"   ("(3ALL _>=_./ _)" [0, 0, 10] 10)
1126   "_geEx"    :: "[idt, 'a, bool] => bool"   ("(3EX _>=_./ _)" [0, 0, 10] 10)
1128 syntax (xsymbols)
1129   "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
1130   "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
1131   "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
1132   "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
1134   "_gtAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_>_./ _)"  [0, 0, 10] 10)
1135   "_gtEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_>_./ _)"  [0, 0, 10] 10)
1136   "_geAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<ge>_./ _)" [0, 0, 10] 10)
1137   "_geEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<ge>_./ _)" [0, 0, 10] 10)
1139 syntax (HOL)
1140   "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3! _<_./ _)"  [0, 0, 10] 10)
1141   "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3? _<_./ _)"  [0, 0, 10] 10)
1142   "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3! _<=_./ _)" [0, 0, 10] 10)
1143   "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3? _<=_./ _)" [0, 0, 10] 10)
1145 syntax (HTML output)
1146   "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
1147   "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
1148   "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
1149   "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
1151   "_gtAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_>_./ _)"  [0, 0, 10] 10)
1152   "_gtEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_>_./ _)"  [0, 0, 10] 10)
1153   "_geAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<ge>_./ _)" [0, 0, 10] 10)
1154   "_geEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<ge>_./ _)" [0, 0, 10] 10)
1156 translations
1157  "ALL x<y. P"   =>  "ALL x. x < y --> P"
1158  "EX x<y. P"    =>  "EX x. x < y  & P"
1159  "ALL x<=y. P"  =>  "ALL x. x <= y --> P"
1160  "EX x<=y. P"   =>  "EX x. x <= y & P"
1161  "ALL x>y. P"   =>  "ALL x. x > y --> P"
1162  "EX x>y. P"    =>  "EX x. x > y  & P"
1163  "ALL x>=y. P"  =>  "ALL x. x >= y --> P"
1164  "EX x>=y. P"   =>  "EX x. x >= y & P"
1166 print_translation {*
1167 let
1168   fun mk v v' q n P =
1169     if v=v' andalso not(v  mem (map fst (Term.add_frees([],n))))
1170     then Syntax.const q \$ Syntax.mark_bound v' \$ n \$ P else raise Match;
1171   fun all_tr' [Const ("_bound",_) \$ Free (v,_),
1172                Const("op -->",_) \$ (Const ("op <",_) \$ (Const ("_bound",_) \$ Free (v',_)) \$ n ) \$ P] =
1173     mk v v' "_lessAll" n P
1175   | all_tr' [Const ("_bound",_) \$ Free (v,_),
1176                Const("op -->",_) \$ (Const ("op <=",_) \$ (Const ("_bound",_) \$ Free (v',_)) \$ n ) \$ P] =
1177     mk v v' "_leAll" n P
1179   | all_tr' [Const ("_bound",_) \$ Free (v,_),
1180                Const("op -->",_) \$ (Const ("op <",_) \$ n \$ (Const ("_bound",_) \$ Free (v',_))) \$ P] =
1181     mk v v' "_gtAll" n P
1183   | all_tr' [Const ("_bound",_) \$ Free (v,_),
1184                Const("op -->",_) \$ (Const ("op <=",_) \$ n \$ (Const ("_bound",_) \$ Free (v',_))) \$ P] =
1185     mk v v' "_geAll" n P;
1187   fun ex_tr' [Const ("_bound",_) \$ Free (v,_),
1188                Const("op &",_) \$ (Const ("op <",_) \$ (Const ("_bound",_) \$ Free (v',_)) \$ n ) \$ P] =
1189     mk v v' "_lessEx" n P
1191   | ex_tr' [Const ("_bound",_) \$ Free (v,_),
1192                Const("op &",_) \$ (Const ("op <=",_) \$ (Const ("_bound",_) \$ Free (v',_)) \$ n ) \$ P] =
1193     mk v v' "_leEx" n P
1195   | ex_tr' [Const ("_bound",_) \$ Free (v,_),
1196                Const("op &",_) \$ (Const ("op <",_) \$ n \$ (Const ("_bound",_) \$ Free (v',_))) \$ P] =
1197     mk v v' "_gtEx" n P
1199   | ex_tr' [Const ("_bound",_) \$ Free (v,_),
1200                Const("op &",_) \$ (Const ("op <=",_) \$ n \$ (Const ("_bound",_) \$ Free (v',_))) \$ P] =
1201     mk v v' "_geEx" n P
1202 in
1203 [("ALL ", all_tr'), ("EX ", ex_tr')]
1204 end
1205 *}
1207 end