# HG changeset patch # User haftmann # Date 1163011714 -3600 # Node ID d594c58e24ed9e95b56dda3de7df6c7952886a40 # Parent 3fd22b0939ffdf898ae87886a69143a4aa4222f2 renamed Lattice_Locales to Lattices diff -r 3fd22b0939ff -r d594c58e24ed src/HOL/Finite_Set.thy --- a/src/HOL/Finite_Set.thy Wed Nov 08 19:46:10 2006 +0100 +++ b/src/HOL/Finite_Set.thy Wed Nov 08 19:48:34 2006 +0100 @@ -7,7 +7,7 @@ header {* Finite sets *} theory Finite_Set -imports Power Inductive Lattice_Locales +imports Power Inductive Lattices begin subsection {* Definition and basic properties *} diff -r 3fd22b0939ff -r d594c58e24ed src/HOL/IsaMakefile --- a/src/HOL/IsaMakefile Wed Nov 08 19:46:10 2006 +0100 +++ b/src/HOL/IsaMakefile Wed Nov 08 19:48:34 2006 +0100 @@ -94,7 +94,7 @@ Integ/cooper_proof.ML Integ/reflected_presburger.ML \ Integ/reflected_cooper.ML Integ/int_arith1.ML Integ/int_factor_simprocs.ML \ Integ/nat_simprocs.ML Integ/presburger.ML Integ/qelim.ML LOrder.thy \ - Lattice_Locales.thy List.ML List.thy Main.thy Map.thy \ + Lattices.thy List.ML List.thy Main.thy Map.thy \ Nat.ML Nat.thy OrderedGroup.ML OrderedGroup.thy \ Orderings.ML Orderings.thy Power.thy PreList.thy Product_Type.thy \ ROOT.ML Recdef.thy Reconstruction.thy Record.thy Refute.thy \ diff -r 3fd22b0939ff -r d594c58e24ed src/HOL/LOrder.thy --- a/src/HOL/LOrder.thy Wed Nov 08 19:46:10 2006 +0100 +++ b/src/HOL/LOrder.thy Wed Nov 08 19:48:34 2006 +0100 @@ -6,7 +6,7 @@ header {* Lattice Orders *} theory LOrder -imports Lattice_Locales +imports Lattices begin text {* diff -r 3fd22b0939ff -r d594c58e24ed src/HOL/Lattice_Locales.thy --- a/src/HOL/Lattice_Locales.thy Wed Nov 08 19:46:10 2006 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,336 +0,0 @@ -(* Title: HOL/Lattices.thy - ID: $Id$ - Author: Tobias Nipkow -*) - -header {* Lattices via Locales *} - -theory Lattice_Locales -imports Orderings -begin - -subsection{* Lattices *} - -text{* This theory of lattice locales only defines binary sup and inf -operations. The extension to finite sets is done in theory @{text -Finite_Set}. In the longer term it may be better to define arbitrary -sups and infs via @{text THE}. *} - -locale lower_semilattice = partial_order + - fixes inf :: "'a \ 'a \ 'a" (infixl "\" 70) - assumes inf_le1: "x \ y \ x" and inf_le2: "x \ y \ y" - and inf_least: "x \ y \ x \ z \ x \ y \ z" - -locale upper_semilattice = partial_order + - fixes sup :: "'a \ 'a \ 'a" (infixl "\" 65) - assumes sup_ge1: "x \ x \ y" and sup_ge2: "y \ x \ y" - and sup_greatest: "y \ x \ z \ x \ y \ z \ x" - -locale lattice = lower_semilattice + upper_semilattice - -lemma (in lower_semilattice) inf_commute: "(x \ y) = (y \ x)" -by(blast intro: antisym inf_le1 inf_le2 inf_least) - -lemma (in upper_semilattice) sup_commute: "(x \ y) = (y \ x)" -by(blast intro: antisym sup_ge1 sup_ge2 sup_greatest) - -lemma (in lower_semilattice) inf_assoc: "(x \ y) \ z = x \ (y \ z)" -by(blast intro: antisym inf_le1 inf_le2 inf_least trans del:refl) - -lemma (in upper_semilattice) sup_assoc: "(x \ y) \ z = x \ (y \ z)" -by(blast intro!: antisym sup_ge1 sup_ge2 intro: sup_greatest trans del:refl) - -lemma (in lower_semilattice) inf_idem[simp]: "x \ x = x" -by(blast intro: antisym inf_le1 inf_le2 inf_least refl) - -lemma (in upper_semilattice) sup_idem[simp]: "x \ x = x" -by(blast intro: antisym sup_ge1 sup_ge2 sup_greatest refl) - -lemma (in lower_semilattice) inf_left_idem[simp]: "x \ (x \ y) = x \ y" -by (simp add: inf_assoc[symmetric]) - -lemma (in upper_semilattice) sup_left_idem[simp]: "x \ (x \ y) = x \ y" -by (simp add: sup_assoc[symmetric]) - -lemma (in lattice) inf_sup_absorb: "x \ (x \ y) = x" -by(blast intro: antisym inf_le1 inf_least sup_ge1) - -lemma (in lattice) sup_inf_absorb: "x \ (x \ y) = x" -by(blast intro: antisym sup_ge1 sup_greatest inf_le1) - -lemma (in lower_semilattice) inf_absorb: "x \ y \ x \ y = x" -by(blast intro: antisym inf_le1 inf_least refl) - -lemma (in upper_semilattice) sup_absorb: "x \ y \ x \ y = y" -by(blast intro: antisym sup_ge2 sup_greatest refl) - - -lemma (in lower_semilattice) less_eq_inf_conv [simp]: - "x \ y \ z = (x \ y \ x \ z)" -by(blast intro: antisym inf_le1 inf_le2 inf_least refl trans) - -lemmas (in lower_semilattice) below_inf_conv = less_eq_inf_conv - -- {* a duplicate for backward compatibility *} - -lemma (in upper_semilattice) above_sup_conv[simp]: - "x \ y \ z = (x \ z \ y \ z)" -by(blast intro: antisym sup_ge1 sup_ge2 sup_greatest refl trans) - - -text{* Towards distributivity: if you have one of them, you have them all. *} - -lemma (in lattice) distrib_imp1: -assumes D: "!!x y z. x \ (y \ z) = (x \ y) \ (x \ z)" -shows "x \ (y \ z) = (x \ y) \ (x \ z)" -proof- - have "x \ (y \ z) = (x \ (x \ z)) \ (y \ z)" by(simp add:sup_inf_absorb) - also have "\ = x \ (z \ (x \ y))" by(simp add:D inf_commute sup_assoc) - also have "\ = ((x \ y) \ x) \ ((x \ y) \ z)" - by(simp add:inf_sup_absorb inf_commute) - also have "\ = (x \ y) \ (x \ z)" by(simp add:D) - finally show ?thesis . -qed - -lemma (in lattice) distrib_imp2: -assumes D: "!!x y z. x \ (y \ z) = (x \ y) \ (x \ z)" -shows "x \ (y \ z) = (x \ y) \ (x \ z)" -proof- - have "x \ (y \ z) = (x \ (x \ z)) \ (y \ z)" by(simp add:inf_sup_absorb) - also have "\ = x \ (z \ (x \ y))" by(simp add:D sup_commute inf_assoc) - also have "\ = ((x \ y) \ x) \ ((x \ y) \ z)" - by(simp add:sup_inf_absorb sup_commute) - also have "\ = (x \ y) \ (x \ z)" by(simp add:D) - finally show ?thesis . -qed - -text{* A package of rewrite rules for deciding equivalence wrt ACI: *} - -lemma (in lower_semilattice) inf_left_commute: "x \ (y \ z) = y \ (x \ z)" -proof - - have "x \ (y \ z) = (y \ z) \ x" by (simp only: inf_commute) - also have "... = y \ (z \ x)" by (simp only: inf_assoc) - also have "z \ x = x \ z" by (simp only: inf_commute) - finally(back_subst) show ?thesis . -qed - -lemma (in upper_semilattice) sup_left_commute: "x \ (y \ z) = y \ (x \ z)" -proof - - have "x \ (y \ z) = (y \ z) \ x" by (simp only: sup_commute) - also have "... = y \ (z \ x)" by (simp only: sup_assoc) - also have "z \ x = x \ z" by (simp only: sup_commute) - finally(back_subst) show ?thesis . -qed - -lemma (in lower_semilattice) inf_left_idem: "x \ (x \ y) = x \ y" -proof - - have "x \ (x \ y) = (x \ x) \ y" by(simp only:inf_assoc) - also have "\ = x \ y" by(simp) - finally show ?thesis . -qed - -lemma (in upper_semilattice) sup_left_idem: "x \ (x \ y) = x \ y" -proof - - have "x \ (x \ y) = (x \ x) \ y" by(simp only:sup_assoc) - also have "\ = x \ y" by(simp) - finally show ?thesis . -qed - - -lemmas (in lower_semilattice) inf_ACI = - inf_commute inf_assoc inf_left_commute inf_left_idem - -lemmas (in upper_semilattice) sup_ACI = - sup_commute sup_assoc sup_left_commute sup_left_idem - -lemmas (in lattice) ACI = inf_ACI sup_ACI - - -subsection{* Distributive lattices *} - -locale distrib_lattice = lattice + - assumes sup_inf_distrib1: "x \ (y \ z) = (x \ y) \ (x \ z)" - -lemma (in distrib_lattice) sup_inf_distrib2: - "(y \ z) \ x = (y \ x) \ (z \ x)" -by(simp add:ACI sup_inf_distrib1) - -lemma (in distrib_lattice) inf_sup_distrib1: - "x \ (y \ z) = (x \ y) \ (x \ z)" -by(rule distrib_imp2[OF sup_inf_distrib1]) - -lemma (in distrib_lattice) inf_sup_distrib2: - "(y \ z) \ x = (y \ x) \ (z \ x)" -by(simp add:ACI inf_sup_distrib1) - -lemmas (in distrib_lattice) distrib = - sup_inf_distrib1 sup_inf_distrib2 inf_sup_distrib1 inf_sup_distrib2 - - -subsection {* Least value operator and min/max -- properties *} - -(*FIXME: derive more of the min/max laws generically via semilattices*) - -lemma LeastI2_order: - "[| P (x::'a::order); - !!y. P y ==> x <= y; - !!x. [| P x; ALL y. P y --> x \ y |] ==> Q x |] - ==> Q (Least P)" - apply (unfold Least_def) - apply (rule theI2) - apply (blast intro: order_antisym)+ - done - -lemma Least_equality: - "[| P (k::'a::order); !!x. P x ==> k <= x |] ==> (LEAST x. P x) = k" - apply (simp add: Least_def) - apply (rule the_equality) - apply (auto intro!: order_antisym) - done - -lemma min_leastL: "(!!x. least <= x) ==> min least x = least" - by (simp add: min_def) - -lemma max_leastL: "(!!x. least <= x) ==> max least x = x" - by (simp add: max_def) - -lemma min_leastR: "(\x\'a\order. least \ x) \ min x least = least" - apply (simp add: min_def) - apply (blast intro: order_antisym) - done - -lemma max_leastR: "(\x\'a\order. least \ x) \ max x least = x" - apply (simp add: max_def) - apply (blast intro: order_antisym) - done - -lemma min_of_mono: - "(!!x y. (f x <= f y) = (x <= y)) ==> min (f m) (f n) = f (min m n)" - by (simp add: min_def) - -lemma max_of_mono: - "(!!x y. (f x <= f y) = (x <= y)) ==> max (f m) (f n) = f (max m n)" - by (simp add: max_def) - -text{* Instantiate locales: *} - -interpretation min_max: - lower_semilattice["op \" "op <" "min :: 'a::linorder \ 'a \ 'a"] -apply unfold_locales -apply(simp add:min_def linorder_not_le order_less_imp_le) -apply(simp add:min_def linorder_not_le order_less_imp_le) -apply(simp add:min_def linorder_not_le order_less_imp_le) -done - -interpretation min_max: - upper_semilattice["op \" "op <" "max :: 'a::linorder \ 'a \ 'a"] -apply unfold_locales -apply(simp add: max_def linorder_not_le order_less_imp_le) -apply(simp add: max_def linorder_not_le order_less_imp_le) -apply(simp add: max_def linorder_not_le order_less_imp_le) -done - -interpretation min_max: - lattice["op \" "op <" "min :: 'a::linorder \ 'a \ 'a" "max"] - by unfold_locales - -interpretation min_max: - distrib_lattice["op \" "op <" "min :: 'a::linorder \ 'a \ 'a" "max"] -apply unfold_locales -apply(rule_tac x=x and y=y in linorder_le_cases) -apply(rule_tac x=x and y=z in linorder_le_cases) -apply(rule_tac x=y and y=z in linorder_le_cases) -apply(simp add:min_def max_def) -apply(simp add:min_def max_def) -apply(rule_tac x=y and y=z in linorder_le_cases) -apply(simp add:min_def max_def) -apply(simp add:min_def max_def) -apply(rule_tac x=x and y=z in linorder_le_cases) -apply(rule_tac x=y and y=z in linorder_le_cases) -apply(simp add:min_def max_def) -apply(simp add:min_def max_def) -apply(rule_tac x=y and y=z in linorder_le_cases) -apply(simp add:min_def max_def) -apply(simp add:min_def max_def) -done - -lemma le_max_iff_disj: "!!z::'a::linorder. (z <= max x y) = (z <= x | z <= y)" - apply(simp add:max_def) - apply (insert linorder_linear) - apply (blast intro: order_trans) - done - -lemmas le_maxI1 = min_max.sup_ge1 -lemmas le_maxI2 = min_max.sup_ge2 - -lemma less_max_iff_disj: "!!z::'a::linorder. (z < max x y) = (z < x | z < y)" - apply (simp add: max_def order_le_less) - apply (insert linorder_less_linear) - apply (blast intro: order_less_trans) - done - -lemma max_less_iff_conj [simp]: - "!!z::'a::linorder. (max x y < z) = (x < z & y < z)" - apply (simp add: order_le_less max_def) - apply (insert linorder_less_linear) - apply (blast intro: order_less_trans) - done - -lemma min_less_iff_conj [simp]: - "!!z::'a::linorder. (z < min x y) = (z < x & z < y)" - apply (simp add: order_le_less min_def) - apply (insert linorder_less_linear) - apply (blast intro: order_less_trans) - done - -lemma min_le_iff_disj: "!!z::'a::linorder. (min x y <= z) = (x <= z | y <= z)" - apply (simp add: min_def) - apply (insert linorder_linear) - apply (blast intro: order_trans) - done - -lemma min_less_iff_disj: "!!z::'a::linorder. (min x y < z) = (x < z | y < z)" - apply (simp add: min_def order_le_less) - apply (insert linorder_less_linear) - apply (blast intro: order_less_trans) - done - -lemmas max_ac = min_max.sup_assoc min_max.sup_commute - mk_left_commute[of max,OF min_max.sup_assoc min_max.sup_commute] - -lemmas min_ac = min_max.inf_assoc min_max.inf_commute - mk_left_commute[of min,OF min_max.inf_assoc min_max.inf_commute] - -lemma split_min: - "P (min (i::'a::linorder) j) = ((i <= j --> P(i)) & (~ i <= j --> P(j)))" - by (simp add: min_def) - -lemma split_max: - "P (max (i::'a::linorder) j) = ((i <= j --> P(j)) & (~ i <= j --> P(i)))" - by (simp add: max_def) - -text {* ML legacy bindings *} - -ML {* -val Least_def = thm "Least_def"; -val Least_equality = thm "Least_equality"; -val min_def = thm "min_def"; -val min_of_mono = thm "min_of_mono"; -val max_def = thm "max_def"; -val max_of_mono = thm "max_of_mono"; -val min_leastL = thm "min_leastL"; -val max_leastL = thm "max_leastL"; -val min_leastR = thm "min_leastR"; -val max_leastR = thm "max_leastR"; -val le_max_iff_disj = thm "le_max_iff_disj"; -val le_maxI1 = thm "le_maxI1"; -val le_maxI2 = thm "le_maxI2"; -val less_max_iff_disj = thm "less_max_iff_disj"; -val max_less_iff_conj = thm "max_less_iff_conj"; -val min_less_iff_conj = thm "min_less_iff_conj"; -val min_le_iff_disj = thm "min_le_iff_disj"; -val min_less_iff_disj = thm "min_less_iff_disj"; -val split_min = thm "split_min"; -val split_max = thm "split_max"; -*} - -end diff -r 3fd22b0939ff -r d594c58e24ed src/HOL/Lattices.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/Lattices.thy Wed Nov 08 19:48:34 2006 +0100 @@ -0,0 +1,336 @@ +(* Title: HOL/Lattices.thy + ID: $Id$ + Author: Tobias Nipkow +*) + +header {* Lattices via Locales *} + +theory Lattices +imports Orderings +begin + +subsection{* Lattices *} + +text{* This theory of lattice locales only defines binary sup and inf +operations. The extension to finite sets is done in theory @{text +Finite_Set}. In the longer term it may be better to define arbitrary +sups and infs via @{text THE}. *} + +locale lower_semilattice = partial_order + + fixes inf :: "'a \ 'a \ 'a" (infixl "\" 70) + assumes inf_le1: "x \ y \ x" and inf_le2: "x \ y \ y" + and inf_least: "x \ y \ x \ z \ x \ y \ z" + +locale upper_semilattice = partial_order + + fixes sup :: "'a \ 'a \ 'a" (infixl "\" 65) + assumes sup_ge1: "x \ x \ y" and sup_ge2: "y \ x \ y" + and sup_greatest: "y \ x \ z \ x \ y \ z \ x" + +locale lattice = lower_semilattice + upper_semilattice + +lemma (in lower_semilattice) inf_commute: "(x \ y) = (y \ x)" +by(blast intro: antisym inf_le1 inf_le2 inf_least) + +lemma (in upper_semilattice) sup_commute: "(x \ y) = (y \ x)" +by(blast intro: antisym sup_ge1 sup_ge2 sup_greatest) + +lemma (in lower_semilattice) inf_assoc: "(x \ y) \ z = x \ (y \ z)" +by(blast intro: antisym inf_le1 inf_le2 inf_least trans del:refl) + +lemma (in upper_semilattice) sup_assoc: "(x \ y) \ z = x \ (y \ z)" +by(blast intro!: antisym sup_ge1 sup_ge2 intro: sup_greatest trans del:refl) + +lemma (in lower_semilattice) inf_idem[simp]: "x \ x = x" +by(blast intro: antisym inf_le1 inf_le2 inf_least refl) + +lemma (in upper_semilattice) sup_idem[simp]: "x \ x = x" +by(blast intro: antisym sup_ge1 sup_ge2 sup_greatest refl) + +lemma (in lower_semilattice) inf_left_idem[simp]: "x \ (x \ y) = x \ y" +by (simp add: inf_assoc[symmetric]) + +lemma (in upper_semilattice) sup_left_idem[simp]: "x \ (x \ y) = x \ y" +by (simp add: sup_assoc[symmetric]) + +lemma (in lattice) inf_sup_absorb: "x \ (x \ y) = x" +by(blast intro: antisym inf_le1 inf_least sup_ge1) + +lemma (in lattice) sup_inf_absorb: "x \ (x \ y) = x" +by(blast intro: antisym sup_ge1 sup_greatest inf_le1) + +lemma (in lower_semilattice) inf_absorb: "x \ y \ x \ y = x" +by(blast intro: antisym inf_le1 inf_least refl) + +lemma (in upper_semilattice) sup_absorb: "x \ y \ x \ y = y" +by(blast intro: antisym sup_ge2 sup_greatest refl) + + +lemma (in lower_semilattice) less_eq_inf_conv [simp]: + "x \ y \ z = (x \ y \ x \ z)" +by(blast intro: antisym inf_le1 inf_le2 inf_least refl trans) + +lemmas (in lower_semilattice) below_inf_conv = less_eq_inf_conv + -- {* a duplicate for backward compatibility *} + +lemma (in upper_semilattice) above_sup_conv[simp]: + "x \ y \ z = (x \ z \ y \ z)" +by(blast intro: antisym sup_ge1 sup_ge2 sup_greatest refl trans) + + +text{* Towards distributivity: if you have one of them, you have them all. *} + +lemma (in lattice) distrib_imp1: +assumes D: "!!x y z. x \ (y \ z) = (x \ y) \ (x \ z)" +shows "x \ (y \ z) = (x \ y) \ (x \ z)" +proof- + have "x \ (y \ z) = (x \ (x \ z)) \ (y \ z)" by(simp add:sup_inf_absorb) + also have "\ = x \ (z \ (x \ y))" by(simp add:D inf_commute sup_assoc) + also have "\ = ((x \ y) \ x) \ ((x \ y) \ z)" + by(simp add:inf_sup_absorb inf_commute) + also have "\ = (x \ y) \ (x \ z)" by(simp add:D) + finally show ?thesis . +qed + +lemma (in lattice) distrib_imp2: +assumes D: "!!x y z. x \ (y \ z) = (x \ y) \ (x \ z)" +shows "x \ (y \ z) = (x \ y) \ (x \ z)" +proof- + have "x \ (y \ z) = (x \ (x \ z)) \ (y \ z)" by(simp add:inf_sup_absorb) + also have "\ = x \ (z \ (x \ y))" by(simp add:D sup_commute inf_assoc) + also have "\ = ((x \ y) \ x) \ ((x \ y) \ z)" + by(simp add:sup_inf_absorb sup_commute) + also have "\ = (x \ y) \ (x \ z)" by(simp add:D) + finally show ?thesis . +qed + +text{* A package of rewrite rules for deciding equivalence wrt ACI: *} + +lemma (in lower_semilattice) inf_left_commute: "x \ (y \ z) = y \ (x \ z)" +proof - + have "x \ (y \ z) = (y \ z) \ x" by (simp only: inf_commute) + also have "... = y \ (z \ x)" by (simp only: inf_assoc) + also have "z \ x = x \ z" by (simp only: inf_commute) + finally(back_subst) show ?thesis . +qed + +lemma (in upper_semilattice) sup_left_commute: "x \ (y \ z) = y \ (x \ z)" +proof - + have "x \ (y \ z) = (y \ z) \ x" by (simp only: sup_commute) + also have "... = y \ (z \ x)" by (simp only: sup_assoc) + also have "z \ x = x \ z" by (simp only: sup_commute) + finally(back_subst) show ?thesis . +qed + +lemma (in lower_semilattice) inf_left_idem: "x \ (x \ y) = x \ y" +proof - + have "x \ (x \ y) = (x \ x) \ y" by(simp only:inf_assoc) + also have "\ = x \ y" by(simp) + finally show ?thesis . +qed + +lemma (in upper_semilattice) sup_left_idem: "x \ (x \ y) = x \ y" +proof - + have "x \ (x \ y) = (x \ x) \ y" by(simp only:sup_assoc) + also have "\ = x \ y" by(simp) + finally show ?thesis . +qed + + +lemmas (in lower_semilattice) inf_ACI = + inf_commute inf_assoc inf_left_commute inf_left_idem + +lemmas (in upper_semilattice) sup_ACI = + sup_commute sup_assoc sup_left_commute sup_left_idem + +lemmas (in lattice) ACI = inf_ACI sup_ACI + + +subsection{* Distributive lattices *} + +locale distrib_lattice = lattice + + assumes sup_inf_distrib1: "x \ (y \ z) = (x \ y) \ (x \ z)" + +lemma (in distrib_lattice) sup_inf_distrib2: + "(y \ z) \ x = (y \ x) \ (z \ x)" +by(simp add:ACI sup_inf_distrib1) + +lemma (in distrib_lattice) inf_sup_distrib1: + "x \ (y \ z) = (x \ y) \ (x \ z)" +by(rule distrib_imp2[OF sup_inf_distrib1]) + +lemma (in distrib_lattice) inf_sup_distrib2: + "(y \ z) \ x = (y \ x) \ (z \ x)" +by(simp add:ACI inf_sup_distrib1) + +lemmas (in distrib_lattice) distrib = + sup_inf_distrib1 sup_inf_distrib2 inf_sup_distrib1 inf_sup_distrib2 + + +subsection {* Least value operator and min/max -- properties *} + +(*FIXME: derive more of the min/max laws generically via semilattices*) + +lemma LeastI2_order: + "[| P (x::'a::order); + !!y. P y ==> x <= y; + !!x. [| P x; ALL y. P y --> x \ y |] ==> Q x |] + ==> Q (Least P)" + apply (unfold Least_def) + apply (rule theI2) + apply (blast intro: order_antisym)+ + done + +lemma Least_equality: + "[| P (k::'a::order); !!x. P x ==> k <= x |] ==> (LEAST x. P x) = k" + apply (simp add: Least_def) + apply (rule the_equality) + apply (auto intro!: order_antisym) + done + +lemma min_leastL: "(!!x. least <= x) ==> min least x = least" + by (simp add: min_def) + +lemma max_leastL: "(!!x. least <= x) ==> max least x = x" + by (simp add: max_def) + +lemma min_leastR: "(\x\'a\order. least \ x) \ min x least = least" + apply (simp add: min_def) + apply (blast intro: order_antisym) + done + +lemma max_leastR: "(\x\'a\order. least \ x) \ max x least = x" + apply (simp add: max_def) + apply (blast intro: order_antisym) + done + +lemma min_of_mono: + "(!!x y. (f x <= f y) = (x <= y)) ==> min (f m) (f n) = f (min m n)" + by (simp add: min_def) + +lemma max_of_mono: + "(!!x y. (f x <= f y) = (x <= y)) ==> max (f m) (f n) = f (max m n)" + by (simp add: max_def) + +text{* Instantiate locales: *} + +interpretation min_max: + lower_semilattice["op \" "op <" "min :: 'a::linorder \ 'a \ 'a"] +apply unfold_locales +apply(simp add:min_def linorder_not_le order_less_imp_le) +apply(simp add:min_def linorder_not_le order_less_imp_le) +apply(simp add:min_def linorder_not_le order_less_imp_le) +done + +interpretation min_max: + upper_semilattice["op \" "op <" "max :: 'a::linorder \ 'a \ 'a"] +apply unfold_locales +apply(simp add: max_def linorder_not_le order_less_imp_le) +apply(simp add: max_def linorder_not_le order_less_imp_le) +apply(simp add: max_def linorder_not_le order_less_imp_le) +done + +interpretation min_max: + lattice["op \" "op <" "min :: 'a::linorder \ 'a \ 'a" "max"] + by unfold_locales + +interpretation min_max: + distrib_lattice["op \" "op <" "min :: 'a::linorder \ 'a \ 'a" "max"] +apply unfold_locales +apply(rule_tac x=x and y=y in linorder_le_cases) +apply(rule_tac x=x and y=z in linorder_le_cases) +apply(rule_tac x=y and y=z in linorder_le_cases) +apply(simp add:min_def max_def) +apply(simp add:min_def max_def) +apply(rule_tac x=y and y=z in linorder_le_cases) +apply(simp add:min_def max_def) +apply(simp add:min_def max_def) +apply(rule_tac x=x and y=z in linorder_le_cases) +apply(rule_tac x=y and y=z in linorder_le_cases) +apply(simp add:min_def max_def) +apply(simp add:min_def max_def) +apply(rule_tac x=y and y=z in linorder_le_cases) +apply(simp add:min_def max_def) +apply(simp add:min_def max_def) +done + +lemma le_max_iff_disj: "!!z::'a::linorder. (z <= max x y) = (z <= x | z <= y)" + apply(simp add:max_def) + apply (insert linorder_linear) + apply (blast intro: order_trans) + done + +lemmas le_maxI1 = min_max.sup_ge1 +lemmas le_maxI2 = min_max.sup_ge2 + +lemma less_max_iff_disj: "!!z::'a::linorder. (z < max x y) = (z < x | z < y)" + apply (simp add: max_def order_le_less) + apply (insert linorder_less_linear) + apply (blast intro: order_less_trans) + done + +lemma max_less_iff_conj [simp]: + "!!z::'a::linorder. (max x y < z) = (x < z & y < z)" + apply (simp add: order_le_less max_def) + apply (insert linorder_less_linear) + apply (blast intro: order_less_trans) + done + +lemma min_less_iff_conj [simp]: + "!!z::'a::linorder. (z < min x y) = (z < x & z < y)" + apply (simp add: order_le_less min_def) + apply (insert linorder_less_linear) + apply (blast intro: order_less_trans) + done + +lemma min_le_iff_disj: "!!z::'a::linorder. (min x y <= z) = (x <= z | y <= z)" + apply (simp add: min_def) + apply (insert linorder_linear) + apply (blast intro: order_trans) + done + +lemma min_less_iff_disj: "!!z::'a::linorder. (min x y < z) = (x < z | y < z)" + apply (simp add: min_def order_le_less) + apply (insert linorder_less_linear) + apply (blast intro: order_less_trans) + done + +lemmas max_ac = min_max.sup_assoc min_max.sup_commute + mk_left_commute[of max,OF min_max.sup_assoc min_max.sup_commute] + +lemmas min_ac = min_max.inf_assoc min_max.inf_commute + mk_left_commute[of min,OF min_max.inf_assoc min_max.inf_commute] + +lemma split_min: + "P (min (i::'a::linorder) j) = ((i <= j --> P(i)) & (~ i <= j --> P(j)))" + by (simp add: min_def) + +lemma split_max: + "P (max (i::'a::linorder) j) = ((i <= j --> P(j)) & (~ i <= j --> P(i)))" + by (simp add: max_def) + +text {* ML legacy bindings *} + +ML {* +val Least_def = thm "Least_def"; +val Least_equality = thm "Least_equality"; +val min_def = thm "min_def"; +val min_of_mono = thm "min_of_mono"; +val max_def = thm "max_def"; +val max_of_mono = thm "max_of_mono"; +val min_leastL = thm "min_leastL"; +val max_leastL = thm "max_leastL"; +val min_leastR = thm "min_leastR"; +val max_leastR = thm "max_leastR"; +val le_max_iff_disj = thm "le_max_iff_disj"; +val le_maxI1 = thm "le_maxI1"; +val le_maxI2 = thm "le_maxI2"; +val less_max_iff_disj = thm "less_max_iff_disj"; +val max_less_iff_conj = thm "max_less_iff_conj"; +val min_less_iff_conj = thm "min_less_iff_conj"; +val min_le_iff_disj = thm "min_le_iff_disj"; +val min_less_iff_disj = thm "min_less_iff_disj"; +val split_min = thm "split_min"; +val split_max = thm "split_max"; +*} + +end