# HG changeset patch # User haftmann # Date 1751994824 -7200 # Node ID 7ddae44464d41ac9c25046b06138bde8952d7a00 # Parent 71cbfcda66d6df63084fd2f07a0b3911e70879ef moved to more appropriate theory diff -r 71cbfcda66d6 -r 7ddae44464d4 NEWS --- a/NEWS Sun Jul 06 10:01:32 2025 +0200 +++ b/NEWS Tue Jul 08 19:13:44 2025 +0200 @@ -115,7 +115,7 @@ discontinued in favour of a generic List.all_range const List.Bleast - discontinued in favour of more concise List.Least as variant of Min + discontinued in favour of more concise Lattices_Big.Least const [List.]map_tailrec ~ List.map_tailrec thm List.map_tailrec_eq [simp] diff -r 71cbfcda66d6 -r 7ddae44464d4 src/HOL/Lattices_Big.thy --- a/src/HOL/Lattices_Big.thy Sun Jul 06 10:01:32 2025 +0200 +++ b/src/HOL/Lattices_Big.thy Tue Jul 08 19:13:44 2025 +0200 @@ -923,6 +923,46 @@ using that by (auto simp add: disjnt_def) (use Max_less_iff in blast) +subsection \An aside: code generation for \LEAST\ and \GREATEST\\ + +context +begin + +qualified definition Least :: \'a::linorder set \ 'a\ \ \only for code generation\ + where Least_eq [code_abbrev, simp]: \Least S = (LEAST x. x \ S)\ + +qualified lemma Least_filter_eq [code_abbrev]: + \Least (Set.filter P S) = (LEAST x. x \ S \ P x)\ + by simp + +qualified definition Least_abort :: \'a set \ 'a::linorder\ + where \Least_abort = Least\ + +declare [[code abort: Least_abort]] + +qualified lemma Least_code [code]: + \Least A = (if finite A \ Set.is_empty A then Least_abort A else Min A)\ + using Least_Min [of \\x. x \ A\] by (auto simp add: Least_abort_def) + +qualified definition Greatest :: \'a::linorder set \ 'a\ \ \only for code generation\ + where Greatest_eq [code_abbrev, simp]: \Greatest S = (GREATEST x. x \ S)\ + +qualified lemma Greatest_filter_eq [code_abbrev]: + \Greatest (Set.filter P S) = (GREATEST x. x \ S \ P x)\ + by simp + +qualified definition Greatest_abort :: \'a set \ 'a::linorder\ + where \Greatest_abort = Greatest\ + +declare [[code abort: Greatest_abort]] + +qualified lemma Greatest_code [code]: + \Greatest A = (if finite A \ Set.is_empty A then Greatest_abort A else Max A)\ + using Greatest_Max [of \\x. x \ A\] by (auto simp add: Greatest_abort_def) + +end + + subsection \Arg Min\ context ord diff -r 71cbfcda66d6 -r 7ddae44464d4 src/HOL/Library/RBT_Set.thy --- a/src/HOL/Library/RBT_Set.thy Sun Jul 06 10:01:32 2025 +0200 +++ b/src/HOL/Library/RBT_Set.thy Tue Jul 08 19:13:44 2025 +0200 @@ -773,16 +773,16 @@ by (auto simp add: set_keys intro: sorted_distinct_set_unique) lemma Least_code [code]: - \List.Least (Set t) = (if RBT.is_empty t then List.Least_abort {} else Min (Set t))\ - apply (auto simp add: List.Least_abort_def simp flip: empty_Set) + \Lattices_Big.Least (Set t) = (if RBT.is_empty t then Lattices_Big.Least_abort {} else Min (Set t))\ + apply (auto simp add: Lattices_Big.Least_abort_def simp flip: empty_Set) apply (subst Least_Min) using is_empty_Set apply auto done lemma Greatest_code [code]: - \List.Greatest (Set t) = (if RBT.is_empty t then List.Greatest_abort {} else Max (Set t))\ - apply (auto simp add: List.Greatest_abort_def simp flip: empty_Set) + \Lattices_Big.Greatest (Set t) = (if RBT.is_empty t then Lattices_Big.Greatest_abort {} else Max (Set t))\ + apply (auto simp add: Lattices_Big.Greatest_abort_def simp flip: empty_Set) apply (subst Greatest_Max) using is_empty_Set apply auto diff -r 71cbfcda66d6 -r 7ddae44464d4 src/HOL/List.thy --- a/src/HOL/List.thy Sun Jul 06 10:01:32 2025 +0200 +++ b/src/HOL/List.thy Tue Jul 08 19:13:44 2025 +0200 @@ -8502,45 +8502,6 @@ "wf_code (set xs) = acyclic (set xs)" unfolding wf_code_def using wf_set . -text \\LEAST\ and \GREATEST\ operator.\ - -context -begin - -qualified definition Least :: \'a::linorder set \ 'a\ \ \only for code generation\ - where Least_eq [code_abbrev, simp]: \Least S = (LEAST x. x \ S)\ - -qualified lemma Least_filter_eq [code_abbrev]: - \Least (Set.filter P S) = (LEAST x. x \ S \ P x)\ - by simp - -qualified definition Least_abort :: \'a set \ 'a::linorder\ - where \Least_abort = Least\ - -declare [[code abort: Least_abort]] - -qualified lemma Least_code [code]: - \Least A = (if finite A \ Set.is_empty A then Least_abort A else Min A)\ - using Least_Min [of \\x. x \ A\] by (auto simp add: Least_abort_def) - -qualified definition Greatest :: \'a::linorder set \ 'a\ \ \only for code generation\ - where Greatest_eq [code_abbrev, simp]: \Greatest S = (GREATEST x. x \ S)\ - -qualified lemma Greatest_filter_eq [code_abbrev]: - \Greatest (Set.filter P S) = (GREATEST x. x \ S \ P x)\ - by simp - -qualified definition Greatest_abort :: \'a set \ 'a::linorder\ - where \Greatest_abort = Greatest\ - -declare [[code abort: Greatest_abort]] - -qualified lemma Greatest_code [code]: - \Greatest A = (if finite A \ Set.is_empty A then Greatest_abort A else Max A)\ - using Greatest_Max [of \\x. x \ A\] by (auto simp add: Greatest_abort_def) - -end - subsubsection \Pretty lists\