nipkow@15524: (* Title: HOL/Orderings.thy nipkow@15524: ID: $Id$ nipkow@15524: Author: Tobias Nipkow, Markus Wenzel, and Larry Paulson nipkow@15524: *) nipkow@15524: haftmann@21083: header {* Abstract orderings *} nipkow@15524: nipkow@15524: theory Orderings haftmann@21216: imports Code_Generator nipkow@15524: begin nipkow@15524: haftmann@21083: section {* Abstract orderings *} haftmann@21083: haftmann@21083: subsection {* Order signatures *} nipkow@15524: haftmann@21194: class ord = haftmann@20588: fixes less_eq :: "'a \ 'a \ bool" wenzelm@21204: and less :: "'a \ 'a \ bool" wenzelm@21204: begin wenzelm@21204: wenzelm@21204: notation wenzelm@21204: less_eq ("op \<^loc><=") wenzelm@21204: less_eq ("(_/ \<^loc><= _)" [50, 51] 50) wenzelm@21204: less ("op \<^loc><") wenzelm@21204: less ("(_/ \<^loc>< _)" [50, 51] 50) wenzelm@21204: wenzelm@21204: notation (xsymbols) wenzelm@21204: less_eq ("op \<^loc>\") wenzelm@21204: less_eq ("(_/ \<^loc>\ _)" [50, 51] 50) nipkow@15524: wenzelm@21204: notation (HTML output) wenzelm@21204: less_eq ("op \<^loc>\") wenzelm@21204: less_eq ("(_/ \<^loc>\ _)" [50, 51] 50) wenzelm@21204: wenzelm@21204: abbreviation (input) wenzelm@21204: greater (infix "\<^loc>>" 50) wenzelm@21204: "x \<^loc>> y \ y \<^loc>< x" wenzelm@21204: greater_eq (infix "\<^loc>>=" 50) wenzelm@21204: "x \<^loc>>= y \ y \<^loc><= x" wenzelm@21204: wenzelm@21204: notation (xsymbols) wenzelm@21204: greater_eq (infixl "\<^loc>\" 50) wenzelm@21204: wenzelm@21204: end wenzelm@21204: wenzelm@21204: notation wenzelm@19656: less_eq ("op <=") wenzelm@19656: less_eq ("(_/ <= _)" [50, 51] 50) wenzelm@21204: less ("op <") wenzelm@21204: less ("(_/ < _)" [50, 51] 50) wenzelm@21204: wenzelm@21204: notation (xsymbols) wenzelm@19656: less_eq ("op \") wenzelm@19656: less_eq ("(_/ \ _)" [50, 51] 50) nipkow@15524: wenzelm@21204: notation (HTML output) wenzelm@21204: less_eq ("op \") wenzelm@21204: less_eq ("(_/ \ _)" [50, 51] 50) haftmann@20714: wenzelm@19536: abbreviation (input) wenzelm@19536: greater (infixl ">" 50) haftmann@20714: "x > y \ y < x" wenzelm@19536: greater_eq (infixl ">=" 50) haftmann@20714: "x >= y \ y <= x" haftmann@20714: wenzelm@21204: notation (xsymbols) wenzelm@19656: greater_eq (infixl "\" 50) nipkow@15524: nipkow@15524: haftmann@21083: subsection {* Partial orderings *} nipkow@15524: haftmann@21216: locale partial_order = haftmann@21216: fixes below :: "'a \ 'a \ bool" (infixl "\" 50) haftmann@21216: fixes less :: "'a \ 'a \ bool" (infixl "\" 50) haftmann@21216: assumes refl [iff]: "x \ x" haftmann@21216: and trans: "x \ y \ y \ z \ x \ z" haftmann@21216: and antisym: "x \ y \ y \ x \ x = y" haftmann@21216: and less_le: "(x \ y) = (x \ y \ x \ y)" haftmann@21216: nipkow@15524: axclass order < ord nipkow@15524: order_refl [iff]: "x <= x" nipkow@15524: order_trans: "x <= y ==> y <= z ==> x <= z" nipkow@15524: order_antisym: "x <= y ==> y <= x ==> x = y" nipkow@15524: order_less_le: "(x < y) = (x <= y & x ~= y)" nipkow@15524: ballarin@15837: interpretation order: haftmann@21216: partial_order ["op \ \ 'a\order \ 'a \ bool" "op < \ 'a\order \ 'a \ bool"] nipkow@15524: apply(rule partial_order.intro) haftmann@21216: apply(rule order_refl, erule (1) order_trans, erule (1) order_antisym, rule order_less_le) nipkow@15524: done nipkow@15524: nipkow@15524: text {* Reflexivity. *} nipkow@15524: haftmann@21216: lemma order_eq_refl: "(x \ 'a\order) = y \ x \ y" nipkow@15524: -- {* This form is useful with the classical reasoner. *} nipkow@15524: apply (erule ssubst) nipkow@15524: apply (rule order_refl) nipkow@15524: done nipkow@15524: nipkow@15524: lemma order_less_irrefl [iff]: "~ x < (x::'a::order)" nipkow@15524: by (simp add: order_less_le) nipkow@15524: nipkow@15524: lemma order_le_less: "((x::'a::order) <= y) = (x < y | x = y)" nipkow@15524: -- {* NOT suitable for iff, since it can cause PROOF FAILED. *} nipkow@15524: apply (simp add: order_less_le, blast) nipkow@15524: done nipkow@15524: nipkow@15524: lemmas order_le_imp_less_or_eq = order_le_less [THEN iffD1, standard] nipkow@15524: nipkow@15524: lemma order_less_imp_le: "!!x::'a::order. x < y ==> x <= y" nipkow@15524: by (simp add: order_less_le) nipkow@15524: nipkow@15524: text {* Asymmetry. *} nipkow@15524: nipkow@15524: lemma order_less_not_sym: "(x::'a::order) < y ==> ~ (y < x)" nipkow@15524: by (simp add: order_less_le order_antisym) nipkow@15524: nipkow@15524: lemma order_less_asym: "x < (y::'a::order) ==> (~P ==> y < x) ==> P" nipkow@15524: apply (drule order_less_not_sym) nipkow@15524: apply (erule contrapos_np, simp) nipkow@15524: done nipkow@15524: nipkow@15524: lemma order_eq_iff: "!!x::'a::order. (x = y) = (x \ y & y \ x)" nipkow@15524: by (blast intro: order_antisym) nipkow@15524: nipkow@15524: lemma order_antisym_conv: "(y::'a::order) <= x ==> (x <= y) = (x = y)" nipkow@15524: by(blast intro:order_antisym) nipkow@15524: haftmann@21083: lemma less_imp_neq: "[| (x::'a::order) < y |] ==> x ~= y" haftmann@21083: by (erule contrapos_pn, erule subst, rule order_less_irrefl) haftmann@21083: nipkow@15524: text {* Transitivity. *} nipkow@15524: nipkow@15524: lemma order_less_trans: "!!x::'a::order. [| x < y; y < z |] ==> x < z" nipkow@15524: apply (simp add: order_less_le) nipkow@15524: apply (blast intro: order_trans order_antisym) nipkow@15524: done nipkow@15524: nipkow@15524: lemma order_le_less_trans: "!!x::'a::order. [| x <= y; y < z |] ==> x < z" nipkow@15524: apply (simp add: order_less_le) nipkow@15524: apply (blast intro: order_trans order_antisym) nipkow@15524: done nipkow@15524: nipkow@15524: lemma order_less_le_trans: "!!x::'a::order. [| x < y; y <= z |] ==> x < z" nipkow@15524: apply (simp add: order_less_le) nipkow@15524: apply (blast intro: order_trans order_antisym) nipkow@15524: done nipkow@15524: haftmann@21083: lemma eq_neq_eq_imp_neq: "[| x = a ; a ~= b; b = y |] ==> x ~= y" haftmann@21083: by (erule subst, erule ssubst, assumption) nipkow@15524: nipkow@15524: text {* Useful for simplification, but too risky to include by default. *} nipkow@15524: nipkow@15524: lemma order_less_imp_not_less: "(x::'a::order) < y ==> (~ y < x) = True" nipkow@15524: by (blast elim: order_less_asym) nipkow@15524: nipkow@15524: lemma order_less_imp_triv: "(x::'a::order) < y ==> (y < x --> P) = True" nipkow@15524: by (blast elim: order_less_asym) nipkow@15524: nipkow@15524: lemma order_less_imp_not_eq: "(x::'a::order) < y ==> (x = y) = False" nipkow@15524: by auto nipkow@15524: nipkow@15524: lemma order_less_imp_not_eq2: "(x::'a::order) < y ==> (y = x) = False" nipkow@15524: by auto nipkow@15524: haftmann@21083: text {* Transitivity rules for calculational reasoning *} nipkow@15524: nipkow@15524: lemma order_neq_le_trans: "a ~= b ==> (a::'a::order) <= b ==> a < b" nipkow@15524: by (simp add: order_less_le) nipkow@15524: nipkow@15524: lemma order_le_neq_trans: "(a::'a::order) <= b ==> a ~= b ==> a < b" nipkow@15524: by (simp add: order_less_le) nipkow@15524: nipkow@15524: lemma order_less_asym': "(a::'a::order) < b ==> b < a ==> P" nipkow@15524: by (rule order_less_asym) nipkow@15524: nipkow@15524: haftmann@21216: subsection {* Linear (total) orderings *} haftmann@21216: haftmann@21216: locale linear_order = partial_order + haftmann@21216: assumes linear: "x \ y \ y \ x" nipkow@15524: nipkow@15524: axclass linorder < order nipkow@15524: linorder_linear: "x <= y | y <= x" nipkow@15524: haftmann@21216: interpretation linorder: haftmann@21216: linear_order ["op \ \ 'a\linorder \ 'a \ bool" "op < \ 'a\linorder \ 'a \ bool"] haftmann@21216: by unfold_locales (rule linorder_linear) haftmann@21216: nipkow@15524: lemma linorder_less_linear: "!!x::'a::linorder. xy | y y ==> P) ==> (y \ x ==> P) ==> P" nipkow@15524: by (insert linorder_linear, blast) nipkow@15524: nipkow@15524: lemma linorder_cases [case_names less equal greater]: nipkow@15524: "((x::'a::linorder) < y ==> P) ==> (x = y ==> P) ==> (y < x ==> P) ==> P" nipkow@15524: by (insert linorder_less_linear, blast) nipkow@15524: nipkow@15524: lemma linorder_not_less: "!!x::'a::linorder. (~ x < y) = (y <= x)" nipkow@15524: apply (simp add: order_less_le) nipkow@15524: apply (insert linorder_linear) nipkow@15524: apply (blast intro: order_antisym) nipkow@15524: done nipkow@15524: nipkow@15524: lemma linorder_not_le: "!!x::'a::linorder. (~ x <= y) = (y < x)" nipkow@15524: apply (simp add: order_less_le) nipkow@15524: apply (insert linorder_linear) nipkow@15524: apply (blast intro: order_antisym) nipkow@15524: done nipkow@15524: nipkow@15524: lemma linorder_neq_iff: "!!x::'a::linorder. (x ~= y) = (x (x < y ==> R) ==> (y < x ==> R) ==> R" nipkow@15524: by (simp add: linorder_neq_iff, blast) nipkow@15524: nipkow@15524: lemma linorder_antisym_conv1: "~ (x::'a::linorder) < y ==> (x <= y) = (x = y)" nipkow@15524: by(blast intro:order_antisym dest:linorder_not_less[THEN iffD1]) nipkow@15524: nipkow@15524: lemma linorder_antisym_conv2: "(x::'a::linorder) <= y ==> (~ x < y) = (x = y)" nipkow@15524: by(blast intro:order_antisym dest:linorder_not_less[THEN iffD1]) nipkow@15524: nipkow@15524: lemma linorder_antisym_conv3: "~ (y::'a::linorder) < x ==> (~ x < y) = (x = y)" nipkow@15524: by(blast intro:order_antisym dest:linorder_not_less[THEN iffD1]) nipkow@15524: paulson@16796: text{*Replacing the old Nat.leI*} paulson@16796: lemma leI: "~ x < y ==> y <= (x::'a::linorder)" paulson@16796: by (simp only: linorder_not_less) paulson@16796: paulson@16796: lemma leD: "y <= (x::'a::linorder) ==> ~ x < y" paulson@16796: by (simp only: linorder_not_less) paulson@16796: paulson@16796: (*FIXME inappropriate name (or delete altogether)*) paulson@16796: lemma not_leE: "~ y <= (x::'a::linorder) ==> x < y" paulson@16796: by (simp only: linorder_not_le) paulson@16796: haftmann@21083: haftmann@21083: subsection {* Reasoning tools setup *} haftmann@21083: haftmann@21091: ML {* haftmann@21091: local haftmann@21091: haftmann@21091: fun decomp_gen sort thy (Trueprop $ t) = haftmann@21091: let fun of_sort t = let val T = type_of t in haftmann@21091: (* exclude numeric types: linear arithmetic subsumes transitivity *) haftmann@21091: T <> HOLogic.natT andalso T <> HOLogic.intT andalso haftmann@21091: T <> HOLogic.realT andalso Sign.of_sort thy (T, sort) end haftmann@21091: fun dec (Const ("Not", _) $ t) = ( haftmann@21091: case dec t of haftmann@21091: NONE => NONE haftmann@21091: | SOME (t1, rel, t2) => SOME (t1, "~" ^ rel, t2)) haftmann@21091: | dec (Const ("op =", _) $ t1 $ t2) = haftmann@21091: if of_sort t1 haftmann@21091: then SOME (t1, "=", t2) haftmann@21091: else NONE haftmann@21091: | dec (Const ("Orderings.less_eq", _) $ t1 $ t2) = haftmann@21091: if of_sort t1 haftmann@21091: then SOME (t1, "<=", t2) haftmann@21091: else NONE haftmann@21091: | dec (Const ("Orderings.less", _) $ t1 $ t2) = haftmann@21091: if of_sort t1 haftmann@21091: then SOME (t1, "<", t2) haftmann@21091: else NONE haftmann@21091: | dec _ = NONE haftmann@21091: in dec t end; haftmann@21091: haftmann@21091: in haftmann@21091: haftmann@21091: structure Quasi_Tac = Quasi_Tac_Fun ( haftmann@21091: (* The setting up of Quasi_Tac serves as a demo. Since there is no haftmann@21091: class for quasi orders, the tactics Quasi_Tac.trans_tac and haftmann@21091: Quasi_Tac.quasi_tac are not of much use. *) haftmann@21091: struct haftmann@21091: val le_trans = thm "order_trans"; haftmann@21091: val le_refl = thm "order_refl"; haftmann@21091: val eqD1 = thm "order_eq_refl"; haftmann@21091: val eqD2 = thm "sym" RS thm "order_eq_refl"; haftmann@21091: val less_reflE = thm "order_less_irrefl" RS thm "notE"; haftmann@21091: val less_imp_le = thm "order_less_imp_le"; haftmann@21091: val le_neq_trans = thm "order_le_neq_trans"; haftmann@21091: val neq_le_trans = thm "order_neq_le_trans"; haftmann@21091: val less_imp_neq = thm "less_imp_neq"; haftmann@21091: val decomp_trans = decomp_gen ["Orderings.order"]; haftmann@21091: val decomp_quasi = decomp_gen ["Orderings.order"]; haftmann@21091: haftmann@21091: end); haftmann@21091: haftmann@21091: structure Order_Tac = Order_Tac_Fun ( haftmann@21091: struct haftmann@21091: val less_reflE = thm "order_less_irrefl" RS thm "notE"; haftmann@21091: val le_refl = thm "order_refl"; haftmann@21091: val less_imp_le = thm "order_less_imp_le"; haftmann@21091: val not_lessI = thm "linorder_not_less" RS thm "iffD2"; haftmann@21091: val not_leI = thm "linorder_not_le" RS thm "iffD2"; haftmann@21091: val not_lessD = thm "linorder_not_less" RS thm "iffD1"; haftmann@21091: val not_leD = thm "linorder_not_le" RS thm "iffD1"; haftmann@21091: val eqI = thm "order_antisym"; haftmann@21091: val eqD1 = thm "order_eq_refl"; haftmann@21091: val eqD2 = thm "sym" RS thm "order_eq_refl"; haftmann@21091: val less_trans = thm "order_less_trans"; haftmann@21091: val less_le_trans = thm "order_less_le_trans"; haftmann@21091: val le_less_trans = thm "order_le_less_trans"; haftmann@21091: val le_trans = thm "order_trans"; haftmann@21091: val le_neq_trans = thm "order_le_neq_trans"; haftmann@21091: val neq_le_trans = thm "order_neq_le_trans"; haftmann@21091: val less_imp_neq = thm "less_imp_neq"; haftmann@21091: val eq_neq_eq_imp_neq = thm "eq_neq_eq_imp_neq"; haftmann@21091: val not_sym = thm "not_sym"; haftmann@21091: val decomp_part = decomp_gen ["Orderings.order"]; haftmann@21091: val decomp_lin = decomp_gen ["Orderings.linorder"]; haftmann@21091: haftmann@21091: end); haftmann@21091: haftmann@21091: end; haftmann@21091: *} haftmann@21091: haftmann@21083: setup {* haftmann@21083: let haftmann@21083: haftmann@21083: val order_antisym_conv = thm "order_antisym_conv" haftmann@21083: val linorder_antisym_conv1 = thm "linorder_antisym_conv1" haftmann@21083: val linorder_antisym_conv2 = thm "linorder_antisym_conv2" haftmann@21083: val linorder_antisym_conv3 = thm "linorder_antisym_conv3" haftmann@21083: haftmann@21083: fun prp t thm = (#prop (rep_thm thm) = t); nipkow@15524: haftmann@21083: fun prove_antisym_le sg ss ((le as Const(_,T)) $ r $ s) = haftmann@21083: let val prems = prems_of_ss ss; haftmann@21083: val less = Const("Orderings.less",T); haftmann@21083: val t = HOLogic.mk_Trueprop(le $ s $ r); haftmann@21083: in case find_first (prp t) prems of haftmann@21083: NONE => haftmann@21083: let val t = HOLogic.mk_Trueprop(HOLogic.Not $ (less $ r $ s)) haftmann@21083: in case find_first (prp t) prems of haftmann@21083: NONE => NONE haftmann@21083: | SOME thm => SOME(mk_meta_eq(thm RS linorder_antisym_conv1)) haftmann@21083: end haftmann@21083: | SOME thm => SOME(mk_meta_eq(thm RS order_antisym_conv)) haftmann@21083: end haftmann@21083: handle THM _ => NONE; nipkow@15524: haftmann@21083: fun prove_antisym_less sg ss (NotC $ ((less as Const(_,T)) $ r $ s)) = haftmann@21083: let val prems = prems_of_ss ss; haftmann@21083: val le = Const("Orderings.less_eq",T); haftmann@21083: val t = HOLogic.mk_Trueprop(le $ r $ s); haftmann@21083: in case find_first (prp t) prems of haftmann@21083: NONE => haftmann@21083: let val t = HOLogic.mk_Trueprop(NotC $ (less $ s $ r)) haftmann@21083: in case find_first (prp t) prems of haftmann@21083: NONE => NONE haftmann@21083: | SOME thm => SOME(mk_meta_eq(thm RS linorder_antisym_conv3)) haftmann@21083: end haftmann@21083: | SOME thm => SOME(mk_meta_eq(thm RS linorder_antisym_conv2)) haftmann@21083: end haftmann@21083: handle THM _ => NONE; nipkow@15524: haftmann@21083: val antisym_le = Simplifier.simproc (the_context()) haftmann@21083: "antisym le" ["(x::'a::order) <= y"] prove_antisym_le; haftmann@21083: val antisym_less = Simplifier.simproc (the_context()) haftmann@21083: "antisym less" ["~ (x::'a::linorder) < y"] prove_antisym_less; haftmann@21083: haftmann@21083: in haftmann@21091: (fn thy => (Simplifier.change_simpset_of thy haftmann@21091: (fn ss => ss haftmann@21091: addsimprocs [antisym_le, antisym_less] haftmann@21091: addSolver (mk_solver "Trans_linear" (fn _ => Order_Tac.linear_tac)) haftmann@21091: addSolver (mk_solver "Trans_partial" (fn _ => Order_Tac.partial_tac))) haftmann@21091: (* Adding the transitivity reasoners also as safe solvers showed a slight haftmann@21091: speed up, but the reasoning strength appears to be not higher (at least haftmann@21091: no breaking of additional proofs in the entire HOL distribution, as haftmann@21091: of 5 March 2004, was observed). *); thy)) haftmann@21083: end haftmann@21083: *} nipkow@15524: nipkow@15524: haftmann@21083: subsection {* Bounded quantifiers *} haftmann@21083: haftmann@21083: syntax wenzelm@21180: "_All_less" :: "[idt, 'a, bool] => bool" ("(3ALL _<_./ _)" [0, 0, 10] 10) wenzelm@21180: "_Ex_less" :: "[idt, 'a, bool] => bool" ("(3EX _<_./ _)" [0, 0, 10] 10) wenzelm@21180: "_All_less_eq" :: "[idt, 'a, bool] => bool" ("(3ALL _<=_./ _)" [0, 0, 10] 10) wenzelm@21180: "_Ex_less_eq" :: "[idt, 'a, bool] => bool" ("(3EX _<=_./ _)" [0, 0, 10] 10) haftmann@21083: wenzelm@21180: "_All_greater" :: "[idt, 'a, bool] => bool" ("(3ALL _>_./ _)" [0, 0, 10] 10) wenzelm@21180: "_Ex_greater" :: "[idt, 'a, bool] => bool" ("(3EX _>_./ _)" [0, 0, 10] 10) wenzelm@21180: "_All_greater_eq" :: "[idt, 'a, bool] => bool" ("(3ALL _>=_./ _)" [0, 0, 10] 10) wenzelm@21180: "_Ex_greater_eq" :: "[idt, 'a, bool] => bool" ("(3EX _>=_./ _)" [0, 0, 10] 10) haftmann@21083: haftmann@21083: syntax (xsymbols) wenzelm@21180: "_All_less" :: "[idt, 'a, bool] => bool" ("(3\_<_./ _)" [0, 0, 10] 10) wenzelm@21180: "_Ex_less" :: "[idt, 'a, bool] => bool" ("(3\_<_./ _)" [0, 0, 10] 10) wenzelm@21180: "_All_less_eq" :: "[idt, 'a, bool] => bool" ("(3\_\_./ _)" [0, 0, 10] 10) wenzelm@21180: "_Ex_less_eq" :: "[idt, 'a, bool] => bool" ("(3\_\_./ _)" [0, 0, 10] 10) haftmann@21083: wenzelm@21180: "_All_greater" :: "[idt, 'a, bool] => bool" ("(3\_>_./ _)" [0, 0, 10] 10) wenzelm@21180: "_Ex_greater" :: "[idt, 'a, bool] => bool" ("(3\_>_./ _)" [0, 0, 10] 10) wenzelm@21180: "_All_greater_eq" :: "[idt, 'a, bool] => bool" ("(3\_\_./ _)" [0, 0, 10] 10) wenzelm@21180: "_Ex_greater_eq" :: "[idt, 'a, bool] => bool" ("(3\_\_./ _)" [0, 0, 10] 10) haftmann@21083: haftmann@21083: syntax (HOL) wenzelm@21180: "_All_less" :: "[idt, 'a, bool] => bool" ("(3! _<_./ _)" [0, 0, 10] 10) wenzelm@21180: "_Ex_less" :: "[idt, 'a, bool] => bool" ("(3? _<_./ _)" [0, 0, 10] 10) wenzelm@21180: "_All_less_eq" :: "[idt, 'a, bool] => bool" ("(3! _<=_./ _)" [0, 0, 10] 10) wenzelm@21180: "_Ex_less_eq" :: "[idt, 'a, bool] => bool" ("(3? _<=_./ _)" [0, 0, 10] 10) haftmann@21083: haftmann@21083: syntax (HTML output) wenzelm@21180: "_All_less" :: "[idt, 'a, bool] => bool" ("(3\_<_./ _)" [0, 0, 10] 10) wenzelm@21180: "_Ex_less" :: "[idt, 'a, bool] => bool" ("(3\_<_./ _)" [0, 0, 10] 10) wenzelm@21180: "_All_less_eq" :: "[idt, 'a, bool] => bool" ("(3\_\_./ _)" [0, 0, 10] 10) wenzelm@21180: "_Ex_less_eq" :: "[idt, 'a, bool] => bool" ("(3\_\_./ _)" [0, 0, 10] 10) haftmann@21083: wenzelm@21180: "_All_greater" :: "[idt, 'a, bool] => bool" ("(3\_>_./ _)" [0, 0, 10] 10) wenzelm@21180: "_Ex_greater" :: "[idt, 'a, bool] => bool" ("(3\_>_./ _)" [0, 0, 10] 10) wenzelm@21180: "_All_greater_eq" :: "[idt, 'a, bool] => bool" ("(3\_\_./ _)" [0, 0, 10] 10) wenzelm@21180: "_Ex_greater_eq" :: "[idt, 'a, bool] => bool" ("(3\_\_./ _)" [0, 0, 10] 10) haftmann@21083: haftmann@21083: translations haftmann@21083: "ALL x "ALL x. x < y \ P" haftmann@21083: "EX x "EX x. x < y \ P" haftmann@21083: "ALL x<=y. P" => "ALL x. x <= y \ P" haftmann@21083: "EX x<=y. P" => "EX x. x <= y \ P" haftmann@21083: "ALL x>y. P" => "ALL x. x > y \ P" haftmann@21083: "EX x>y. P" => "EX x. x > y \ P" haftmann@21083: "ALL x>=y. P" => "ALL x. x >= y \ P" haftmann@21083: "EX x>=y. P" => "EX x. x >= y \ P" haftmann@21083: haftmann@21083: print_translation {* haftmann@21083: let wenzelm@21180: val syntax_name = Sign.const_syntax_name (the_context ()); wenzelm@21180: val impl = syntax_name "op -->"; wenzelm@21180: val conj = syntax_name "op &"; wenzelm@21180: val less = syntax_name "Orderings.less"; wenzelm@21180: val less_eq = syntax_name "Orderings.less_eq"; wenzelm@21180: wenzelm@21180: val trans = wenzelm@21180: [(("ALL ", impl, less), ("_All_less", "_All_greater")), wenzelm@21180: (("ALL ", impl, less_eq), ("_All_less_eq", "_All_greater_eq")), wenzelm@21180: (("EX ", conj, less), ("_Ex_less", "_Ex_greater")), wenzelm@21180: (("EX ", conj, less_eq), ("_Ex_less_eq", "_Ex_greater_eq"))]; wenzelm@21180: haftmann@21083: fun mk v v' c n P = wenzelm@21180: if v = v' andalso not (Term.exists_subterm (fn Free (x, _) => x = v | _ => false) n) haftmann@21083: then Syntax.const c $ Syntax.mark_bound v' $ n $ P else raise Match; wenzelm@21180: wenzelm@21180: fun tr' q = (q, wenzelm@21180: fn [Const ("_bound", _) $ Free (v, _), Const (c, _) $ (Const (d, _) $ t $ u) $ P] => wenzelm@21180: (case AList.lookup (op =) trans (q, c, d) of wenzelm@21180: NONE => raise Match wenzelm@21180: | SOME (l, g) => wenzelm@21180: (case (t, u) of wenzelm@21180: (Const ("_bound", _) $ Free (v', _), n) => mk v v' l n P wenzelm@21180: | (n, Const ("_bound", _) $ Free (v', _)) => mk v v' g n P wenzelm@21180: | _ => raise Match)) wenzelm@21180: | _ => raise Match); wenzelm@21180: in [tr' "ALL ", tr' "EX "] end haftmann@21083: *} haftmann@21083: haftmann@21083: haftmann@21083: subsection {* Transitivity reasoning on decreasing inequalities *} haftmann@21083: wenzelm@21180: (* FIXME cleanup *) wenzelm@21180: haftmann@21083: text {* These support proving chains of decreasing inequalities haftmann@21083: a >= b >= c ... in Isar proofs. *} haftmann@21083: haftmann@21083: lemma xt1: haftmann@21083: "a = b ==> b > c ==> a > c" haftmann@21083: "a > b ==> b = c ==> a > c" haftmann@21083: "a = b ==> b >= c ==> a >= c" haftmann@21083: "a >= b ==> b = c ==> a >= c" haftmann@21083: "(x::'a::order) >= y ==> y >= x ==> x = y" haftmann@21083: "(x::'a::order) >= y ==> y >= z ==> x >= z" haftmann@21083: "(x::'a::order) > y ==> y >= z ==> x > z" haftmann@21083: "(x::'a::order) >= y ==> y > z ==> x > z" haftmann@21083: "(a::'a::order) > b ==> b > a ==> ?P" haftmann@21083: "(x::'a::order) > y ==> y > z ==> x > z" haftmann@21083: "(a::'a::order) >= b ==> a ~= b ==> a > b" haftmann@21083: "(a::'a::order) ~= b ==> a >= b ==> a > b" haftmann@21083: "a = f b ==> b > c ==> (!!x y. x > y ==> f x > f y) ==> a > f c" haftmann@21083: "a > b ==> f b = c ==> (!!x y. x > y ==> f x > f y) ==> f a > c" haftmann@21083: "a = f b ==> b >= c ==> (!!x y. x >= y ==> f x >= f y) ==> a >= f c" haftmann@21083: "a >= b ==> f b = c ==> (!! x y. x >= y ==> f x >= f y) ==> f a >= c" haftmann@21083: by auto haftmann@21083: haftmann@21083: lemma xt2: haftmann@21083: "(a::'a::order) >= f b ==> b >= c ==> (!!x y. x >= y ==> f x >= f y) ==> a >= f c" haftmann@21083: by (subgoal_tac "f b >= f c", force, force) haftmann@21083: haftmann@21083: lemma xt3: "(a::'a::order) >= b ==> (f b::'b::order) >= c ==> haftmann@21083: (!!x y. x >= y ==> f x >= f y) ==> f a >= c" haftmann@21083: by (subgoal_tac "f a >= f b", force, force) haftmann@21083: haftmann@21083: lemma xt4: "(a::'a::order) > f b ==> (b::'b::order) >= c ==> haftmann@21083: (!!x y. x >= y ==> f x >= f y) ==> a > f c" haftmann@21083: by (subgoal_tac "f b >= f c", force, force) haftmann@21083: haftmann@21083: lemma xt5: "(a::'a::order) > b ==> (f b::'b::order) >= c==> haftmann@21083: (!!x y. x > y ==> f x > f y) ==> f a > c" haftmann@21083: by (subgoal_tac "f a > f b", force, force) haftmann@21083: haftmann@21083: lemma xt6: "(a::'a::order) >= f b ==> b > c ==> haftmann@21083: (!!x y. x > y ==> f x > f y) ==> a > f c" haftmann@21083: by (subgoal_tac "f b > f c", force, force) haftmann@21083: haftmann@21083: lemma xt7: "(a::'a::order) >= b ==> (f b::'b::order) > c ==> haftmann@21083: (!!x y. x >= y ==> f x >= f y) ==> f a > c" haftmann@21083: by (subgoal_tac "f a >= f b", force, force) haftmann@21083: haftmann@21083: lemma xt8: "(a::'a::order) > f b ==> (b::'b::order) > c ==> haftmann@21083: (!!x y. x > y ==> f x > f y) ==> a > f c" haftmann@21083: by (subgoal_tac "f b > f c", force, force) haftmann@21083: haftmann@21083: lemma xt9: "(a::'a::order) > b ==> (f b::'b::order) > c ==> haftmann@21083: (!!x y. x > y ==> f x > f y) ==> f a > c" haftmann@21083: by (subgoal_tac "f a > f b", force, force) haftmann@21083: haftmann@21083: lemmas xtrans = xt1 xt2 xt3 xt4 xt5 xt6 xt7 xt8 xt9 haftmann@21083: haftmann@21083: (* haftmann@21083: Since "a >= b" abbreviates "b <= a", the abbreviation "..." stands haftmann@21083: for the wrong thing in an Isar proof. haftmann@21083: haftmann@21083: The extra transitivity rules can be used as follows: haftmann@21083: haftmann@21083: lemma "(a::'a::order) > z" haftmann@21083: proof - haftmann@21083: have "a >= b" (is "_ >= ?rhs") haftmann@21083: sorry haftmann@21083: also have "?rhs >= c" (is "_ >= ?rhs") haftmann@21083: sorry haftmann@21083: also (xtrans) have "?rhs = d" (is "_ = ?rhs") haftmann@21083: sorry haftmann@21083: also (xtrans) have "?rhs >= e" (is "_ >= ?rhs") haftmann@21083: sorry haftmann@21083: also (xtrans) have "?rhs > f" (is "_ > ?rhs") haftmann@21083: sorry haftmann@21083: also (xtrans) have "?rhs > z" haftmann@21083: sorry haftmann@21083: finally (xtrans) show ?thesis . haftmann@21083: qed haftmann@21083: haftmann@21083: Alternatively, one can use "declare xtrans [trans]" and then haftmann@21083: leave out the "(xtrans)" above. haftmann@21083: *) haftmann@21083: haftmann@21216: subsection {* Monotonicity, syntactic least value operator and syntactic min/max *} haftmann@21083: haftmann@21216: locale mono = haftmann@21216: fixes f haftmann@21216: assumes mono: "A \ B \ f A \ f B" haftmann@21216: haftmann@21216: lemmas monoI [intro?] = mono.intro haftmann@21216: and monoD [dest?] = mono.mono haftmann@21083: haftmann@21083: constdefs haftmann@21083: Least :: "('a::ord => bool) => 'a" (binder "LEAST " 10) haftmann@21083: "Least P == THE x. P x & (ALL y. P y --> x <= y)" haftmann@21083: -- {* We can no longer use LeastM because the latter requires Hilbert-AC. *} haftmann@21083: haftmann@21083: constdefs haftmann@21083: min :: "['a::ord, 'a] => 'a" haftmann@21083: "min a b == (if a <= b then a else b)" haftmann@21083: max :: "['a::ord, 'a] => 'a" haftmann@21083: "max a b == (if a <= b then b else a)" haftmann@21083: nipkow@15524: end