bit::matrix
— Logical Operators
Methods to perform element-by-element binary AND
, XOR
, OR
, +, -, * between two equal sized bit-matrix.
template<std::unsigned_integral Block, typename Alloc>
constexpr bit::matrix<Block, Alloc>
operator&(const bit::matrix<Block, Alloc> &lhs,
1const bit::matrix<Block, Alloc> &rhs);
operator^(const bit::matrix<Block, Alloc> &lhs,
2const bit::matrix<Block, Alloc> &rhs);
operator|(const bit::matrix<Block, Alloc> &lhs,
3const bit::matrix<Block, Alloc> &rhs);
operator+(const bit::matrix<Block, Alloc> &lhs,
4const bit::matrix<Block, Alloc> &rhs);
operator-(const bit::matrix<Block, Alloc> &lhs,
5const bit::matrix<Block, Alloc> &rhs);
operator*(const bit::matrix<Block, Alloc> &lhs,
6const bit::matrix<Block, Alloc> &rhs);
- 1
-
Returns a bit-matrix, the binary
AND
ofrhs
&lhs
. - 2
-
Returns a bit-matrix, the binary
XOR
ofrhs
&lhs
. - 3
-
Returns a bit-matrix, the binary
OR
ofrhs
&lhs
. - 4
-
Returns a bit-matrix, the binary
XOR
ofrhs
&lhs
.
In \(\mathbb{F}_2\), addition corresponds toXOR
. - 5
-
Returns a bit-matrix, the binary
XOR
ofrhs
&lhs
.
In \(\mathbb{F}_2\), subtraction corresponds toXOR
. - 6
-
Returns a bit-matrix, the binary
AND
ofrhs
&lhs
.
In \(\mathbb{F}_2\), multiplication corresponds toAND
.
The two bit-matrices in question must have the same dimensions. Set the BIT_VERIFY flag at compile time to check this condition — any violation will cause the program to abort with a helpful message.
|
Example
#include <bit/bit.h>
int main()
{
::matrix<> m1(4,[](std::size_t i, std::size_t j) { return (i + j) % 2; });
bitauto m2 = bit::matrix<>::ones(4);
std::cout << "m1:\n" << m1 << '\n';
std::cout << "m2:\n" << m2 << '\n';
std::cout << "m1 & m2:\n" << (m1 & m2) << '\n';
std::cout << "m1 | m2:\n" << (m1 | m2) << '\n';
std::cout << "m1 ^ m2:\n" << (m1 ^ m2) << '\n';
}
Output
m1:
│0 1 0 1│
│1 0 1 0│
│0 1 0 1│
│1 0 1 0│
m2:
│1 1 1 1│
│1 1 1 1│
│1 1 1 1│
│1 1 1 1│
m1 & m2:
│0 1 0 1│
│1 0 1 0│
│0 1 0 1│
│1 0 1 0│
m1 | m2:
│1 1 1 1│
│1 1 1 1│
│1 1 1 1│
│1 1 1 1│
m1 ^ m2:
│1 0 1 0│
│0 1 0 1│
│1 0 1 0│
│0 1 0 1│
See Also
matrix::operator&=
matrix::operator|=
matrix::operator^=
matrix::operator+=
matrix::operator-=
matrix::operator*=
matrix::operator~