(* Title: HOL/Library/Z2.thy Author: Brian Huffman *)
section‹The Field of Integers mod 2›
theory Z2 imports Main begin
text‹ Note that in most cases 🍋‹bool›is appropriate when a binary type is needed; the type provided here, for historical reasons named 🪙‹bit›, is only needed if proper field operations are required. ›
typedef bit = ‹UNIV :: bool set› ..
instantiation bit :: zero_neq_one begin
definition zero_bit :: bit where‹0 = Abs_bit False›
definition one_bit :: bit where‹1 = Abs_bit True›
instance by standard (simp add: zero_bit_def one_bit_def Abs_bit_inject)
end
free_constructors case_bit for‹0::bit› | ‹1::bit› proof - fix P :: bool fix a :: bit assume‹a = 0 ==> P›and‹a = 1 ==> P› thenshow P by (cases a) (auto simp add: zero_bit_def one_bit_def Abs_bit_inject) qed simp
lemma bit_not_zero_iff [simp]: ‹a ≠ 0 ⟷ a = 1›for a :: bit by (cases a) simp_all
lemma bit_not_one_iff [simp]: ‹a ≠ 1 ⟷ a = 0›for a :: bit by (cases a) simp_all
instantiation bit :: semidom_modulo begin
definition plus_bit :: ‹bit ==> bit ==> bit› where‹a + b = Abs_bit (Rep_bit a ≠ Rep_bit b)›
definition minus_bit :: ‹bit ==> bit ==> bit› where [simp]: ‹minus_bit = plus›
definition times_bit :: ‹bit ==> bit ==> bit› where‹a * b = Abs_bit (Rep_bit a ∧ Rep_bit b)›
definition divide_bit :: ‹bit ==> bit ==> bit› where [simp]: ‹divide_bit = times›
definition modulo_bit :: ‹bit ==> bit ==> bit› where‹a mod b = Abs_bit (Rep_bit a ∧¬ Rep_bit b)›
instance by standard
(auto simp flip: Rep_bit_inject
simp add: zero_bit_def one_bit_def plus_bit_def times_bit_def modulo_bit_def Abs_bit_inverse Rep_bit_inverse)
qualified lemma bit_eq_iff: ‹a = b ⟷ (even a ⟷ even b)›for a b :: bit by (cases a; cases b) simp_all
end
lemma modulo_bit_unfold [simp, code]: ‹a mod b = of_bool (odd a ∧ even b)›for a b :: bit by (simp add: modulo_bit_def Abs_bit_eq_of_bool Rep_bit_eq_odd)
lemma power_bit_unfold [simp]: ‹a ^ n = of_bool (odd a ∨ n = 0)›for a :: bit by (cases a) simp_all
definition bit_bit :: ‹bit ==> nat ==> bool› where [simp]: ‹bit_bit b n ⟷ odd b ∧ n = 0›
instance by standard
(auto intro: Abs_bit_induct simp add: Abs_bit_eq_of_bool)
end
instantiation bit :: ring_bit_operations begin
context includes bit_operations_syntax begin
definition not_bit :: ‹bit ==> bit› where [simp]: ‹NOT b = of_bool (even b)›for b :: bit
definition and_bit :: ‹bit ==> bit ==> bit› where [simp]: ‹b AND c = of_bool (odd b ∧ odd c)›for b c :: bit
definition or_bit :: ‹bit ==> bit ==> bit› where [simp]: ‹b OR c = of_bool (odd b ∨ odd c)›for b c :: bit
definition xor_bit :: ‹bit ==> bit ==> bit› where [simp]: ‹b XOR c = of_bool (odd b ≠ odd c)›for b c :: bit
definition mask_bit :: ‹nat ==> bit› where [simp]: ‹mask n = (of_bool (n > 0) :: bit)›
definition set_bit_bit :: ‹nat ==> bit ==> bit› where [simp]: ‹set_bit n b = of_bool (n = 0 ∨ odd b)›for b :: bit
definition unset_bit_bit :: ‹nat ==> bit ==> bit› where [simp]: ‹unset_bit n b = of_bool (n > 0 ∧ odd b)›for b :: bit
definition flip_bit_bit :: ‹nat ==> bit ==> bit› where [simp]: ‹flip_bit n b = of_bool ((n = 0) ≠ odd b)›for b :: bit
definition push_bit_bit :: ‹nat ==> bit ==> bit› where [simp]: ‹push_bit n b = of_bool (odd b ∧ n = 0)›for b :: bit
definition drop_bit_bit :: ‹nat ==> bit ==> bit› where [simp]: ‹drop_bit n b = of_bool (odd b ∧ n = 0)›for b :: bit
definition take_bit_bit :: ‹nat ==> bit ==> bit› where [simp]: ‹take_bit n b = of_bool (odd b ∧ n > 0)›for b :: bit
end
instance by standard auto
end
lemma add_bit_eq_xor [simp, code]: ‹(+) = (Bit_Operations.xor :: bit ==> _)› by (auto simp add: fun_eq_iff)
lemma mult_bit_eq_and [simp, code]: ‹(*) = (Bit_Operations.and :: bit \ _)\ by (simp add: fun_eq_iff) lemma bit_numeral_even [simp]: ‹numeral (Num.Bit0 n) = (0 :: bit)› by (simp only: Z2.bit_eq_iff even_numeral) simp lemma bit_numeral_odd [simp]: ‹numeral (Num.Bit1 n) = (1 :: bit)› by (simp only: Z2.bit_eq_iff odd_numeral) simp end
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.6Bemerkung:
(vorverarbeitet am 2026-04-27)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.