binar - High-performance binary arithmetic
Fast bit vectors and bit matrices with linear algebra over GF(2).
Overview
binar provides efficient Python bindings to high-performance Rust implementations of:
- Bit vectors (
BitVector) - Variable-length sequences of bits - Bit matrices (
BitMatrix) - 2D arrays of bits with linear algebra operations - Operations optimized for quantum computing and error correction
The library is designed for applications requiring fast linear algebra over GF(2) (the binary field with elements {0, 1}), where addition is XOR and multiplication is AND.
Installation
pip install binar
For development:
cd binar/bindings/python
maturin develop --release
Quick Start
import binar
# Bit vectors: create, manipulate, and compute
v1 = binar.BitVector("10110")
v2 = binar.BitVector([True, False, True, False, False])
print(v1.weight) # 3 (number of 1s)
print(v1.support) # [0, 2, 3] (indices of 1s)
# Boolean operations
v3 = v1 ^ v2 # XOR
print(v1.dot(v2)) # Inner product over GF(2)
# Bit matrices: linear algebra over GF(2)
m = binar.BitMatrix([
"1010",
"0110",
"1100",
"0011"
])
print(m.shape) # (4, 4)
# Matrix operations
identity = binar.BitMatrix.identity(4)
product = m @ identity # Matrix multiplication
m_rref = m.echelonized() # Row echelon form
kernel = m.kernel() # Null space basis
Key Features
BitVector
- Create from strings, lists, or factory methods
- Boolean operations: XOR, AND, OR
- Hamming weight and parity computation
- Inner product over GF(2)
- Support (indices of set bits)
BitMatrix
- Create from rows or factory methods
- Matrix multiplication over GF(2)
- Element-wise boolean operations
- Row echelon form and reduced row echelon form
- Null space (kernel) computation
- Transpose and submatrix extraction
Use Cases
binar is particularly useful for:
- Quantum error correction: Parity check matrices, stabilizer codes
- Linear codes: Generator and check matrices over GF(2)
- Graph theory: Adjacency matrices, graph algorithms
- Cryptography: Linear feedback shift registers, boolean functions
- Computational algebra: Gaussian elimination, system solving over GF(2)
Performance
Built on optimized Rust code with:
- SIMD acceleration for bit operations
- Cache-friendly memory layout
- Efficient Gaussian elimination algorithms
- Zero-copy integration between Python and Rust
Examples
Solving Linear Systems over GF(2)
import binar
# Coefficient matrix
A = binar.BitMatrix([
"110",
"101",
"011"
])
# Find kernel (solutions to Ax = 0)
kernel = A.kernel()
print(f"Null space dimension: {kernel.row_count}")
# Verify solution
for row in kernel.rows:
result = A @ row
assert result.is_zero # Ax = 0
Parity Check Matrix for [7,4,3] Hamming Code
import binar
# Parity check matrix for [7,4,3] Hamming code
H = binar.BitMatrix([
"1010101",
"0110011",
"0001111"
])
# Check syndrome for error vector
error = binar.BitVector("0001000") # Error on bit 3
syndrome = H @ error
print(f"Syndrome: {syndrome}") # Points to error location
# Generate all codewords by finding kernel
codewords = H.kernel()
print(f"Code dimension: {codewords.row_count}") # 4
API Reference
See the type stubs file for complete API documentation with type hints.
Related Packages
- paulimer: Pauli and Clifford algebra built on binar
License
MIT License - See LICENSE file for details.
Contributing
Contributions welcome! See github.com/microsoft/qdk-ec for guidelines.
Release files for binar 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| binar-0.1.4-cp314-cp314-pyemscripten_2026_0_wasm32.whl | CPython 3.14 | CPython 3.14 | PyEmscripten 2026.0+ WebAssembly | Details |
| binar-0.1.4-cp39-abi3-win_arm64.whl | CPython 3.9 | abi3 | Windows ARM64 | Details |
| binar-0.1.4-cp39-abi3-win_amd64.whl | CPython 3.9 | abi3 | Windows x86-64 | Details |
| binar-0.1.4-cp39-abi3-manylinux_2_28_x86_64.whl | CPython 3.9 | abi3 | Linux glibc 2.28+ x86-64 | Details |
| binar-0.1.4-cp39-abi3-manylinux_2_28_aarch64.whl | CPython 3.9 | abi3 | Linux glibc 2.28+ ARM64 | Details |
| binar-0.1.4-cp39-abi3-macosx_11_0_arm64.whl | CPython 3.9 | abi3 | macOS 11.0+ ARM64 | Details |
| binar-0.1.4-cp39-abi3-macosx_10_12_x86_64.whl | CPython 3.9 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 2.9 MB
Release files / binar-0.1.4-cp314-cp314-pyemscripten_2026_0_wasm32.whl
| Download URL | binar-0.1.4-cp314-cp314-pyemscripten_2026_0_wasm32.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.14 PyEmscripten 2026.0+ WebAssembly |
|
SHA-256 checksum How to use checksums |
74b053dc5b6216c25e92ae657cd4f97cca2916c0c398158cecd385b2d8030e85
|
|
BLAKE2b-256 checksum How to use checksums |
702c0124365ca17dc34ce928e9be4ffda1bd86771a295d1de5ddfc8a9fb25dd7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.4-cp39-abi3-win_arm64.whl
| Download URL | binar-0.1.4-cp39-abi3-win_arm64.whl |
|---|---|
| Size | 258.0 kB |
| Tags | CPython 3.9 Windows ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
5ea9629da10a1be1c4d44ace818a9f238d31b4eb139fd11ccfe56ff29e52e41a
|
|
BLAKE2b-256 checksum How to use checksums |
0c326da9d757835055d7a17d2cbbe127304e41f5648d8e56516e2166dd6866b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.4-cp39-abi3-win_amd64.whl
| Download URL | binar-0.1.4-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 266.9 kB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
a29cc9f63c384c02877963823d84be31fe00fbead37370be626947418c65fded
|
|
BLAKE2b-256 checksum How to use checksums |
320e6f0b0e119c3b99c96f483c8134944cc666f5fda985a5f90133628f30bf5d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.4-cp39-abi3-manylinux_2_28_x86_64.whl
| Download URL | binar-0.1.4-cp39-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 330.8 kB |
| Tags | CPython 3.9 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
bda5a13c931ec6d335ebddd9c2aef27f8518265a1da8b17cbd597d88ce46881d
|
|
BLAKE2b-256 checksum How to use checksums |
0abb083c87be5fa4bd1e484d0bd5a45b4305cc44353b9a271601769c393e4c18
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.4-cp39-abi3-manylinux_2_28_aarch64.whl
| Download URL | binar-0.1.4-cp39-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 314.6 kB |
| Tags | CPython 3.9 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
8edb331b77077a85d0f6f502798d02694d3d1b43ec1e67a46c560d30d89af5e6
|
|
BLAKE2b-256 checksum How to use checksums |
c7533b49a6405fa6bcac3e7f235c91830894064aa4dc367b9b6cbbee8d652086
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.4-cp39-abi3-macosx_11_0_arm64.whl
| Download URL | binar-0.1.4-cp39-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 284.2 kB |
| Tags | CPython 3.9 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
8ae9f82a30fc31efba492d6a0b1b251a23ec8a55cbd21d7a0efc6015b5aed147
|
|
BLAKE2b-256 checksum How to use checksums |
101336f8a347b8ae0f38fc19b55dfc1291fd9b55c6f16b7d4e76eeaf900d0761
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.4-cp39-abi3-macosx_10_12_x86_64.whl
| Download URL | binar-0.1.4-cp39-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 297.9 kB |
| Tags | CPython 3.9 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
96ef703e3f22b50a71ed51c245668624731e989ff7113102bf189f27a1cce531
|
|
BLAKE2b-256 checksum How to use checksums |
955174c47074440921a1ac3103c94b94a3e77f71a1203bc2c3443eed2d386dfe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|