# HG changeset patch # User Manuel Eberl # Date 1575279111 -3600 # Node ID 6695aeae8ec99ca36776a4b1b4ea3ba56c2f028b # Parent 8b8f9d3b3facda7c8e92fc649c869f7b5bcd879e# Parent 0c47c128f9af68c7a6ea51f208fc0f946a5ef28a Merged diff -r 8b8f9d3b3fac -r 6695aeae8ec9 src/HOL/Analysis/Analysis.thy diff -r 8b8f9d3b3fac -r 6695aeae8ec9 src/HOL/Analysis/Complex_Transcendental.thy --- a/src/HOL/Analysis/Complex_Transcendental.thy Sun Dec 01 11:51:17 2019 +0100 +++ b/src/HOL/Analysis/Complex_Transcendental.thy Mon Dec 02 10:31:51 2019 +0100 @@ -4053,4 +4053,6 @@ apply (auto simp: Re_complex_div_eq_0 exp_of_nat_mult [symmetric] mult_ac exp_Euler) done + + end diff -r 8b8f9d3b3fac -r 6695aeae8ec9 src/HOL/Analysis/Homeomorphism.thy --- a/src/HOL/Analysis/Homeomorphism.thy Sun Dec 01 11:51:17 2019 +0100 +++ b/src/HOL/Analysis/Homeomorphism.thy Mon Dec 02 10:31:51 2019 +0100 @@ -2184,7 +2184,6 @@ qed qed - corollary covering_space_lift_stronger: fixes p :: "'a::real_normed_vector \ 'b::real_normed_vector" and f :: "'c::real_normed_vector \ 'b" @@ -2252,4 +2251,36 @@ by (metis that covering_space_lift_strong [OF cov _ \z \ U\ U contf fim]) qed +subsection\<^marker>\tag unimportant\ \Homeomorphisms of arc images\ + +lemma homeomorphism_arc: + fixes g :: "real \ 'a::t2_space" + assumes "arc g" + obtains h where "homeomorphism {0..1} (path_image g) g h" +using assms by (force simp: arc_def homeomorphism_compact path_def path_image_def) + +lemma homeomorphic_arc_image_interval: + fixes g :: "real \ 'a::t2_space" and a::real + assumes "arc g" "a < b" + shows "(path_image g) homeomorphic {a..b}" +proof - + have "(path_image g) homeomorphic {0..1::real}" + by (meson assms(1) homeomorphic_def homeomorphic_sym homeomorphism_arc) + also have "\ homeomorphic {a..b}" + using assms by (force intro: homeomorphic_closed_intervals_real) + finally show ?thesis . +qed + +lemma homeomorphic_arc_images: + fixes g :: "real \ 'a::t2_space" and h :: "real \ 'b::t2_space" + assumes "arc g" "arc h" + shows "(path_image g) homeomorphic (path_image h)" +proof - + have "(path_image g) homeomorphic {0..1::real}" + by (meson assms homeomorphic_def homeomorphic_sym homeomorphism_arc) + also have "\ homeomorphic (path_image h)" + by (meson assms homeomorphic_def homeomorphism_arc) + finally show ?thesis . +qed + end diff -r 8b8f9d3b3fac -r 6695aeae8ec9 src/HOL/Analysis/Path_Connected.thy --- a/src/HOL/Analysis/Path_Connected.thy Sun Dec 01 11:51:17 2019 +0100 +++ b/src/HOL/Analysis/Path_Connected.thy Mon Dec 02 10:31:51 2019 +0100 @@ -4055,7 +4055,6 @@ shows "\g. homeomorphism S T f g" using assms injective_into_1d_eq_homeomorphism by blast - subsection\<^marker>\tag unimportant\ \Rectangular paths\ definition\<^marker>\tag unimportant\ rectpath where diff -r 8b8f9d3b3fac -r 6695aeae8ec9 src/HOL/Analysis/Retracts.thy --- a/src/HOL/Analysis/Retracts.thy Sun Dec 01 11:51:17 2019 +0100 +++ b/src/HOL/Analysis/Retracts.thy Mon Dec 02 10:31:51 2019 +0100 @@ -2591,4 +2591,51 @@ shows "connected(-S)" using assms path_connected_complement_homeomorphic_interval path_connected_imp_connected by blast + +lemma path_connected_arc_complement: + fixes \ :: "real \ 'a::euclidean_space" + assumes "arc \" "2 \ DIM('a)" + shows "path_connected(- path_image \)" +proof - + have "path_image \ homeomorphic {0..1::real}" + by (simp add: assms homeomorphic_arc_image_interval) + then + show ?thesis + apply (rule path_connected_complement_homeomorphic_convex_compact) + apply (auto simp: assms) + done +qed + +lemma connected_arc_complement: + fixes \ :: "real \ 'a::euclidean_space" + assumes "arc \" "2 \ DIM('a)" + shows "connected(- path_image \)" + by (simp add: assms path_connected_arc_complement path_connected_imp_connected) + +lemma inside_arc_empty: + fixes \ :: "real \ 'a::euclidean_space" + assumes "arc \" + shows "inside(path_image \) = {}" +proof (cases "DIM('a) = 1") + case True + then show ?thesis + using assms connected_arc_image connected_convex_1_gen inside_convex by blast +next + case False + show ?thesis + proof (rule inside_bounded_complement_connected_empty) + show "connected (- path_image \)" + apply (rule connected_arc_complement [OF assms]) + using False + by (metis DIM_ge_Suc0 One_nat_def Suc_1 not_less_eq_eq order_class.order.antisym) + show "bounded (path_image \)" + by (simp add: assms bounded_arc_image) + qed +qed + +lemma inside_simple_curve_imp_closed: + fixes \ :: "real \ 'a::euclidean_space" + shows "\simple_path \; x \ inside(path_image \)\ \ pathfinish \ = pathstart \" + using arc_simple_path inside_arc_empty by blast + end diff -r 8b8f9d3b3fac -r 6695aeae8ec9 src/HOL/Code_Numeral.thy --- a/src/HOL/Code_Numeral.thy Sun Dec 01 11:51:17 2019 +0100 +++ b/src/HOL/Code_Numeral.thy Mon Dec 02 10:31:51 2019 +0100 @@ -299,7 +299,7 @@ instance by (standard; transfer) (fact bit_eq_rec bit_induct push_bit_eq_mult drop_bit_eq_div bits_div_0 bits_div_by_1 bit_mod_div_trivial even_succ_div_2 - div_exp_eq mod_exp_eq mult_exp_mod_exp_eq div_exp_mod_exp_eq)+ + exp_div_exp_eq div_exp_eq mod_exp_eq mult_exp_mod_exp_eq div_exp_mod_exp_eq)+ end @@ -995,7 +995,7 @@ instance by (standard; transfer) (fact bit_eq_rec bit_induct push_bit_eq_mult drop_bit_eq_div bits_div_0 bits_div_by_1 bit_mod_div_trivial even_succ_div_2 - div_exp_eq mod_exp_eq mult_exp_mod_exp_eq div_exp_mod_exp_eq)+ + exp_div_exp_eq div_exp_eq mod_exp_eq mult_exp_mod_exp_eq div_exp_mod_exp_eq)+ end diff -r 8b8f9d3b3fac -r 6695aeae8ec9 src/HOL/Parity.thy --- a/src/HOL/Parity.thy Sun Dec 01 11:51:17 2019 +0100 +++ b/src/HOL/Parity.thy Mon Dec 02 10:31:51 2019 +0100 @@ -577,6 +577,7 @@ and bits_div_by_1 [simp]: \a div 1 = a\ and bit_mod_div_trivial [simp]: \a mod b div b = 0\ and even_succ_div_2 [simp]: \even a \ (1 + a) div 2 = a div 2\ + and exp_div_exp_eq: \2 ^ m div 2 ^ n = of_bool (2 ^ m \ 0 \ m \ n) * 2 ^ (m - n)\ and div_exp_eq: \a div 2 ^ m div 2 ^ n = a div 2 ^ (m + n)\ and mod_exp_eq: \a mod 2 ^ m mod 2 ^ n = a mod 2 ^ min m n\ and mult_exp_mod_exp_eq: \m \ n \ (a * 2 ^ m) mod (2 ^ n) = (a mod 2 ^ (n - m)) * 2 ^ m\ @@ -750,6 +751,10 @@ apply (metis bit_eq_iff local.mod2_eq_if local.mod_div_mult_eq) done +lemma bit_exp_iff: + \bit (2 ^ m) n \ 2 ^ m \ 0 \ m = n\ + by (auto simp add: bit_def exp_div_exp_eq) + end lemma nat_bit_induct [case_names zero even odd]: @@ -810,7 +815,7 @@ apply (auto simp add: mod_mod_cancel div_mult2_eq power_add mod_mult2_eq le_iff_add split: split_min_lin) apply (simp add: mult.commute) done -qed (auto simp add: div_mult2_eq mod_mult2_eq power_add) +qed (auto simp add: div_mult2_eq mod_mult2_eq power_add power_diff) lemma int_bit_induct [case_names zero minus even odd]: "P k" if zero_int: "P 0" @@ -891,6 +896,24 @@ with rec [of k True] show ?case by (simp add: ac_simps) qed + show \(2::int) ^ m div 2 ^ n = of_bool ((2::int) ^ m \ 0 \ n \ m) * 2 ^ (m - n)\ + for m n :: nat + proof (cases \m < n\) + case True + then have \n = m + (n - m)\ + by simp + then have \(2::int) ^ m div 2 ^ n = (2::int) ^ m div 2 ^ (m + (n - m))\ + by simp + also have \\ = (2::int) ^ m div (2 ^ m * 2 ^ (n - m))\ + by (simp add: power_add) + also have \\ = (2::int) ^ m div 2 ^ m div 2 ^ (n - m)\ + by (simp add: zdiv_zmult2_eq) + finally show ?thesis using \m < n\ by simp + next + case False + then show ?thesis + by (simp add: power_diff) + qed show \k mod 2 ^ m mod 2 ^ n = k mod 2 ^ min m n\ for m n :: nat and k :: int using mod_exp_eq [of \nat k\ m n] @@ -905,7 +928,7 @@ apply (auto simp add: power_add zmod_zmult2_eq le_iff_add split: split_min_lin) apply (simp add: ac_simps) done -qed (auto simp add: zdiv_zmult2_eq zmod_zmult2_eq power_add) +qed (auto simp add: zdiv_zmult2_eq zmod_zmult2_eq power_add power_diff not_le) class semiring_bit_shifts = semiring_bits + fixes push_bit :: \nat \ 'a \ 'a\ diff -r 8b8f9d3b3fac -r 6695aeae8ec9 src/HOL/Transfer.thy --- a/src/HOL/Transfer.thy Sun Dec 01 11:51:17 2019 +0100 +++ b/src/HOL/Transfer.thy Mon Dec 02 10:31:51 2019 +0100 @@ -642,13 +642,25 @@ end -subsection \\<^const>\of_nat\\ +subsection \\<^const>\of_bool\ and \<^const>\of_nat\\ + +context + includes lifting_syntax +begin + +lemma transfer_rule_of_bool: + \((\) ===> (\)) of_bool of_bool\ + if [transfer_rule]: \0 \ 0\ \1 \ 1\ + for R :: \'a::zero_neq_one \ 'b::zero_neq_one \ bool\ (infix \\\ 50) + by (unfold of_bool_def [abs_def]) transfer_prover lemma transfer_rule_of_nat: - fixes R :: "'a::semiring_1 \ 'b::semiring_1 \ bool" - assumes [transfer_rule]: "R 0 0" "R 1 1" - "rel_fun R (rel_fun R R) plus plus" - shows "rel_fun HOL.eq R of_nat of_nat" + "((=) ===> (\)) of_nat of_nat" + if [transfer_rule]: \0 \ 0\ \1 \ 1\ + \((\) ===> (\) ===> (\)) (+) (+)\ + for R :: \'a::semiring_1 \ 'b::semiring_1 \ bool\ (infix \\\ 50) by (unfold of_nat_def [abs_def]) transfer_prover end + +end diff -r 8b8f9d3b3fac -r 6695aeae8ec9 src/HOL/ex/Bit_Operations.thy --- a/src/HOL/ex/Bit_Operations.thy Sun Dec 01 11:51:17 2019 +0100 +++ b/src/HOL/ex/Bit_Operations.thy Mon Dec 02 10:31:51 2019 +0100 @@ -9,12 +9,39 @@ Main begin +lemma minus_1_div_exp_eq_int [simp]: + \- 1 div (2 :: int) ^ n = - 1\ + for n :: nat + by (induction n) (use div_exp_eq [symmetric, of \- 1 :: int\ 1] in \simp_all add: ac_simps\) + +context semiring_bits +begin + +lemma bits_div_by_0 [simp]: + \a div 0 = 0\ + by (metis local.add_cancel_right_right local.bit_mod_div_trivial local.mod_mult_div_eq local.mult_not_zero) + +lemma bit_0_eq [simp]: + \bit 0 = bot\ + by (simp add: fun_eq_iff bit_def) + +end + +context semiring_bit_shifts +begin + +end + + subsection \Bit operations in suitable algebraic structures\ class semiring_bit_operations = semiring_bit_shifts + - fixes "and" :: "'a \ 'a \ 'a" (infixr "AND" 64) - and or :: "'a \ 'a \ 'a" (infixr "OR" 59) - and xor :: "'a \ 'a \ 'a" (infixr "XOR" 59) + fixes "and" :: \'a \ 'a \ 'a\ (infixr "AND" 64) + and or :: \'a \ 'a \ 'a\ (infixr "OR" 59) + and xor :: \'a \ 'a \ 'a\ (infixr "XOR" 59) + assumes bit_and_iff: \\n. bit (a AND b) n \ bit a n \ bit b n\ + and bit_or_iff: \\n. bit (a OR b) n \ bit a n \ bit b n\ + and bit_xor_iff: \\n. bit (a XOR b) n \ bit a n \ bit b n\ begin text \ @@ -40,7 +67,7 @@ text \ Having - <^const>\set_bit\, \<^const>\unset_bit\ and \<^const>\flip_bit\ as separate + \<^const>\set_bit\, \<^const>\unset_bit\ and \<^const>\flip_bit\ as separate operations allows to implement them using bit masks later. \ @@ -85,19 +112,38 @@ class ring_bit_operations = semiring_bit_operations + ring_parity + fixes not :: \'a \ 'a\ (\NOT\) - assumes boolean_algebra: \boolean_algebra (AND) (OR) NOT 0 (- 1)\ - and boolean_algebra_xor_eq: \boolean_algebra.xor (AND) (OR) NOT = (XOR)\ + assumes bits_even_minus_1_div_exp_iff [simp]: \even (- 1 div 2 ^ n) \ 2 ^ n = 0\ + assumes bit_not_iff: \\n. bit (NOT a) n \ 2 ^ n \ 0 \ \ bit a n\ begin +lemma bits_minus_1_mod_2_eq [simp]: + \(- 1) mod 2 = 1\ + by (simp add: mod_2_eq_odd) + +lemma bit_minus_1_iff [simp]: + \bit (- 1) n \ 2 ^ n \ 0\ + by (simp add: bit_def) + sublocale bit: boolean_algebra \(AND)\ \(OR)\ NOT 0 \- 1\ rewrites \bit.xor = (XOR)\ proof - interpret bit: boolean_algebra \(AND)\ \(OR)\ NOT 0 \- 1\ - by (fact boolean_algebra) + apply standard + apply (auto simp add: bit_eq_iff bit_and_iff bit_or_iff bit_not_iff) + apply (metis local.bit_def local.bit_exp_iff local.bits_div_by_0) + apply (metis local.bit_def local.bit_exp_iff local.bits_div_by_0) + done show \boolean_algebra (AND) (OR) NOT 0 (- 1)\ by standard - show \boolean_algebra.xor (AND) (OR) NOT = (XOR)\ - by (fact boolean_algebra_xor_eq) + show \boolean_algebra.xor (AND) (OR) NOT = (XOR)\ + apply (auto simp add: fun_eq_iff bit.xor_def bit_eq_iff bit_and_iff bit_or_iff bit_not_iff bit_xor_iff) + apply (metis local.bit_def local.bit_exp_iff local.bits_div_by_0) + apply (metis local.bit_def local.bit_exp_iff local.bits_div_by_0) + apply (metis local.bit_def local.bit_exp_iff local.bits_div_by_0) + apply (metis local.bit_def local.bit_exp_iff local.bits_div_by_0) + apply (metis local.bit_def local.bit_exp_iff local.bits_div_by_0) + apply (metis local.bit_def local.bit_exp_iff local.bits_div_by_0) + done qed text \ @@ -265,7 +311,39 @@ "n XOR 0 = n" for n :: nat by simp -instance .. +instance proof + fix m n q :: nat + show \bit (m AND n) q \ bit m q \ bit n q\ + proof (rule sym, induction q arbitrary: m n) + case 0 + then show ?case + by (simp add: and_nat.even_iff) + next + case (Suc q) + with and_nat.rec [of m n] show ?case + by simp + qed + show \bit (m OR n) q \ bit m q \ bit n q\ + proof (rule sym, induction q arbitrary: m n) + case 0 + then show ?case + by (simp add: or_nat.even_iff) + next + case (Suc q) + with or_nat.rec [of m n] show ?case + by simp + qed + show \bit (m XOR n) q \ bit m q \ bit n q\ + proof (rule sym, induction q arbitrary: m n) + case 0 + then show ?case + by (simp add: xor_nat.even_iff) + next + case (Suc q) + with xor_nat.rec [of m n] show ?case + by simp + qed +qed end @@ -625,89 +703,49 @@ lemma even_not_iff [simp]: "even (NOT k) \ odd k" - for k :: int + for k :: int by (simp add: not_int_def) +lemma bit_not_iff_int: + \bit (NOT k) n \ \ bit k n\ + for k :: int + by (induction n arbitrary: k) + (simp_all add: not_int_def flip: complement_div_2) + + instance proof - interpret bit_int: boolean_algebra "(AND)" "(OR)" NOT 0 "- 1 :: int" - proof - show "k AND (l OR r) = k AND l OR k AND r" - for k l r :: int - proof (induction k arbitrary: l r rule: int_bit_induct) - case zero - show ?case - by simp - next - case minus - show ?case - by simp - next - case (even k) - then show ?case by (simp add: and_int.rec [of "k * 2"] - or_int.rec [of "(k AND l div 2) * 2"] or_int.rec [of l]) - next - case (odd k) - then show ?case by (simp add: and_int.rec [of "1 + k * 2"] - or_int.rec [of "(k AND l div 2) * 2"] or_int.rec [of "1 + (k AND l div 2) * 2"] or_int.rec [of l]) - qed - show "k OR l AND r = (k OR l) AND (k OR r)" - for k l r :: int - proof (induction k arbitrary: l r rule: int_bit_induct) - case zero - then show ?case - by simp - next - case minus - then show ?case - by simp - next - case (even k) - then show ?case by (simp add: or_int.rec [of "k * 2"] - and_int.rec [of "(k OR l div 2) * 2"] and_int.rec [of "1 + (k OR l div 2) * 2"] and_int.rec [of l]) - next - case (odd k) - then show ?case by (simp add: or_int.rec [of "1 + k * 2"] - and_int.rec [of "1 + (k OR l div 2) * 2"] and_int.rec [of l]) - qed - show "k AND NOT k = 0" for k :: int - by (induction k rule: int_bit_induct) - (simp_all add: not_int_def complement_half minus_diff_commute [of 1]) - show "k OR NOT k = - 1" for k :: int - by (induction k rule: int_bit_induct) - (simp_all add: not_int_def complement_half minus_diff_commute [of 1]) - qed (simp_all add: and_int.assoc or_int.assoc, - simp_all add: and_int.commute or_int.commute) - show "boolean_algebra (AND) (OR) NOT 0 (- 1 :: int)" - by (fact bit_int.boolean_algebra_axioms) - show "bit_int.xor = ((XOR) :: int \ _)" - proof (rule ext)+ - fix k l :: int - have "k XOR l = k AND NOT l OR NOT k AND l" - proof (induction k arbitrary: l rule: int_bit_induct) - case zero - show ?case - by simp - next - case minus - show ?case - by (simp add: not_int_def) - next - case (even k) - then show ?case - by (simp add: xor_int.rec [of "k * 2"] and_int.rec [of "k * 2"] - or_int.rec [of _ "1 + 2 * NOT k AND l"] not_div_2) - (simp add: and_int.rec [of _ l]) - next - case (odd k) - then show ?case - by (simp add: xor_int.rec [of "1 + k * 2"] and_int.rec [of "1 + k * 2"] - or_int.rec [of _ "2 * NOT k AND l"] not_div_2) - (simp add: and_int.rec [of _ l]) - qed - then show "bit_int.xor k l = k XOR l" - by (simp add: bit_int.xor_def) + fix k l :: int and n :: nat + show \bit (k AND l) n \ bit k n \ bit l n\ + proof (rule sym, induction n arbitrary: k l) + case 0 + then show ?case + by (simp add: and_int.even_iff) + next + case (Suc n) + with and_int.rec [of k l] show ?case + by simp qed -qed + show \bit (k OR l) n \ bit k n \ bit l n\ + proof (rule sym, induction n arbitrary: k l) + case 0 + then show ?case + by (simp add: or_int.even_iff) + next + case (Suc n) + with or_int.rec [of k l] show ?case + by simp + qed + show \bit (k XOR l) n \ bit k n \ bit l n\ + proof (rule sym, induction n arbitrary: k l) + case 0 + then show ?case + by (simp add: xor_int.even_iff) + next + case (Suc n) + with xor_int.rec [of k l] show ?case + by simp + qed +qed (simp_all add: bit_not_iff_int) end @@ -743,36 +781,21 @@ lemma take_bit_not_iff: "Parity.take_bit n (NOT k) = Parity.take_bit n (NOT l) \ Parity.take_bit n k = Parity.take_bit n l" for k l :: int - by (simp add: not_int_def take_bit_complement_iff) + by (auto simp add: bit_eq_iff bit_take_bit_iff bit_not_iff_int) lemma take_bit_and [simp]: "Parity.take_bit n (k AND l) = Parity.take_bit n k AND Parity.take_bit n l" for k l :: int - apply (induction n arbitrary: k l) - apply simp - apply (subst and_int.rec) - apply (subst (2) and_int.rec) - apply simp - done + by (auto simp add: bit_eq_iff bit_take_bit_iff bit_and_iff) lemma take_bit_or [simp]: "Parity.take_bit n (k OR l) = Parity.take_bit n k OR Parity.take_bit n l" for k l :: int - apply (induction n arbitrary: k l) - apply simp - apply (subst or_int.rec) - apply (subst (2) or_int.rec) - apply simp - done + by (auto simp add: bit_eq_iff bit_take_bit_iff bit_or_iff) lemma take_bit_xor [simp]: "Parity.take_bit n (k XOR l) = Parity.take_bit n k XOR Parity.take_bit n l" for k l :: int - apply (induction n arbitrary: k l) - apply simp - apply (subst xor_int.rec) - apply (subst (2) xor_int.rec) - apply simp - done + by (auto simp add: bit_eq_iff bit_take_bit_iff bit_xor_iff) end diff -r 8b8f9d3b3fac -r 6695aeae8ec9 src/HOL/ex/Word.thy --- a/src/HOL/ex/Word.thy Sun Dec 01 11:51:17 2019 +0100 +++ b/src/HOL/ex/Word.thy Mon Dec 02 10:31:51 2019 +0100 @@ -10,6 +10,19 @@ "HOL-ex.Bit_Operations" begin +context + includes lifting_syntax +begin + +lemma transfer_rule_of_bool: + \((\) ===> (\)) of_bool of_bool\ + if [transfer_rule]: \0 \ 0\ \1 \ 1\ + for R :: \'a::zero_neq_one \ 'b::zero_neq_one \ bool\ (infix \\\ 50) + by (unfold of_bool_def [abs_def]) transfer_prover + +end + + subsection \Preliminaries\ lemma length_not_greater_eq_2_iff [simp]: @@ -161,12 +174,18 @@ context includes lifting_syntax - notes transfer_rule_numeral [transfer_rule] + notes + transfer_rule_of_bool [transfer_rule] + transfer_rule_numeral [transfer_rule] transfer_rule_of_nat [transfer_rule] transfer_rule_of_int [transfer_rule] begin lemma [transfer_rule]: + "((=) ===> (pcr_word :: int \ 'a::len word \ bool)) of_bool of_bool" + by transfer_prover + +lemma [transfer_rule]: "((=) ===> (pcr_word :: int \ 'a::len word \ bool)) numeral numeral" by transfer_prover @@ -324,6 +343,10 @@ \a div 0 = 0\ for a :: \'a::len0 word\ by transfer simp +(*lemma + \a div a = of_bool (a \ 0)\ for a :: \'a::len word\ + by transfer simp*) + context includes lifting_syntax begin @@ -389,6 +412,11 @@ by (transfer; cases rule: length_cases [where ?'a = 'a]) (simp_all add: mod_2_eq_odd) qed +(*lemma + \2 ^ n = (0 :: 'a word) \ LENGTH('a::len) \ n\ + apply transfer*) + + subsubsection \Orderings\ @@ -612,6 +640,9 @@ if \even a\ for a :: \'a word\ using that by transfer (auto dest: le_Suc_ex) + show \(2 :: 'a word) ^ m div 2 ^ n = of_bool ((2 :: 'a word) ^ m \ 0 \ n \ m) * 2 ^ (m - n)\ + for m n :: nat + by transfer (simp, simp add: exp_div_exp_eq) show "a div 2 ^ m div 2 ^ n = a div 2 ^ (m + n)" for a :: "'a word" and m n :: nat apply transfer @@ -637,6 +668,23 @@ done qed +context + includes lifting_syntax +begin + +lemma transfer_rule_bit_word [transfer_rule]: + \((pcr_word :: int \ 'a::len word \ bool) ===> (=)) (\k n. n < LENGTH('a) \ bit k n) bit\ +proof - + let ?t = \\a n. odd (take_bit LENGTH('a) a div take_bit LENGTH('a) ((2::int) ^ n))\ + have \((pcr_word :: int \ 'a word \ bool) ===> (=)) ?t bit\ + by (unfold bit_def) transfer_prover + also have \?t = (\k n. n < LENGTH('a) \ bit k n)\ + by (simp add: fun_eq_iff bit_take_bit_iff flip: bit_def) + finally show ?thesis . +qed + +end + instantiation word :: (len) semiring_bit_shifts begin @@ -702,25 +750,18 @@ by simp instance proof - interpret bit_word: boolean_algebra "(AND)" "(OR)" NOT 0 "- 1 :: 'a word" - proof - show "a AND (b OR c) = a AND b OR a AND c" - for a b c :: "'a word" - by transfer (simp add: bit.conj_disj_distrib) - show "a OR b AND c = (a OR b) AND (a OR c)" - for a b c :: "'a word" - by transfer (simp add: bit.disj_conj_distrib) - qed (transfer; simp add: ac_simps)+ - show "boolean_algebra (AND) (OR) NOT 0 (- 1 :: 'a word)" - by (fact bit_word.boolean_algebra_axioms) - show "bit_word.xor = ((XOR) :: 'a word \ _)" - proof (rule ext)+ - fix a b :: "'a word" - have "a XOR b = a AND NOT b OR NOT a AND b" - by transfer (simp add: bit.xor_def) - then show "bit_word.xor a b = a XOR b" - by (simp add: bit_word.xor_def) - qed + fix a b :: \'a word\ and n :: nat + show \even (- 1 div (2 :: 'a word) ^ n) \ (2 :: 'a word) ^ n = 0\ + by transfer + (simp flip: drop_bit_eq_div add: drop_bit_take_bit, simp add: drop_bit_eq_div) + show \bit (NOT a) n \ (2 :: 'a word) ^ n \ 0 \ \ bit a n\ + by transfer (simp add: bit_not_iff) + show \bit (a AND b) n \ bit a n \ bit b n\ + by transfer (auto simp add: bit_and_iff) + show \bit (a OR b) n \ bit a n \ bit b n\ + by transfer (auto simp add: bit_or_iff) + show \bit (a XOR b) n \ bit a n \ bit b n\ + by transfer (auto simp add: bit_xor_iff) qed end