Bit-prefix projection of bit strings as an additive homomorphism #
When M ≤ q, taking the first M bits of a q-bit word v : BitString q agrees with
Cslib.BitString.zeroExtend (d' := M) v, forms a surjective additive group homomorphism
Cslib.BitString.restrictBitsAddHom hM : BitString q →+ BitString M, and reduces the unsigned
integer value Cslib.BitString.equivFin q v modulo 2 ^ M
(Cslib.BitString.val_equivFin_restrictBitsAddHom).
Placing these declarations in a dedicated topic module avoids expanding the public interface of the
widely imported CslibFrontier/Foundations/Data/BitString/Basic.lean.
Main definitions #
Cslib.BitString.restrictBitsAddHom: projectingBitString qto its firstM ≤ qbits as an additive group homomorphismBitString q →+ BitString M.
Main results #
Cslib.BitString.restrictBitsAddHom_eq_zeroExtend:restrictBitsAddHom hM vagrees withzeroExtend (d' := M) v.Cslib.BitString.restrictBitsAddHom_zeroExtend,Cslib.BitString.restrictBitsAddHom_surjective:zeroExtendis a right inverse torestrictBitsAddHom hM, which is therefore surjective.Cslib.BitString.val_equivFin_restrictBitsAddHom: the unsigned value ofrestrictBitsAddHom hM vis(equivFin q v).val % 2 ^ M.Cslib.BitString.val_equivFin_eq_div_mod_of_testBit: a bit string read off the binary digitss, …, s + d - 1of a numberNhas valueN / 2 ^ s % 2 ^ d.Cslib.BitString.val_equivFin_zeroExtend_of_ge: widening by zeros preserves the unsigned value.
When M ≤ q, restrictBitsAddHom hM v agrees pointwise with zeroExtend (d' := M) v.
Zero-extending an M-bit string to q ≥ M bits is a right inverse to
restrictBitsAddHom hM.
restrictBitsAddHom hM is surjective whenever M ≤ q.
Extending a word with zero high bits preserves its unsigned value.