# HG changeset patch # User haftmann # Date 1701550190 0 # Node ID 486a32079c60061d47be85d7892cd60ed68f0eb6 # Parent 7476818dfd5d7c9525f81546356b7a00a9a4bc7c compactified specification of type class parity diff -r 7476818dfd5d -r 486a32079c60 NEWS --- a/NEWS Sat Dec 02 20:49:49 2023 +0000 +++ b/NEWS Sat Dec 02 20:49:50 2023 +0000 @@ -29,6 +29,9 @@ unique_euclidean_semiring_with_bit_operations is renamed to linordered_euclidean_semiring_bit_operations. Minor INCOMPATIBILITY. +* Streamlined specification of type class (semi)ring_parity. Minor + INCOMPATIBILITY. + *** ML *** diff -r 7476818dfd5d -r 486a32079c60 src/HOL/Library/Word.thy --- a/src/HOL/Library/Word.thy Sat Dec 02 20:49:49 2023 +0000 +++ b/src/HOL/Library/Word.thy Sat Dec 02 20:49:50 2023 +0000 @@ -668,16 +668,7 @@ end instance word :: (len) semiring_parity -proof - show "\ 2 dvd (1::'a word)" - by transfer simp - show even_iff_mod_2_eq_0: "2 dvd a \ a mod 2 = 0" - for a :: "'a word" - by transfer (simp_all add: mod_2_eq_odd take_bit_Suc) - show "\ 2 dvd a \ a mod 2 = 1" - for a :: "'a word" - by transfer (simp_all add: mod_2_eq_odd take_bit_Suc) -qed + by (standard; transfer) (simp_all add: mod_2_eq_odd) lemma word_bit_induct [case_names zero even odd]: \P a\ if word_zero: \P 0\ diff -r 7476818dfd5d -r 486a32079c60 src/HOL/Parity.thy --- a/src/HOL/Parity.thy Sat Dec 02 20:49:49 2023 +0000 +++ b/src/HOL/Parity.thy Sat Dec 02 20:49:50 2023 +0000 @@ -12,16 +12,15 @@ subsection \Ring structures with parity and \even\/\odd\ predicates\ class semiring_parity = comm_semiring_1 + semiring_modulo + - assumes even_iff_mod_2_eq_zero: "2 dvd a \ a mod 2 = 0" - and odd_iff_mod_2_eq_one: "\ 2 dvd a \ a mod 2 = 1" - and odd_one [simp]: "\ 2 dvd 1" + assumes mod_2_eq_odd: \a mod 2 = of_bool (\ 2 dvd a)\ + and odd_one [simp]: \\ 2 dvd 1\ begin abbreviation even :: "'a \ bool" - where "even a \ 2 dvd a" + where \even a \ 2 dvd a\ abbreviation odd :: "'a \ bool" - where "odd a \ \ 2 dvd a" + where \odd a \ \ 2 dvd a\ end @@ -42,25 +41,21 @@ begin lemma evenE [elim?]: - assumes "even a" - obtains b where "a = 2 * b" + assumes \even a\ + obtains b where \a = 2 * b\ using assms by (rule dvdE) lemma oddE [elim?]: - assumes "odd a" - obtains b where "a = 2 * b + 1" + assumes \odd a\ + obtains b where \a = 2 * b + 1\ proof - - have "a = 2 * (a div 2) + a mod 2" + have \a = 2 * (a div 2) + a mod 2\ by (simp add: mult_div_mod_eq) - with assms have "a = 2 * (a div 2) + 1" - by (simp add: odd_iff_mod_2_eq_one) - then show ?thesis .. + with assms have \a = 2 * (a div 2) + 1\ + by (simp add: mod_2_eq_odd) + then show thesis .. qed -lemma mod_2_eq_odd: - \a mod 2 = of_bool (odd a)\ - by (simp_all flip: odd_iff_mod_2_eq_one even_iff_mod_2_eq_zero) - lemma of_bool_odd_eq_mod_2: \of_bool (odd a) = a mod 2\ by (simp add: mod_2_eq_odd) @@ -77,6 +72,14 @@ \a mod 2 \ 1 \ a mod 2 = 0\ by (simp add: mod_2_eq_odd) +lemma even_iff_mod_2_eq_zero: + \2 dvd a \ a mod 2 = 0\ + by (simp add: mod_2_eq_odd) + +lemma odd_iff_mod_2_eq_one: + \\ 2 dvd a \ a mod 2 = 1\ + by (simp add: mod_2_eq_odd) + lemma even_mod_2_iff [simp]: \even (a mod 2) \ even a\ by (simp add: mod_2_eq_odd) @@ -810,15 +813,13 @@ subclass semiring_parity proof - show "2 dvd a \ a mod 2 = 0" for a - by (fact dvd_eq_mod_eq_0) - show "\ 2 dvd a \ a mod 2 = 1" for a - proof - assume "a mod 2 = 1" - then show "\ 2 dvd a" - by auto + show \a mod 2 = of_bool (\ 2 dvd a)\ for a + proof (cases \2 dvd a\) + case True + then show ?thesis + by (simp add: dvd_eq_mod_eq_0) next - assume "\ 2 dvd a" + case False have eucl: "euclidean_size (a mod 2) = 1" proof (rule Orderings.order_antisym) show "euclidean_size (a mod 2) \ 1" @@ -839,15 +840,17 @@ then have "of_nat (euclidean_size a) mod 2 = 1" by (simp add: of_nat_mod) from \\ 2 dvd a\ eucl - show "a mod 2 = 1" + have "a mod 2 = 1" by (auto intro: division_segment_eq_iff simp add: division_segment_mod) + with \\ 2 dvd a\ show ?thesis + by simp qed - show "\ is_unit 2" - proof (rule notI) - assume "is_unit 2" - then have "of_nat 2 dvd of_nat 1" + show \\ is_unit 2\ + proof + assume \is_unit 2\ + then have \of_nat 2 dvd of_nat 1\ by simp - then have "is_unit (2::nat)" + then have \is_unit (2::nat)\ by (simp only: of_nat_dvd_iff) then show False by simp