diff -r 518a1464f1ac -r 791c44b1d130 src/HOL/Library/Word.thy --- a/src/HOL/Library/Word.thy Sun Nov 02 20:01:43 2025 +0100 +++ b/src/HOL/Library/Word.thy Sun Nov 02 20:36:24 2025 +0100 @@ -4609,203 +4609,12 @@ by (simp add: word_cat_eq) -subsection \Computation on ranges\ - -context -begin - -qualified definition range :: \'a::len word \ 'a word \ 'a word list\ \ \only for code generation\ - where range_eq: \range a b = sorted_list_of_set {a.. - -qualified lemma set_range_eq [simp]: - \set (range a b) = {a.. - using finite_atLeastLessThan by (simp add: range_eq) - -qualified lemma distinct_range [simp]: - \distinct (range a b)\ - by (simp add: range_eq) - -qualified lemma range_code [code]: - \range a b = (if a < b then a # range (a + 1) b else [])\ -proof (cases \a < b\) - case True - then have \{a.. - apply (auto simp add: not_le) - apply (metis inc_le leD word_le_less_eq) - apply (metis dual_order.strict_implies_order inc_less_eq_iff word_not_simps(3)) - done - then show ?thesis - apply (auto simp add: range_eq finite_atLeastLessThan intro!: insort_is_Cons) - apply (subst insort_is_Cons) - apply auto - apply (metis Diff_insert Diff_insert0 atLeastAtMost_iff - atLeastLessThan_eq_atLeastAtMost_diff inc_less_eq_triv_imp - word_not_simps(3)) - done -next - case False - then show ?thesis - by (simp add: range_eq) -qed - -qualified lemma atLeast_eq_range [code_unfold]: - \{a..} = insert (- 1) (set (range a (- 1)))\ - by (auto simp add: not_less word_order.extremum_unique) - -qualified lemma greaterThan_eq_range [code_unfold]: - \{a<..} = (if a = - 1 then {} else insert (- 1) (set (range (a + 1) (- 1))))\ - apply (auto simp add: not_less not_le word_order.extremum_unique inc_less_eq_iff) - apply (simp add: order_neq_le_trans) - done - -qualified lemma lessThan_eq_range [code_unfold]: - \{.. - by auto - -qualified lemma atMost_eq_range [code_unfold]: - \{..b} = insert b (set (range 0 b))\ for b :: \'a::len word\ - by auto - -qualified lemma atLeastLessThan_eq_range [code_unfold]: - \{a.. - by simp - -qualified lemma atLeastAtMost_eq_range [code_unfold]: - \{a..b} = (if b = - 1 then {a..} else set (range a (b + 1)))\ - apply auto - using inc_less_eq_iff linorder_not_le apply blast - using inc_le linorder_not_less apply blast - done - -qualified lemma greaterThanLessThan_eq_range [code_unfold]: - \{a<.. - by (auto simp add: inc_less_eq_iff) - -qualified lemma greaterThanAtMost_eq_range [code_unfold]: - \{a<..b} = (if b = - 1 then {a<..} else if a = - 1 then {} else set (range (a + 1) (b + 1)))\ - apply (auto simp add: inc_less_eq_iff) - apply (metis add_diff_cancel add_eq_0_iff2 less_eq_dec_iff) - using inc_le linorder_not_less apply blast - done - -qualified definition all_range :: \('a::len word \ bool) \ 'a word \ 'a word \ bool\ \ \only for code generation\ - where all_range_iff [code_abbrev, simp]: \all_range P a b \ (\n\{a.. - -qualified lemma all_range_code [code]: - \all_range P a b \ (a < b \ P a \ all_range P (a + 1) b)\ - apply (auto simp add: Ball_def simp flip: less_iff_succ_less_eq) - apply (metis inc_less_eq_iff order_le_less word_not_simps(3)) - apply (metis antisym_conv2 inc_le) - done - -qualified lemma forall_atLeast_iff [code_unfold]: - \(\n\{a..}. P n) \ all_range P a (- 1) \ P (- 1)\ - apply auto - using atLeastLessThan_iff word_order.not_eq_extremum apply blast - done - -qualified lemma forall_greater_eq_iff [code_unfold]: - \(\n\a. P n) \ (\n\{a..}. P n)\ - by auto - -qualified lemma forall_greaterThan_iff [code_unfold]: - \(\n\{a<..}. P n) \ a = - 1 \ all_range P (a + 1) (- 1) \ P (- 1)\ - apply (auto simp add: inc_less_eq_iff word_order.not_eq_extremum) - apply (metis atLeastLessThan_iff inc_le word_order.not_eq_extremum) - done - -qualified lemma forall_greater_iff [code_unfold]: - \(\n>a. P n) \ (\n\{a<..}. P n)\ - by auto - -qualified lemma forall_lessThan_iff [code_unfold]: - \(\n\{.. all_range P 0 b\ - by auto - -qualified lemma forall_less_iff [code_unfold]: - \(\n (\n\{.. - by auto - -qualified lemma forall_atMost_iff [code_unfold]: - \(\n\{..b}. P n) \ P b \ all_range P 0 b\ - by auto - -qualified lemma forall_less_eq_iff [code_unfold]: - \(\n\b. P n) \ (\n\{..b}. P n)\ - by auto - -qualified lemma forall_atLeastLessThan_iff [code_unfold]: - \(\n\{a.. all_range P a b\ - by simp - -qualified lemma forall_atLeastAtMost_iff [code_unfold]: - \(\n\{a..b}. P n) \ (if b = - 1 then (\n\{a..}. P n) else all_range P a (b + 1))\ - apply auto - apply (metis atLeastAtMost_iff inc_le not_less_iff_gr_or_eq order_le_less) - apply (metis (no_types, lifting) antisym_conv2 atLeastLessThan_iff dual_order.trans inc_less_eq_triv_imp - nle_le) - done - -qualified lemma forall_greaterThanLessThan_iff [code_unfold]: - \(\n\{a<.. a = - 1 \ all_range P (a + 1) b\ - by (auto simp add: inc_less_eq_iff) - -qualified lemma forall_greaterThanAtMost_iff [code_unfold]: - \(\n\{a<..b}. P n) \ (if b = - 1 then (\n\{a<..}. P n) else a = - 1 \ all_range P (a + 1) (b + 1))\ - apply auto - apply (metis greaterThanAtMost_iff inc_less_eq_iff linorder_not_less) - apply (meson atLeastLessThan_iff inc_less_eq_iff order_le_less_trans word_le_less_eq) - done - -qualified lemma exists_atLeast_iff [code_unfold]: - \(\n\{a..}. P n) \ \ all_range (Not \ P) a (- 1) \ P (- 1)\ - using forall_atLeast_iff [of a \Not \ P\] by auto - -qualified lemma exists_greater_eq_iff [code_unfold]: - \(\n\a. P n) \ (\n\{a..}. P n)\ - by auto - -qualified lemma exists_greaterThan_iff [code_unfold]: - \(\n\{a<..}. P n) \ a \ - 1 \ (\ all_range (Not \ P) (a + 1) (- 1) \ P (- 1))\ - using forall_greaterThan_iff [of a \Not \ P\] by auto - -qualified lemma exists_greater_iff [code_unfold]: - \(\n>a. P n) \ (\n\{a<..}. P n)\ - by auto - -qualified lemma exists_lessThan_iff [code_unfold]: - \(\n\{.. \ all_range (Not \ P) 0 b\ - using forall_lessThan_iff [of b \Not \ P\] by auto - -qualified lemma exists_less_iff [code_unfold]: - \(\n (\n\{.. - by auto - -qualified lemma exists_atMost_iff [code_unfold]: - \(\n\{..b}. P n) \ P b \ \ all_range (Not \ P) 0 b\ - using forall_atMost_iff [of b \Not \ P\] by auto - -qualified lemma exists_less_eq_iff [code_unfold]: - \(\n\b. P n) \ (\n\{..b}. P n)\ - by auto - -qualified lemma exists_atLeastLessThan_iff [code_unfold]: - \(\n\{a.. \ all_range (Not \ P) a b\ - using forall_atLeastLessThan_iff [of a b \Not \ P\] by simp - -qualified lemma exists_atLeastAtMost_iff [code_unfold]: - \(\n\{a..b}. P n) \ (if b = - 1 then \n\{a..}. P n else \ all_range (Not \ P) a (b + 1))\ - using forall_atLeastAtMost_iff [of a b \Not \ P\] by auto - -qualified lemma exists_greaterThanLessThan_iff [code_unfold]: - \(\n\{a<.. a \ - 1 \ \ all_range (Not \ P) (a + 1) b\ - using forall_greaterThanLessThan_iff [of a b \Not \ P\] by auto - -qualified lemma exists_greaterThanAtMost_iff [code_unfold]: - \(\n\{a<..b}. P n) \ (if b = - 1 then \n\{a<..}. P n else a \ - 1 \ \ all_range (Not \ P) (a + 1) (b + 1))\ - using forall_greaterThanAtMost_iff [of a b \Not \ P\] by auto - -end +subsection \Executable intervals\ + +instance word :: (len) \{interval_top, interval_bot}\ + by standard + (simp_all add: less_eq_dec_self_iff_eq inc_less_eq_self_iff_eq less_inc_imp_less_eq dec_less_imp_less_eq) + subsection \Tool support\