# HG changeset patch # User haftmann # Date 1600851161 0 # Node ID db43ee05066d0a9eda719dd277556c46866d24a6 # Parent ae89eac1d332a685a974a4592db6ba167bded9bc canonical enum instance for word diff -r ae89eac1d332 -r db43ee05066d src/HOL/Word/Word.thy --- a/src/HOL/Word/Word.thy Sun Sep 20 21:09:40 2020 +0200 +++ b/src/HOL/Word/Word.thy Wed Sep 23 08:52:41 2020 +0000 @@ -561,6 +561,49 @@ by transfer rule + +subsection \Enumeration\ + +lemma inj_on_word_of_nat: + \inj_on (word_of_nat :: nat \ 'a::len word) {0..<2 ^ LENGTH('a)}\ + by (rule inj_onI; transfer) (simp_all add: take_bit_int_eq_self) + +lemma UNIV_word_eq_word_of_nat: + \(UNIV :: 'a::len word set) = word_of_nat ` {0..<2 ^ LENGTH('a)}\ (is \_ = ?A\) +proof + show \word_of_nat ` {0..<2 ^ LENGTH('a)} \ UNIV\ + by simp + show \UNIV \ ?A\ + proof + fix w :: \'a word\ + show \w \ (word_of_nat ` {0..<2 ^ LENGTH('a)} :: 'a word set)\ + by (rule image_eqI [of _ _ \unat w\]; transfer) simp_all + qed +qed + +instantiation word :: (len) enum +begin + +definition enum_word :: \'a word list\ + where \enum_word = map word_of_nat [0..<2 ^ LENGTH('a)]\ + +definition enum_all_word :: \('a word \ bool) \ bool\ + where \enum_all_word = Ball UNIV\ + +definition enum_ex_word :: \('a word \ bool) \ bool\ + where \enum_ex_word = Bex UNIV\ + +lemma [code]: + \Enum.enum_all P \ Ball UNIV P\ + \Enum.enum_ex P \ Bex UNIV P\ for P :: \'a word \ bool\ + by (simp_all add: enum_all_word_def enum_ex_word_def) + +instance + by standard (simp_all add: UNIV_word_eq_word_of_nat inj_on_word_of_nat enum_word_def enum_all_word_def enum_ex_word_def distinct_map) + +end + + subsection \Bit-wise operations\ instantiation word :: (len) semiring_modulo @@ -2884,6 +2927,17 @@ by (simp add: udvd_iff_dvd) qed +lemma udvd_imp_dvd: + \v dvd w\ if \v udvd w\ for v w :: \'a::len word\ +proof - + from that obtain u :: \'a word\ where w: \unat w = unat v * unat u\ .. + then have \(word_of_nat (unat w) :: 'a word) = word_of_nat (unat v * unat u)\ + by simp + then have \w = v * u\ + by simp + then show \v dvd w\ .. +qed + lemma udvd_nat_alt: \a udvd b \ (\n. unat b = n * unat a)\ by (auto simp add: udvd_iff_dvd)