Skip to main content

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

binar-0.1.3-cp38-abi3-win_arm64.whl (252.2 kB view details)

Uploaded CPython 3.8+Windows ARM64

binar-0.1.3-cp38-abi3-win_amd64.whl (274.1 kB view details)

Uploaded CPython 3.8+Windows x86-64

binar-0.1.3-cp38-abi3-pyemscripten_2026_0_wasm32.whl (1.1 MB view details)

Uploaded CPython 3.8+PyEmscripten 2026.0 wasm32

binar-0.1.3-cp38-abi3-manylinux_2_28_x86_64.whl (331.2 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.28+ x86-64

binar-0.1.3-cp38-abi3-manylinux_2_28_aarch64.whl (312.8 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.28+ ARM64

binar-0.1.3-cp38-abi3-macosx_11_0_arm64.whl (283.9 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

binar-0.1.3-cp38-abi3-macosx_10_12_x86_64.whl (297.1 kB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file binar-0.1.3-cp38-abi3-win_arm64.whl.

File metadata

  • Download URL: binar-0.1.3-cp38-abi3-win_arm64.whl
  • Upload date:
  • Size: 252.2 kB
  • Tags: CPython 3.8+, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: RestSharp/106.13.0.0

File hashes

Hashes for binar-0.1.3-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 ef5c952383de9efff534b9c6a5e8bfaf4379ae8f49de6d1b8b04f48106c67f48
MD5 5c7f29e086f05e28bc31ef9609e0ba75
BLAKE2b-256 3b777a0c0af7c880230b6641b60ba343307c1434e5bacbe82a2acb756351e3c1

See more details on using hashes here.

File details

Details for the file binar-0.1.3-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: binar-0.1.3-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 274.1 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: RestSharp/106.13.0.0

File hashes

Hashes for binar-0.1.3-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 cfc92b8f7a5a2aa0575dcd6091688a49ebfafeb01e68efda0fce3cff27b2ab26
MD5 48808eb0233b930e154c8cc2ea5c2893
BLAKE2b-256 2192e1307cb4123f57b3492f8bc1e21c509898d1ce9ecf65a9f711807f5e1c2d

See more details on using hashes here.

File details

Details for the file binar-0.1.3-cp38-abi3-pyemscripten_2026_0_wasm32.whl.

File metadata

File hashes

Hashes for binar-0.1.3-cp38-abi3-pyemscripten_2026_0_wasm32.whl
Algorithm Hash digest
SHA256 da1e548338f585a663755ad7faf0cab627c38024d62bbd0b5fe68bf9ef1de855
MD5 0fe5c4aa18298fc2bb88ed30c5cdcf20
BLAKE2b-256 94f3afee10300bf3057b751210cb5b0a690c4a347cb1fe7d813132548778bdad

See more details on using hashes here.

File details

Details for the file binar-0.1.3-cp38-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for binar-0.1.3-cp38-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0a62ff8231d1d55369557321ceb21bde9688e9668c2f5cc666df9a1b3b2500b7
MD5 e243ee0d0177448f2441cc8dced0fc93
BLAKE2b-256 30debb1a0126dfd107011226e0ebee1aaff0544445fbf5d2a46bb2f421ff2dea

See more details on using hashes here.

File details

Details for the file binar-0.1.3-cp38-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for binar-0.1.3-cp38-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a9f9c16aa842053e2c65ddd39407b7795f673fe0dc1b5492f3a1c6929f47d4b0
MD5 cd281675eb59ba359dbc7d343e4ae0cb
BLAKE2b-256 2ec41627fcc226bb7b7236d9790a81602c19a95b692715d1bdf7b040cd5360f3

See more details on using hashes here.

File details

Details for the file binar-0.1.3-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for binar-0.1.3-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d4f7f0a88ee113d5a65db4e0a05266901326d961b2147758f9c102b7f88fc48e
MD5 2b842a5766b9a5a0079f1818b12248d2
BLAKE2b-256 4efdc3fa7842803498c8e05314cc991a89399c5a2db4d9c1aa346f01d2d10dd1

See more details on using hashes here.

File details

Details for the file binar-0.1.3-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for binar-0.1.3-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9e23d47035497060a354fc8fac9cac87f61c6cfd064af94415b5033298725158
MD5 1043937907b28a697c80361c6ca70675
BLAKE2b-256 5ab33cb2d91fcb8ba4c9e0e7e39e503e554fb1e716eec25cca21c1b5c32dca1e

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.3 This release

7 files

0.1.2

7 files

0.1.1

11 files

0.1.0

6 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page