src/HOL/HOL.thy
 author wenzelm Wed Jul 24 00:10:52 2002 +0200 (2002-07-24) changeset 13412 666137b488a4 parent 12937 0c4fd7529467 child 13421 8fcdf4a26468 permissions -rw-r--r--
predicate defs via locales;
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 syntax (output)
79   "="           :: "['a, 'a] => bool"                    (infix 50)
80   "_not_equal"  :: "['a, 'a] => bool"                    (infix "~=" 50)
82 syntax (xsymbols)
83   Not           :: "bool => bool"                        ("\<not> _"  40)
84   "op &"        :: "[bool, bool] => bool"                (infixr "\<and>" 35)
85   "op |"        :: "[bool, bool] => bool"                (infixr "\<or>" 30)
86   "op -->"      :: "[bool, bool] => bool"                (infixr "\<longrightarrow>" 25)
87   "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
88   "ALL "        :: "[idts, bool] => bool"                ("(3\<forall>_./ _)" [0, 10] 10)
89   "EX "         :: "[idts, bool] => bool"                ("(3\<exists>_./ _)" [0, 10] 10)
90   "EX! "        :: "[idts, bool] => bool"                ("(3\<exists>!_./ _)" [0, 10] 10)
91   "_case1"      :: "['a, 'b] => case_syn"                ("(2_ \<Rightarrow>/ _)" 10)
92 (*"_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ \\<orelse> _")*)
94 syntax (xsymbols output)
95   "_not_equal"  :: "['a, 'a] => bool"                    (infix "\<noteq>" 50)
97 syntax (HTML output)
98   Not           :: "bool => bool"                        ("\<not> _"  40)
100 syntax (HOL)
101   "ALL "        :: "[idts, bool] => bool"                ("(3! _./ _)" [0, 10] 10)
102   "EX "         :: "[idts, bool] => bool"                ("(3? _./ _)" [0, 10] 10)
103   "EX! "        :: "[idts, bool] => bool"                ("(3?! _./ _)" [0, 10] 10)
106 subsubsection {* Axioms and basic definitions *}
108 axioms
109   eq_reflection: "(x=y) ==> (x==y)"
111   refl:         "t = (t::'a)"
112   subst:        "[| s = t; P(s) |] ==> P(t::'a)"
114   ext:          "(!!x::'a. (f x ::'b) = g x) ==> (%x. f x) = (%x. g x)"
115     -- {* Extensionality is built into the meta-logic, and this rule expresses *}
116     -- {* a related property.  It is an eta-expanded version of the traditional *}
117     -- {* rule, and similar to the ABS rule of HOL *}
119   the_eq_trivial: "(THE x. x = a) = (a::'a)"
121   impI:         "(P ==> Q) ==> P-->Q"
122   mp:           "[| P-->Q;  P |] ==> Q"
124 defs
125   True_def:     "True      == ((%x::bool. x) = (%x. x))"
126   All_def:      "All(P)    == (P = (%x. True))"
127   Ex_def:       "Ex(P)     == !Q. (!x. P x --> Q) --> Q"
128   False_def:    "False     == (!P. P)"
129   not_def:      "~ P       == P-->False"
130   and_def:      "P & Q     == !R. (P-->Q-->R) --> R"
131   or_def:       "P | Q     == !R. (P-->R) --> (Q-->R) --> R"
132   Ex1_def:      "Ex1(P)    == ? x. P(x) & (! y. P(y) --> y=x)"
134 axioms
135   iff:          "(P-->Q) --> (Q-->P) --> (P=Q)"
136   True_or_False:  "(P=True) | (P=False)"
138 defs
139   Let_def:      "Let s f == f(s)"
140   if_def:       "If P x y == THE z::'a. (P=True --> z=x) & (P=False --> z=y)"
142   arbitrary_def:  "False ==> arbitrary == (THE x. False)"
143     -- {* @{term arbitrary} is completely unspecified, but is made to appear as a
144     definition syntactically *}
147 subsubsection {* Generic algebraic operations *}
149 axclass zero < type
150 axclass one < type
151 axclass plus < type
152 axclass minus < type
153 axclass times < type
154 axclass inverse < type
156 global
158 consts
159   "0"           :: "'a::zero"                       ("0")
160   "1"           :: "'a::one"                        ("1")
161   "+"           :: "['a::plus, 'a]  => 'a"          (infixl 65)
162   -             :: "['a::minus, 'a] => 'a"          (infixl 65)
163   uminus        :: "['a::minus] => 'a"              ("- _"  80)
164   *             :: "['a::times, 'a] => 'a"          (infixl 70)
166 local
168 typed_print_translation {*
169   let
170     fun tr' c = (c, fn show_sorts => fn T => fn ts =>
171       if T = dummyT orelse not (! show_types) andalso can Term.dest_Type T then raise Match
172       else Syntax.const Syntax.constrainC \$ Syntax.const c \$ Syntax.term_of_typ show_sorts T);
173   in [tr' "0", tr' "1"] end;
174 *} -- {* show types that are presumably too general *}
177 consts
178   abs           :: "'a::minus => 'a"
179   inverse       :: "'a::inverse => 'a"
180   divide        :: "['a::inverse, 'a] => 'a"        (infixl "'/" 70)
182 syntax (xsymbols)
183   abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
184 syntax (HTML output)
185   abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
187 axclass plus_ac0 < plus, zero
188   commute: "x + y = y + x"
189   assoc:   "(x + y) + z = x + (y + z)"
190   zero:    "0 + x = x"
193 subsection {* Theory and package setup *}
195 subsubsection {* Basic lemmas *}
197 use "HOL_lemmas.ML"
198 theorems case_split = case_split_thm [case_names True False]
201 subsubsection {* Intuitionistic Reasoning *}
203 lemma impE':
204   assumes 1: "P --> Q"
205     and 2: "Q ==> R"
206     and 3: "P --> Q ==> P"
207   shows R
208 proof -
209   from 3 and 1 have P .
210   with 1 have Q by (rule impE)
211   with 2 show R .
212 qed
214 lemma allE':
215   assumes 1: "ALL x. P x"
216     and 2: "P x ==> ALL x. P x ==> Q"
217   shows Q
218 proof -
219   from 1 have "P x" by (rule spec)
220   from this and 1 show Q by (rule 2)
221 qed
223 lemma notE':
224   assumes 1: "~ P"
225     and 2: "~ P ==> P"
226   shows R
227 proof -
228   from 2 and 1 have P .
229   with 1 show R by (rule notE)
230 qed
232 lemmas [CPure.elim!] = disjE iffE FalseE conjE exE
233   and [CPure.intro!] = iffI conjI impI TrueI notI allI refl
234   and [CPure.elim 2] = allE notE' impE'
235   and [CPure.intro] = exI disjI2 disjI1
237 lemmas [trans] = trans
238   and [sym] = sym not_sym
239   and [CPure.elim?] = iffD1 iffD2 impE
242 subsubsection {* Atomizing meta-level connectives *}
244 lemma atomize_all [atomize]: "(!!x. P x) == Trueprop (ALL x. P x)"
245 proof
246   assume "!!x. P x"
247   show "ALL x. P x" by (rule allI)
248 next
249   assume "ALL x. P x"
250   thus "!!x. P x" by (rule allE)
251 qed
253 lemma atomize_imp [atomize]: "(A ==> B) == Trueprop (A --> B)"
254 proof
255   assume r: "A ==> B"
256   show "A --> B" by (rule impI) (rule r)
257 next
258   assume "A --> B" and A
259   thus B by (rule mp)
260 qed
262 lemma atomize_eq [atomize]: "(x == y) == Trueprop (x = y)"
263 proof
264   assume "x == y"
265   show "x = y" by (unfold prems) (rule refl)
266 next
267   assume "x = y"
268   thus "x == y" by (rule eq_reflection)
269 qed
271 lemma atomize_conj [atomize]:
272   "(!!C. (A ==> B ==> PROP C) ==> PROP C) == Trueprop (A & B)"
273 proof
274   assume "!!C. (A ==> B ==> PROP C) ==> PROP C"
275   show "A & B" by (rule conjI)
276 next
277   fix C
278   assume "A & B"
279   assume "A ==> B ==> PROP C"
280   thus "PROP C"
281   proof this
282     show A by (rule conjunct1)
283     show B by (rule conjunct2)
284   qed
285 qed
287 lemmas [symmetric, rulify] = atomize_all atomize_imp
290 subsubsection {* Classical Reasoner setup *}
293 setup hypsubst_setup
295 ML_setup {*
296   Context.>> (ContextRules.addSWrapper (fn tac => hyp_subst_tac' ORELSE' tac));
297 *}
299 setup Classical.setup
300 setup clasetup
302 lemmas [intro?] = ext
303   and [elim?] = ex1_implies_ex
305 use "blastdata.ML"
306 setup Blast.setup
309 subsubsection {* Simplifier setup *}
311 lemma meta_eq_to_obj_eq: "x == y ==> x = y"
312 proof -
313   assume r: "x == y"
314   show "x = y" by (unfold r) (rule refl)
315 qed
317 lemma eta_contract_eq: "(%s. f s) = f" ..
319 lemma simp_thms:
320   shows not_not: "(~ ~ P) = P"
321   and
322     "(P ~= Q) = (P = (~Q))"
323     "(P | ~P) = True"    "(~P | P) = True"
324     "((~P) = (~Q)) = (P=Q)"
325     "(x = x) = True"
326     "(~True) = False"  "(~False) = True"
327     "(~P) ~= P"  "P ~= (~P)"
328     "(True=P) = P"  "(P=True) = P"  "(False=P) = (~P)"  "(P=False) = (~P)"
329     "(True --> P) = P"  "(False --> P) = True"
330     "(P --> True) = True"  "(P --> P) = True"
331     "(P --> False) = (~P)"  "(P --> ~P) = (~P)"
332     "(P & True) = P"  "(True & P) = P"
333     "(P & False) = False"  "(False & P) = False"
334     "(P & P) = P"  "(P & (P & Q)) = (P & Q)"
335     "(P & ~P) = False"    "(~P & P) = False"
336     "(P | True) = True"  "(True | P) = True"
337     "(P | False) = P"  "(False | P) = P"
338     "(P | P) = P"  "(P | (P | Q)) = (P | Q)" and
339     "(ALL x. P) = P"  "(EX x. P) = P"  "EX x. x=t"  "EX x. t=x"
340     -- {* needed for the one-point-rule quantifier simplification procs *}
341     -- {* essential for termination!! *} and
342     "!!P. (EX x. x=t & P(x)) = P(t)"
343     "!!P. (EX x. t=x & P(x)) = P(t)"
344     "!!P. (ALL x. x=t --> P(x)) = P(t)"
345     "!!P. (ALL x. t=x --> P(x)) = P(t)"
346   by (blast, blast, blast, blast, blast, rules+)
348 lemma imp_cong: "(P = P') ==> (P' ==> (Q = Q')) ==> ((P --> Q) = (P' --> Q'))"
349   by rules
351 lemma ex_simps:
352   "!!P Q. (EX x. P x & Q)   = ((EX x. P x) & Q)"
353   "!!P Q. (EX x. P & Q x)   = (P & (EX x. Q x))"
354   "!!P Q. (EX x. P x | Q)   = ((EX x. P x) | Q)"
355   "!!P Q. (EX x. P | Q x)   = (P | (EX x. Q x))"
356   "!!P Q. (EX x. P x --> Q) = ((ALL x. P x) --> Q)"
357   "!!P Q. (EX x. P --> Q x) = (P --> (EX x. Q x))"
358   -- {* Miniscoping: pushing in existential quantifiers. *}
359   by (rules | blast)+
361 lemma all_simps:
362   "!!P Q. (ALL x. P x & Q)   = ((ALL x. P x) & Q)"
363   "!!P Q. (ALL x. P & Q x)   = (P & (ALL x. Q x))"
364   "!!P Q. (ALL x. P x | Q)   = ((ALL x. P x) | Q)"
365   "!!P Q. (ALL x. P | Q x)   = (P | (ALL x. Q x))"
366   "!!P Q. (ALL x. P x --> Q) = ((EX x. P x) --> Q)"
367   "!!P Q. (ALL x. P --> Q x) = (P --> (ALL x. Q x))"
368   -- {* Miniscoping: pushing in universal quantifiers. *}
369   by (rules | blast)+
371 lemma eq_ac:
372   shows eq_commute: "(a=b) = (b=a)"
373     and eq_left_commute: "(P=(Q=R)) = (Q=(P=R))"
374     and eq_assoc: "((P=Q)=R) = (P=(Q=R))" by (rules, blast+)
375 lemma neq_commute: "(a~=b) = (b~=a)" by rules
377 lemma conj_comms:
378   shows conj_commute: "(P&Q) = (Q&P)"
379     and conj_left_commute: "(P&(Q&R)) = (Q&(P&R))" by rules+
380 lemma conj_assoc: "((P&Q)&R) = (P&(Q&R))" by rules
382 lemma disj_comms:
383   shows disj_commute: "(P|Q) = (Q|P)"
384     and disj_left_commute: "(P|(Q|R)) = (Q|(P|R))" by rules+
385 lemma disj_assoc: "((P|Q)|R) = (P|(Q|R))" by rules
387 lemma conj_disj_distribL: "(P&(Q|R)) = (P&Q | P&R)" by rules
388 lemma conj_disj_distribR: "((P|Q)&R) = (P&R | Q&R)" by rules
390 lemma disj_conj_distribL: "(P|(Q&R)) = ((P|Q) & (P|R))" by rules
391 lemma disj_conj_distribR: "((P&Q)|R) = ((P|R) & (Q|R))" by rules
393 lemma imp_conjR: "(P --> (Q&R)) = ((P-->Q) & (P-->R))" by rules
394 lemma imp_conjL: "((P&Q) -->R)  = (P --> (Q --> R))" by rules
395 lemma imp_disjL: "((P|Q) --> R) = ((P-->R)&(Q-->R))" by rules
397 text {* These two are specialized, but @{text imp_disj_not1} is useful in @{text "Auth/Yahalom"}. *}
398 lemma imp_disj_not1: "(P --> Q | R) = (~Q --> P --> R)" by blast
399 lemma imp_disj_not2: "(P --> Q | R) = (~R --> P --> Q)" by blast
401 lemma imp_disj1: "((P-->Q)|R) = (P--> Q|R)" by blast
402 lemma imp_disj2: "(Q|(P-->R)) = (P--> Q|R)" by blast
404 lemma de_Morgan_disj: "(~(P | Q)) = (~P & ~Q)" by rules
405 lemma de_Morgan_conj: "(~(P & Q)) = (~P | ~Q)" by blast
406 lemma not_imp: "(~(P --> Q)) = (P & ~Q)" by blast
407 lemma not_iff: "(P~=Q) = (P = (~Q))" by blast
408 lemma disj_not1: "(~P | Q) = (P --> Q)" by blast
409 lemma disj_not2: "(P | ~Q) = (Q --> P)"  -- {* changes orientation :-( *}
410   by blast
411 lemma imp_conv_disj: "(P --> Q) = ((~P) | Q)" by blast
413 lemma iff_conv_conj_imp: "(P = Q) = ((P --> Q) & (Q --> P))" by rules
416 lemma cases_simp: "((P --> Q) & (~P --> Q)) = Q"
417   -- {* Avoids duplication of subgoals after @{text split_if}, when the true and false *}
418   -- {* cases boil down to the same thing. *}
419   by blast
421 lemma not_all: "(~ (! x. P(x))) = (? x.~P(x))" by blast
422 lemma imp_all: "((! x. P x) --> Q) = (? x. P x --> Q)" by blast
423 lemma not_ex: "(~ (? x. P(x))) = (! x.~P(x))" by rules
424 lemma imp_ex: "((? x. P x) --> Q) = (! x. P x --> Q)" by rules
426 lemma ex_disj_distrib: "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))" by rules
427 lemma all_conj_distrib: "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))" by rules
429 text {*
430   \medskip The @{text "&"} congruence rule: not included by default!
431   May slow rewrite proofs down by as much as 50\% *}
433 lemma conj_cong:
434     "(P = P') ==> (P' ==> (Q = Q')) ==> ((P & Q) = (P' & Q'))"
435   by rules
437 lemma rev_conj_cong:
438     "(Q = Q') ==> (Q' ==> (P = P')) ==> ((P & Q) = (P' & Q'))"
439   by rules
441 text {* The @{text "|"} congruence rule: not included by default! *}
443 lemma disj_cong:
444     "(P = P') ==> (~P' ==> (Q = Q')) ==> ((P | Q) = (P' | Q'))"
445   by blast
447 lemma eq_sym_conv: "(x = y) = (y = x)"
448   by rules
451 text {* \medskip if-then-else rules *}
453 lemma if_True: "(if True then x else y) = x"
454   by (unfold if_def) blast
456 lemma if_False: "(if False then x else y) = y"
457   by (unfold if_def) blast
459 lemma if_P: "P ==> (if P then x else y) = x"
460   by (unfold if_def) blast
462 lemma if_not_P: "~P ==> (if P then x else y) = y"
463   by (unfold if_def) blast
465 lemma split_if: "P (if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))"
466   apply (rule case_split [of Q])
467    apply (subst if_P)
468     prefer 3 apply (subst if_not_P)
469      apply blast+
470   done
472 lemma split_if_asm: "P (if Q then x else y) = (~((Q & ~P x) | (~Q & ~P y)))"
473   apply (subst split_if)
474   apply blast
475   done
477 lemmas if_splits = split_if split_if_asm
479 lemma if_def2: "(if Q then x else y) = ((Q --> x) & (~ Q --> y))"
480   by (rule split_if)
482 lemma if_cancel: "(if c then x else x) = x"
483   apply (subst split_if)
484   apply blast
485   done
487 lemma if_eq_cancel: "(if x = y then y else x) = x"
488   apply (subst split_if)
489   apply blast
490   done
492 lemma if_bool_eq_conj: "(if P then Q else R) = ((P-->Q) & (~P-->R))"
493   -- {* This form is useful for expanding @{text if}s on the RIGHT of the @{text "==>"} symbol. *}
494   by (rule split_if)
496 lemma if_bool_eq_disj: "(if P then Q else R) = ((P&Q) | (~P&R))"
497   -- {* And this form is useful for expanding @{text if}s on the LEFT. *}
498   apply (subst split_if)
499   apply blast
500   done
502 lemma Eq_TrueI: "P ==> P == True" by (unfold atomize_eq) rules
503 lemma Eq_FalseI: "~P ==> P == False" by (unfold atomize_eq) rules
505 use "simpdata.ML"
506 setup Simplifier.setup
507 setup "Simplifier.method_setup Splitter.split_modifiers" setup simpsetup
508 setup Splitter.setup setup Clasimp.setup
511 subsubsection {* Generic cases and induction *}
513 constdefs
514   induct_forall :: "('a => bool) => bool"
515   "induct_forall P == \<forall>x. P x"
516   induct_implies :: "bool => bool => bool"
517   "induct_implies A B == A --> B"
518   induct_equal :: "'a => 'a => bool"
519   "induct_equal x y == x = y"
520   induct_conj :: "bool => bool => bool"
521   "induct_conj A B == A & B"
523 lemma induct_forall_eq: "(!!x. P x) == Trueprop (induct_forall (\<lambda>x. P x))"
524   by (simp only: atomize_all induct_forall_def)
526 lemma induct_implies_eq: "(A ==> B) == Trueprop (induct_implies A B)"
527   by (simp only: atomize_imp induct_implies_def)
529 lemma induct_equal_eq: "(x == y) == Trueprop (induct_equal x y)"
530   by (simp only: atomize_eq induct_equal_def)
532 lemma induct_forall_conj: "induct_forall (\<lambda>x. induct_conj (A x) (B x)) =
533     induct_conj (induct_forall A) (induct_forall B)"
534   by (unfold induct_forall_def induct_conj_def) rules
536 lemma induct_implies_conj: "induct_implies C (induct_conj A B) =
537     induct_conj (induct_implies C A) (induct_implies C B)"
538   by (unfold induct_implies_def induct_conj_def) rules
540 lemma induct_conj_curry: "(induct_conj A B ==> C) == (A ==> B ==> C)"
541   by (simp only: atomize_imp atomize_eq induct_conj_def) (rules intro: equal_intr_rule)
543 lemma induct_impliesI: "(A ==> B) ==> induct_implies A B"
544   by (simp add: induct_implies_def)
546 lemmas induct_atomize = atomize_conj induct_forall_eq induct_implies_eq induct_equal_eq
547 lemmas induct_rulify1 [symmetric, standard] = induct_forall_eq induct_implies_eq induct_equal_eq
548 lemmas induct_rulify2 = induct_forall_def induct_implies_def induct_equal_def induct_conj_def
549 lemmas induct_conj = induct_forall_conj induct_implies_conj induct_conj_curry
551 hide const induct_forall induct_implies induct_equal induct_conj
554 text {* Method setup. *}
556 ML {*
557   structure InductMethod = InductMethodFun
558   (struct
559     val dest_concls = HOLogic.dest_concls;
560     val cases_default = thm "case_split";
561     val local_impI = thm "induct_impliesI";
562     val conjI = thm "conjI";
563     val atomize = thms "induct_atomize";
564     val rulify1 = thms "induct_rulify1";
565     val rulify2 = thms "induct_rulify2";
566     val localize = [Thm.symmetric (thm "induct_implies_def")];
567   end);
568 *}
570 setup InductMethod.setup
573 subsection {* Order signatures and orders *}
575 axclass
576   ord < type
578 syntax
579   "op <"        :: "['a::ord, 'a] => bool"             ("op <")
580   "op <="       :: "['a::ord, 'a] => bool"             ("op <=")
582 global
584 consts
585   "op <"        :: "['a::ord, 'a] => bool"             ("(_/ < _)"  [50, 51] 50)
586   "op <="       :: "['a::ord, 'a] => bool"             ("(_/ <= _)" [50, 51] 50)
588 local
590 syntax (xsymbols)
591   "op <="       :: "['a::ord, 'a] => bool"             ("op \<le>")
592   "op <="       :: "['a::ord, 'a] => bool"             ("(_/ \<le> _)"  [50, 51] 50)
594 (*Tell blast about overloading of < and <= to reduce the risk of
595   its applying a rule for the wrong type*)
596 ML {*
597 Blast.overloaded ("op <" , domain_type);
598 Blast.overloaded ("op <=", domain_type);
599 *}
602 subsubsection {* Monotonicity *}
604 locale mono =
605   fixes f
606   assumes mono: "A <= B ==> f A <= f B"
608 lemmas monoI [intro?] = mono.intro [OF mono_axioms.intro]
609   and monoD [dest?] = mono.mono
611 lemma mono_def: "mono f == ALL A B. A <= B --> f A <= f B"
612   -- compatibility
613   by (simp only: atomize_eq mono_def mono_axioms_def)
616 constdefs
617   min :: "['a::ord, 'a] => 'a"
618   "min a b == (if a <= b then a else b)"
619   max :: "['a::ord, 'a] => 'a"
620   "max a b == (if a <= b then b else a)"
622 lemma min_leastL: "(!!x. least <= x) ==> min least x = least"
623   by (simp add: min_def)
625 lemma min_of_mono:
626     "ALL x y. (f x <= f y) = (x <= y) ==> min (f m) (f n) = f (min m n)"
627   by (simp add: min_def)
629 lemma max_leastL: "(!!x. least <= x) ==> max least x = x"
630   by (simp add: max_def)
632 lemma max_of_mono:
633     "ALL x y. (f x <= f y) = (x <= y) ==> max (f m) (f n) = f (max m n)"
634   by (simp add: max_def)
637 subsubsection "Orders"
639 axclass order < ord
640   order_refl [iff]: "x <= x"
641   order_trans: "x <= y ==> y <= z ==> x <= z"
642   order_antisym: "x <= y ==> y <= x ==> x = y"
643   order_less_le: "(x < y) = (x <= y & x ~= y)"
646 text {* Reflexivity. *}
648 lemma order_eq_refl: "!!x::'a::order. x = y ==> x <= y"
649     -- {* This form is useful with the classical reasoner. *}
650   apply (erule ssubst)
651   apply (rule order_refl)
652   done
654 lemma order_less_irrefl [simp]: "~ x < (x::'a::order)"
655   by (simp add: order_less_le)
657 lemma order_le_less: "((x::'a::order) <= y) = (x < y | x = y)"
658     -- {* NOT suitable for iff, since it can cause PROOF FAILED. *}
659   apply (simp add: order_less_le)
660   apply blast
661   done
663 lemmas order_le_imp_less_or_eq = order_le_less [THEN iffD1, standard]
665 lemma order_less_imp_le: "!!x::'a::order. x < y ==> x <= y"
666   by (simp add: order_less_le)
669 text {* Asymmetry. *}
671 lemma order_less_not_sym: "(x::'a::order) < y ==> ~ (y < x)"
672   by (simp add: order_less_le order_antisym)
674 lemma order_less_asym: "x < (y::'a::order) ==> (~P ==> y < x) ==> P"
675   apply (drule order_less_not_sym)
676   apply (erule contrapos_np)
677   apply simp
678   done
681 text {* Transitivity. *}
683 lemma order_less_trans: "!!x::'a::order. [| x < y; y < z |] ==> x < z"
684   apply (simp add: order_less_le)
685   apply (blast intro: order_trans order_antisym)
686   done
688 lemma order_le_less_trans: "!!x::'a::order. [| x <= y; y < z |] ==> x < z"
689   apply (simp add: order_less_le)
690   apply (blast intro: order_trans order_antisym)
691   done
693 lemma order_less_le_trans: "!!x::'a::order. [| x < y; y <= z |] ==> x < z"
694   apply (simp add: order_less_le)
695   apply (blast intro: order_trans order_antisym)
696   done
699 text {* Useful for simplification, but too risky to include by default. *}
701 lemma order_less_imp_not_less: "(x::'a::order) < y ==>  (~ y < x) = True"
702   by (blast elim: order_less_asym)
704 lemma order_less_imp_triv: "(x::'a::order) < y ==>  (y < x --> P) = True"
705   by (blast elim: order_less_asym)
707 lemma order_less_imp_not_eq: "(x::'a::order) < y ==>  (x = y) = False"
708   by auto
710 lemma order_less_imp_not_eq2: "(x::'a::order) < y ==>  (y = x) = False"
711   by auto
714 text {* Other operators. *}
716 lemma min_leastR: "(!!x::'a::order. least <= x) ==> min x least = least"
717   apply (simp add: min_def)
718   apply (blast intro: order_antisym)
719   done
721 lemma max_leastR: "(!!x::'a::order. least <= x) ==> max x least = x"
722   apply (simp add: max_def)
723   apply (blast intro: order_antisym)
724   done
727 subsubsection {* Least value operator *}
729 constdefs
730   Least :: "('a::ord => bool) => 'a"               (binder "LEAST " 10)
731   "Least P == THE x. P x & (ALL y. P y --> x <= y)"
732     -- {* We can no longer use LeastM because the latter requires Hilbert-AC. *}
734 lemma LeastI2:
735   "[| P (x::'a::order);
736       !!y. P y ==> x <= y;
737       !!x. [| P x; ALL y. P y --> x \<le> y |] ==> Q x |]
738    ==> Q (Least P)"
739   apply (unfold Least_def)
740   apply (rule theI2)
741     apply (blast intro: order_antisym)+
742   done
744 lemma Least_equality:
745     "[| P (k::'a::order); !!x. P x ==> k <= x |] ==> (LEAST x. P x) = k"
746   apply (simp add: Least_def)
747   apply (rule the_equality)
748   apply (auto intro!: order_antisym)
749   done
752 subsubsection "Linear / total orders"
754 axclass linorder < order
755   linorder_linear: "x <= y | y <= x"
757 lemma linorder_less_linear: "!!x::'a::linorder. x<y | x=y | y<x"
758   apply (simp add: order_less_le)
759   apply (insert linorder_linear)
760   apply blast
761   done
763 lemma linorder_cases [case_names less equal greater]:
764     "((x::'a::linorder) < y ==> P) ==> (x = y ==> P) ==> (y < x ==> P) ==> P"
765   apply (insert linorder_less_linear)
766   apply blast
767   done
769 lemma linorder_not_less: "!!x::'a::linorder. (~ x < y) = (y <= x)"
770   apply (simp add: order_less_le)
771   apply (insert linorder_linear)
772   apply (blast intro: order_antisym)
773   done
775 lemma linorder_not_le: "!!x::'a::linorder. (~ x <= y) = (y < x)"
776   apply (simp add: order_less_le)
777   apply (insert linorder_linear)
778   apply (blast intro: order_antisym)
779   done
781 lemma linorder_neq_iff: "!!x::'a::linorder. (x ~= y) = (x<y | y<x)"
782   apply (cut_tac x = x and y = y in linorder_less_linear)
783   apply auto
784   done
786 lemma linorder_neqE: "x ~= (y::'a::linorder) ==> (x < y ==> R) ==> (y < x ==> R) ==> R"
787   apply (simp add: linorder_neq_iff)
788   apply blast
789   done
792 subsubsection "Min and max on (linear) orders"
794 lemma min_same [simp]: "min (x::'a::order) x = x"
795   by (simp add: min_def)
797 lemma max_same [simp]: "max (x::'a::order) x = x"
798   by (simp add: max_def)
800 lemma le_max_iff_disj: "!!z::'a::linorder. (z <= max x y) = (z <= x | z <= y)"
801   apply (simp add: max_def)
802   apply (insert linorder_linear)
803   apply (blast intro: order_trans)
804   done
806 lemma le_maxI1: "(x::'a::linorder) <= max x y"
807   by (simp add: le_max_iff_disj)
809 lemma le_maxI2: "(y::'a::linorder) <= max x y"
810     -- {* CANNOT use with @{text "[intro!]"} because blast will give PROOF FAILED. *}
811   by (simp add: le_max_iff_disj)
813 lemma less_max_iff_disj: "!!z::'a::linorder. (z < max x y) = (z < x | z < y)"
814   apply (simp add: max_def order_le_less)
815   apply (insert linorder_less_linear)
816   apply (blast intro: order_less_trans)
817   done
819 lemma max_le_iff_conj [simp]:
820     "!!z::'a::linorder. (max x y <= z) = (x <= z & y <= z)"
821   apply (simp add: max_def)
822   apply (insert linorder_linear)
823   apply (blast intro: order_trans)
824   done
826 lemma max_less_iff_conj [simp]:
827     "!!z::'a::linorder. (max x y < z) = (x < z & y < z)"
828   apply (simp add: order_le_less max_def)
829   apply (insert linorder_less_linear)
830   apply (blast intro: order_less_trans)
831   done
833 lemma le_min_iff_conj [simp]:
834     "!!z::'a::linorder. (z <= min x y) = (z <= x & z <= y)"
835     -- {* @{text "[iff]"} screws up a @{text blast} in MiniML *}
836   apply (simp add: min_def)
837   apply (insert linorder_linear)
838   apply (blast intro: order_trans)
839   done
841 lemma min_less_iff_conj [simp]:
842     "!!z::'a::linorder. (z < min x y) = (z < x & z < y)"
843   apply (simp add: order_le_less min_def)
844   apply (insert linorder_less_linear)
845   apply (blast intro: order_less_trans)
846   done
848 lemma min_le_iff_disj: "!!z::'a::linorder. (min x y <= z) = (x <= z | y <= z)"
849   apply (simp add: min_def)
850   apply (insert linorder_linear)
851   apply (blast intro: order_trans)
852   done
854 lemma min_less_iff_disj: "!!z::'a::linorder. (min x y < z) = (x < z | y < z)"
855   apply (simp add: min_def order_le_less)
856   apply (insert linorder_less_linear)
857   apply (blast intro: order_less_trans)
858   done
860 lemma split_min:
861     "P (min (i::'a::linorder) j) = ((i <= j --> P(i)) & (~ i <= j --> P(j)))"
862   by (simp add: min_def)
864 lemma split_max:
865     "P (max (i::'a::linorder) j) = ((i <= j --> P(j)) & (~ i <= j --> P(i)))"
866   by (simp add: max_def)
869 subsubsection "Bounded quantifiers"
871 syntax
872   "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3ALL _<_./ _)"  [0, 0, 10] 10)
873   "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3EX _<_./ _)"  [0, 0, 10] 10)
874   "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3ALL _<=_./ _)" [0, 0, 10] 10)
875   "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3EX _<=_./ _)" [0, 0, 10] 10)
877 syntax (xsymbols)
878   "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_<_./ _)"  [0, 0, 10] 10)
879   "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_<_./ _)"  [0, 0, 10] 10)
880   "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<le>_./ _)" [0, 0, 10] 10)
881   "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<le>_./ _)" [0, 0, 10] 10)
883 syntax (HOL)
884   "_lessAll" :: "[idt, 'a, bool] => bool"   ("(3! _<_./ _)"  [0, 0, 10] 10)
885   "_lessEx"  :: "[idt, 'a, bool] => bool"   ("(3? _<_./ _)"  [0, 0, 10] 10)
886   "_leAll"   :: "[idt, 'a, bool] => bool"   ("(3! _<=_./ _)" [0, 0, 10] 10)
887   "_leEx"    :: "[idt, 'a, bool] => bool"   ("(3? _<=_./ _)" [0, 0, 10] 10)
889 translations
890  "ALL x<y. P"   =>  "ALL x. x < y --> P"
891  "EX x<y. P"    =>  "EX x. x < y  & P"
892  "ALL x<=y. P"  =>  "ALL x. x <= y --> P"
893  "EX x<=y. P"   =>  "EX x. x <= y & P"
895 end