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.
Metadata
Release files for binar 0.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 6.4 MB
Release files / binar-0.1.8-cp315-abi3.abi3t-win_arm64.whl
| Download URL | binar-0.1.8-cp315-abi3.abi3t-win_arm64.whl |
|---|---|
| Size | 256.6 kB |
| Tags | CPython 3.15 Windows ARM64 abi3 abi3t |
|
SHA-256 checksum How to use checksums |
ca94f42651526177347fec87176c0f7697f9f5d044b058cd352bc80bd2422e41
|
|
BLAKE2b-256 checksum How to use checksums |
c027f054150f793f9a29ffb442e761134c88e0ee608fc0b303a1309d73bddc52
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.8-cp315-abi3.abi3t-win_amd64.whl
| Download URL | binar-0.1.8-cp315-abi3.abi3t-win_amd64.whl |
|---|---|
| Size | 283.5 kB |
| Tags | CPython 3.15 Windows x86-64 abi3 abi3t |
|
SHA-256 checksum How to use checksums |
bda07f35ddc0667e1106d0ab9e40b5ba0f9b5bd999d5d4cc0e461aeb0e7518a1
|
|
BLAKE2b-256 checksum How to use checksums |
f8a3e3b1c0ff543d705c512c274287011d55053723f13e12eaf529a4d96e876a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.8-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl
| Download URL | binar-0.1.8-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 344.9 kB |
| Tags | CPython 3.15 Linux glibc 2.28+ x86-64 abi3 abi3t |
|
SHA-256 checksum How to use checksums |
ef70ccf494b05786d63ab785f303bdb9e6c80faa9fdfc67210a79c3247652ca7
|
|
BLAKE2b-256 checksum How to use checksums |
d45d7b766d6aa99d05df493dd5389add90689c18447f06547e3a39222ebc6112
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.8-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl
| Download URL | binar-0.1.8-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 322.3 kB |
| Tags | CPython 3.15 Linux glibc 2.28+ ARM64 abi3 abi3t |
|
SHA-256 checksum How to use checksums |
e11a1efc13d91f48013043cb6638fb8a29340213a594613cffbc8999c1c55c00
|
|
BLAKE2b-256 checksum How to use checksums |
49e47dbf820c5915a354b735ca9da0c3c7770df5260abb90088735faee96ceb4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.8-cp315-abi3.abi3t-macosx_11_0_arm64.whl
| Download URL | binar-0.1.8-cp315-abi3.abi3t-macosx_11_0_arm64.whl |
|---|---|
| Size | 288.8 kB |
| Tags | CPython 3.15 abi3 abi3t macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
a3766ccf59014639fe49dfc7ee0a5cafab7ec38cf7371ff86139826de7bf128c
|
|
BLAKE2b-256 checksum How to use checksums |
bde2f50f7dcc224a9f307dfb09c68bdee635c335de465576c78e0a7168a3bee7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.8-cp315-abi3.abi3t-macosx_10_12_x86_64.whl
| Download URL | binar-0.1.8-cp315-abi3.abi3t-macosx_10_12_x86_64.whl |
|---|---|
| Size | 305.1 kB |
| Tags | CPython 3.15 abi3 abi3t macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
113788b3b9febf4564087f96e29f2c063160008742dce5d211337897578c731e
|
|
BLAKE2b-256 checksum How to use checksums |
632cd2c747c6926f715363b152f58886c23fccefe3bc106fcfddc156b385967d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.8-cp314-cp314t-win_arm64.whl
| Download URL | binar-0.1.8-cp314-cp314t-win_arm64.whl |
|---|---|
| Size | 257.4 kB |
| Tags | CPython 3.14 CPython 3.14 free-threading Windows ARM64 |
|
SHA-256 checksum How to use checksums |
df863d74ed338be13deb13d105fb4b708d8e9755a701cadb3fa96fa7a7d1cebf
|
|
BLAKE2b-256 checksum How to use checksums |
1b8c44993fc6006aa1272266e2d49308e74c311d2b10bb4771396b5bf9104e54
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.8-cp314-cp314t-win_amd64.whl
| Download URL | binar-0.1.8-cp314-cp314t-win_amd64.whl |
|---|---|
| Size | 267.6 kB |
| Tags | CPython 3.14 CPython 3.14 free-threading Windows x86-64 |
|
SHA-256 checksum How to use checksums |
637edb78e1d6b12c90fbf6249248e1490d3a2014c4c94ee4e6d1a677c77c6c94
|
|
BLAKE2b-256 checksum How to use checksums |
2cfd63c7cf8da38e57d34a433690609aff4c14b00513a6813e9c51bc6ef33f1e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.8-cp314-cp314t-manylinux_2_28_x86_64.whl
| Download URL | binar-0.1.8-cp314-cp314t-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 329.8 kB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
d03cf1ad804df6f9b7daa480b6035e553d799a5cf25766cde728caccaa07b58e
|
|
BLAKE2b-256 checksum How to use checksums |
f523d07024099330664b6c5983ed3f3e7e6398cc49b18200724baa8120ffffb5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.8-cp314-cp314t-manylinux_2_28_aarch64.whl
| Download URL | binar-0.1.8-cp314-cp314t-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 310.5 kB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
e26f297d5bc9f760450eff77cf461031a25289a25bad3dd2f03841754ab767ab
|
|
BLAKE2b-256 checksum How to use checksums |
3e7df20935a4fa9d0277cc6f41a06a74c3fd9132225891bd6b40c5689e6abeb8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.8-cp314-cp314t-macosx_11_0_arm64.whl
| Download URL | binar-0.1.8-cp314-cp314t-macosx_11_0_arm64.whl |
|---|---|
| Size | 276.7 kB |
| Tags | CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
c5b48be80b1d4ce05b7dab2716567308a780780f3f7fc2544ca476b84dfa3d00
|
|
BLAKE2b-256 checksum How to use checksums |
cd70e0b40451100f21116da71ee0269615a5f8b2d1f0f06677b1936f20f36655
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.8-cp314-cp314t-macosx_10_12_x86_64.whl
| Download URL | binar-0.1.8-cp314-cp314t-macosx_10_12_x86_64.whl |
|---|---|
| Size | 290.9 kB |
| Tags | CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
e1610b8d5503a92f315130d9fbe9739202f6338240252c381425818225c8bbb7
|
|
BLAKE2b-256 checksum How to use checksums |
7305e1f33a48e782d11e188559709609b369a1802ae1b1dd0f5ba721096f11cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.8-cp314-cp314-pyemscripten_2026_0_wasm32.whl
| Download URL | binar-0.1.8-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 |
c4181869b5040e982de05177cdd42c65018348c337b52624087b7c643807aa51
|
|
BLAKE2b-256 checksum How to use checksums |
f62a667ae7e5e2dd6adde8e7998cfe4e6f067fcf5708fb1ed85456e1cc0b651f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.8-cp39-abi3-win_arm64.whl
| Download URL | binar-0.1.8-cp39-abi3-win_arm64.whl |
|---|---|
| Size | 259.4 kB |
| Tags | CPython 3.9 Windows ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
6cb35005b905804dbd9ff718ff21c49720bfd074f784e84b28b7a1d01ccad469
|
|
BLAKE2b-256 checksum How to use checksums |
0f877183e4940457c55c8e4c94df666977e955a891907188daf29510adbb684e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.8-cp39-abi3-win_amd64.whl
| Download URL | binar-0.1.8-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 269.7 kB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
82fab59bc8aad14370717584810f8572fe14bc5b13a1c058101fbef553d67a68
|
|
BLAKE2b-256 checksum How to use checksums |
8de04983581bd28886396179ea66de50f3e6f566773a73456eab78db048f8c0a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.8-cp39-abi3-manylinux_2_28_x86_64.whl
| Download URL | binar-0.1.8-cp39-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 334.4 kB |
| Tags | CPython 3.9 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
9e904767f05b7f61902c123d11b7953d5a8f0215dd030607c88d6fd5968d832c
|
|
BLAKE2b-256 checksum How to use checksums |
b6397a0752c766d3b6d5609f7ec3751674084fe452325699268102d5fbe9842d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.8-cp39-abi3-manylinux_2_28_aarch64.whl
| Download URL | binar-0.1.8-cp39-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 317.3 kB |
| Tags | CPython 3.9 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
3a0e480846de81aa6146620dd568edefd38300724b40934ba2d85a01740481ef
|
|
BLAKE2b-256 checksum How to use checksums |
1047346c3d8d70f5a6415217226e6fb4522d6439c38c2c9817a449a7a83f518f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.8-cp39-abi3-macosx_11_0_arm64.whl
| Download URL | binar-0.1.8-cp39-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 287.1 kB |
| Tags | CPython 3.9 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
f4f11ee1c070842ab4304f59ffc1315b8f9b9ce85fa19aac74ee80a16594c86d
|
|
BLAKE2b-256 checksum How to use checksums |
4e51a9530956f08106fdd74373fb2372ac1f66038d1cf86035dfc2c3a878250b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.8-cp39-abi3-macosx_10_12_x86_64.whl
| Download URL | binar-0.1.8-cp39-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 301.0 kB |
| Tags | CPython 3.9 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
9883defa0a52f1548c3b79fb7d283ed984a26ba4848c04e399176f1f662a072e
|
|
BLAKE2b-256 checksum How to use checksums |
48312e06d0d9b1d15dc23e877307bd1f650bcc8340c07985d037480b42a7fca7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Security for binar 0.1.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.