Bitwise operations on integers #
Possibly only of archaeological significance.
Recursors #
Int.bitCasesOn
: Parity disjunction. Something is true/defined onℤ
if it's true/defined for even and for odd values.
div2 n = n/2
Equations
- (Int.ofNat n).div2 = ↑n.div2
- (Int.negSucc n).div2 = Int.negSucc n.div2
Instances For
Int.natBitwise
is an auxiliary definition for Int.bitwise
.
Equations
- Int.natBitwise f m n = bif f false false then Int.negSucc (Nat.bitwise (fun (x y : Bool) => !f x y) m n) else ↑(Nat.bitwise f m n)
Instances For
Int.bitwise
applies the function f
to pairs of bits in the same position in
the binary representations of its inputs.
Equations
- Int.bitwise f (Int.ofNat m) (Int.ofNat n) = Int.natBitwise f m n
- Int.bitwise f (Int.ofNat m) (Int.negSucc n) = Int.natBitwise (fun (x y : Bool) => f x !y) m n
- Int.bitwise f (Int.negSucc m) (Int.ofNat n) = Int.natBitwise (fun (x y : Bool) => f (!x) y) m n
- Int.bitwise f (Int.negSucc m) (Int.negSucc n) = Int.natBitwise (fun (x y : Bool) => f (!x) !y) m n
Instances For
lnot
flips all the bits in the binary representation of its input
Equations
- (Int.ofNat n).lnot = Int.negSucc n
- (Int.negSucc n).lnot = ↑n
Instances For
lor
takes two integers and returns their bitwise or
Equations
- (Int.ofNat m).lor (Int.ofNat n) = ↑(m ||| n)
- (Int.ofNat m).lor (Int.negSucc n) = Int.negSucc (n.ldiff m)
- (Int.negSucc m).lor (Int.ofNat n) = Int.negSucc (m.ldiff n)
- (Int.negSucc m).lor (Int.negSucc n) = Int.negSucc (m &&& n)
Instances For
land
takes two integers and returns their bitwise and
Equations
- (Int.ofNat m).land (Int.ofNat n) = ↑(m &&& n)
- (Int.ofNat m).land (Int.negSucc n) = ↑(m.ldiff n)
- (Int.negSucc m).land (Int.ofNat n) = ↑(n.ldiff m)
- (Int.negSucc m).land (Int.negSucc n) = Int.negSucc (m ||| n)
Instances For
ldiff a b
performs bitwise set difference. For each corresponding
pair of bits taken as booleans, say aᵢ
and bᵢ
, it applies the
boolean operation aᵢ ∧ bᵢ
to obtain the iᵗʰ
bit of the result.
Equations
- (Int.ofNat m).ldiff (Int.ofNat n) = ↑(m.ldiff n)
- (Int.ofNat m).ldiff (Int.negSucc n) = ↑(m &&& n)
- (Int.negSucc m).ldiff (Int.ofNat n) = Int.negSucc (m ||| n)
- (Int.negSucc m).ldiff (Int.negSucc n) = ↑(n.ldiff m)
Instances For
xor
computes the bitwise xor
of two natural numbers
Equations
- (Int.ofNat m).xor (Int.ofNat n) = ↑(m ^^^ n)
- (Int.ofNat m).xor (Int.negSucc n) = Int.negSucc (m ^^^ n)
- (Int.negSucc m).xor (Int.ofNat n) = Int.negSucc (m ^^^ n)
- (Int.negSucc m).xor (Int.negSucc n) = ↑(m ^^^ n)
Instances For
m <<< n
produces an integer whose binary representation
is obtained by left-shifting the binary representation of m
by n
places
Equations
- One or more equations did not get rendered due to their size.
m >>> n
produces an integer whose binary representation
is obtained by right-shifting the binary representation of m
by n
places
Equations
- Int.instShiftRight_mathlib = { shiftRight := fun (m n : ℤ) => m <<< (-n) }
bitwise ops #
bitwise ops #
Compare with Int.zero_shiftRight
, which has n : ℕ
.