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.5
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.5-cp315-abi3.abi3t-win_arm64.whl
| Download URL | binar-0.1.5-cp315-abi3.abi3t-win_arm64.whl |
|---|---|
| Size | 256.2 kB |
| Tags | CPython 3.15 Windows ARM64 abi3 abi3t |
|
SHA-256 checksum How to use checksums |
ceeef8468c503b4f895e753e56516c1475c188db011e073386a4e77ff3f49614
|
|
BLAKE2b-256 checksum How to use checksums |
58b13ab2aaa33bcf84ba88ec8c244522d9ed74ab1e35fd1ef0190fff24d94484
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.5-cp315-abi3.abi3t-win_amd64.whl
| Download URL | binar-0.1.5-cp315-abi3.abi3t-win_amd64.whl |
|---|---|
| Size | 284.1 kB |
| Tags | CPython 3.15 Windows x86-64 abi3 abi3t |
|
SHA-256 checksum How to use checksums |
650b04727bf890741a30e37de088ad2617ab7ad7cdce7ee4381a129b8271f4e0
|
|
BLAKE2b-256 checksum How to use checksums |
a37043415dcca81b92d8720f39019c9293d4ef5ec45399271a020db9ed4e59ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.5-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl
| Download URL | binar-0.1.5-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 342.4 kB |
| Tags | CPython 3.15 Linux glibc 2.28+ x86-64 abi3 abi3t |
|
SHA-256 checksum How to use checksums |
7495ad62ed28d65753b942edf3c41ab688e58ef1a207a393a2f074a301680be6
|
|
BLAKE2b-256 checksum How to use checksums |
e015a2c7873a3c05a635bb54f31c9c09dad23123286fe6d2bf7f40b3d67ffa52
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.5-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl
| Download URL | binar-0.1.5-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 320.7 kB |
| Tags | CPython 3.15 Linux glibc 2.28+ ARM64 abi3 abi3t |
|
SHA-256 checksum How to use checksums |
9143425b285d846813813a3691438c4ca607d1c7185d6d3ca965433160a23c17
|
|
BLAKE2b-256 checksum How to use checksums |
fd3a7436a26ec4b6644df1a626b67aa9274949c52ec77fe4f4fe850108df686a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.5-cp315-abi3.abi3t-macosx_11_0_arm64.whl
| Download URL | binar-0.1.5-cp315-abi3.abi3t-macosx_11_0_arm64.whl |
|---|---|
| Size | 287.2 kB |
| Tags | CPython 3.15 abi3 abi3t macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
a54f2e6fd604638eb2c08a3c862847f7816ddf76369310d413976a35761e573e
|
|
BLAKE2b-256 checksum How to use checksums |
057dd3c69936b5a5c7e91d26bd7a1f9a9392572e26821c42a82c051337c0f0aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.5-cp315-abi3.abi3t-macosx_10_12_x86_64.whl
| Download URL | binar-0.1.5-cp315-abi3.abi3t-macosx_10_12_x86_64.whl |
|---|---|
| Size | 302.4 kB |
| Tags | CPython 3.15 abi3 abi3t macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
b18f6f00a2dfda3db3162436adf0b71eecb74ff953760584639e6a3667069bdf
|
|
BLAKE2b-256 checksum How to use checksums |
164eb877fb3a586e03d3802682ed25a0e35565ec5655c01d215820d81ea31350
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.5-cp314-cp314t-win_arm64.whl
| Download URL | binar-0.1.5-cp314-cp314t-win_arm64.whl |
|---|---|
| Size | 256.5 kB |
| Tags | CPython 3.14 CPython 3.14 free-threading Windows ARM64 |
|
SHA-256 checksum How to use checksums |
4703850ca3d36fbae8533f35de90193f1e79043aa16f30f7bcdf3300f6265f49
|
|
BLAKE2b-256 checksum How to use checksums |
1cc05207476d593d69d39f4ec59c61343afd1b5f2b3adb51ce4ee9b4cdc9483f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.5-cp314-cp314t-win_amd64.whl
| Download URL | binar-0.1.5-cp314-cp314t-win_amd64.whl |
|---|---|
| Size | 267.5 kB |
| Tags | CPython 3.14 CPython 3.14 free-threading Windows x86-64 |
|
SHA-256 checksum How to use checksums |
714f19789b352fb9b7bd489909498e4fd20b519fe2c6d47da6544da267986549
|
|
BLAKE2b-256 checksum How to use checksums |
e097c276aa4ae51dcf33a95beb37e2d79863f9e8efe74a027faf4a9287b6a783
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.5-cp314-cp314t-manylinux_2_28_x86_64.whl
| Download URL | binar-0.1.5-cp314-cp314t-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 327.5 kB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
205e5aec5ef0d8e660824859ce58a41bf307bf826bf37e55e0a6cfa3950ae489
|
|
BLAKE2b-256 checksum How to use checksums |
06e68a3dae6adcf21a44f67c1520f3e88674fc87d0b1858085ed07e40f005232
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.5-cp314-cp314t-manylinux_2_28_aarch64.whl
| Download URL | binar-0.1.5-cp314-cp314t-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 308.7 kB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
2013f275a5da89130436a1404fb70188fe539ba9b4befe12d95737ced10c8ddb
|
|
BLAKE2b-256 checksum How to use checksums |
7063467ae9928947d21bc6fa2cb1c436abbd8a1fdc63167111dc88e5422c4edc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.5-cp314-cp314t-macosx_11_0_arm64.whl
| Download URL | binar-0.1.5-cp314-cp314t-macosx_11_0_arm64.whl |
|---|---|
| Size | 275.2 kB |
| Tags | CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
15724d1edcc88ebd5b61d95b278d83abd94c5d5372fa8d121a254f9d377696c4
|
|
BLAKE2b-256 checksum How to use checksums |
0c682846bdff722ba67b3312faf94974398f86d5680866674bc97a815ba22fbe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.5-cp314-cp314t-macosx_10_12_x86_64.whl
| Download URL | binar-0.1.5-cp314-cp314t-macosx_10_12_x86_64.whl |
|---|---|
| Size | 288.4 kB |
| Tags | CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
04ecf2e57b0ce760918ff348f780ec4deb70c3395644cecfce79345512215edc
|
|
BLAKE2b-256 checksum How to use checksums |
031ca008af88fe4dca7cec4a25ad7f327dbe3bdcef157da94a2b0e76c7a0ca6d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.5-cp314-cp314-pyemscripten_2026_0_wasm32.whl
| Download URL | binar-0.1.5-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 |
60c2d987303db58d1f820d4d290612715d835fc401c9b9117c35c41bb6033dd7
|
|
BLAKE2b-256 checksum How to use checksums |
0202096b593ef5c9dc6d3914138d2cade0059cbf7b8cea2c19ee8243728326f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.5-cp39-abi3-win_arm64.whl
| Download URL | binar-0.1.5-cp39-abi3-win_arm64.whl |
|---|---|
| Size | 258.6 kB |
| Tags | CPython 3.9 Windows ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
b30be33c13a61e211a41088f80f83b183a5abec14b8afdadea46f0fe914001fb
|
|
BLAKE2b-256 checksum How to use checksums |
246409081d46cbbae75806fe8dea02f6e4663075791089a785c1c41aeb0705f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.5-cp39-abi3-win_amd64.whl
| Download URL | binar-0.1.5-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 267.7 kB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
4e54cc9d91ee92df18fbcd0fb21e80c62e016214e5efa500e62217cb1d7b3d3d
|
|
BLAKE2b-256 checksum How to use checksums |
eb8322c3dea14ff01f8d6415e45beb84923a43593c68d466988444cbd9d49d30
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.5-cp39-abi3-manylinux_2_28_x86_64.whl
| Download URL | binar-0.1.5-cp39-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 331.7 kB |
| Tags | CPython 3.9 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
c39d9283d19a901959a6070075ec359202e4c40e3969502a66a116a9276e6cb6
|
|
BLAKE2b-256 checksum How to use checksums |
3c6b74147c8dd43139d386217f97788d1ac509605d5dc514fd0ec71f360878ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.5-cp39-abi3-manylinux_2_28_aarch64.whl
| Download URL | binar-0.1.5-cp39-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 315.5 kB |
| Tags | CPython 3.9 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
294dc000f8212bc84b89ec37c79bdd0e8fb08a4a7ec04b44d839aad81fcbfdb4
|
|
BLAKE2b-256 checksum How to use checksums |
d68d7b0690bf6213f13d7ee251adc5f3f470e98868c503a950d6e020cb08fec5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.5-cp39-abi3-macosx_11_0_arm64.whl
| Download URL | binar-0.1.5-cp39-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 285.4 kB |
| Tags | CPython 3.9 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
caa32666fb7f58c1cc08be3c2356effb5007842071ff3c5363b0dba6ab24df0a
|
|
BLAKE2b-256 checksum How to use checksums |
1efe7c77233bb0d4aac7c43d8bc2215f0a8bc468202f315add3929a80c28dbf8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / binar-0.1.5-cp39-abi3-macosx_10_12_x86_64.whl
| Download URL | binar-0.1.5-cp39-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 298.8 kB |
| Tags | CPython 3.9 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
5da095d12b95407c117989f53ac60d8011379d9d931f2ba5e03e422482c4deb4
|
|
BLAKE2b-256 checksum How to use checksums |
afdfcd3255fb408331115c590e4711191991f1adecba1042e4c40b569383d85d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|