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.2-cp38-abi3-win_arm64.whl (240.6 kB view details)

Uploaded CPython 3.8+Windows ARM64

binar-0.1.2-cp38-abi3-win_amd64.whl (260.0 kB view details)

Uploaded CPython 3.8+Windows x86-64

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

Uploaded CPython 3.8+PyEmscripten 2026.0 wasm32

binar-0.1.2-cp38-abi3-manylinux_2_35_x86_64.whl (309.5 kB view details)

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

binar-0.1.2-cp38-abi3-manylinux_2_35_aarch64.whl (304.0 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.35+ ARM64

binar-0.1.2-cp38-abi3-macosx_11_0_arm64.whl (274.8 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

binar-0.1.2-cp38-abi3-macosx_10_12_x86_64.whl (286.5 kB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: binar-0.1.2-cp38-abi3-win_arm64.whl
  • Upload date:
  • Size: 240.6 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.2-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 cf8a5145c4e884361fef86bcf817bb6c75a3dda7823139f96196e358a79da86a
MD5 6a176e18a45b28634b0e77af3ee73d16
BLAKE2b-256 3548cf912742b89b7727185d4df4df042fc73add44e2bb9488f8e87ddf6c8fe8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: binar-0.1.2-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 260.0 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.2-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 63dc95c53e8bde3954b81837c2423bd004e938152effa92a38dd3b8953962ae3
MD5 3de2fd1ceeb877f75c32d40cb8575588
BLAKE2b-256 87c2566be1052b49c7e0cd721ca19eecd36441d4d9f44c23059089d8aaf865ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for binar-0.1.2-cp38-abi3-pyemscripten_2026_0_wasm32.whl
Algorithm Hash digest
SHA256 17bec798fa6875f7d02c00e1c99b5e5a9a6d802e81524d9a420c6f59f928a478
MD5 20ba2f811506c9e04f96391a7c1136bb
BLAKE2b-256 f96611590ebf70fb91a50c33186921498f535f3cfd884b470a0e8272a7774320

See more details on using hashes here.

File details

Details for the file binar-0.1.2-cp38-abi3-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for binar-0.1.2-cp38-abi3-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 053a750dd14f22362eb799daebaa5e08863e7c00009f7b0714d90e21f760a72f
MD5 fe659f47f6e2591ce373739b669ecab8
BLAKE2b-256 502663ff334f87348878e682b64fdf42d957cd89d2a6cb824ea1470be134aed8

See more details on using hashes here.

File details

Details for the file binar-0.1.2-cp38-abi3-manylinux_2_35_aarch64.whl.

File metadata

File hashes

Hashes for binar-0.1.2-cp38-abi3-manylinux_2_35_aarch64.whl
Algorithm Hash digest
SHA256 66e4a6a06772addfe8d0c28ce31eb4f8423782f43be358747511005814eb085a
MD5 7825d386b555fa1e900c8d2a02981c03
BLAKE2b-256 d2d669e4be4bbdae673d8c749990237bfaae6ab7268c1bf2dcbe982d6c7e0ce0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for binar-0.1.2-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 445d763799c1ea87001eff96c5b14d5fb7a0d5ccf0a83017f98f8c9fd288035b
MD5 9da573fde12c4677a1fa26b186c214a3
BLAKE2b-256 ac3a547490feac1ae1d5902156c5e2f551e857c9c5188acd00d30f402a1306ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for binar-0.1.2-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 44f21cbe86f3f08f5fa74cb24c7f0c241b95a6c99b0532aded238c31c5838256
MD5 8be2ec6fcd09ee36967578ffba19697e
BLAKE2b-256 a403c806a41cf57bbbe42631a2fb23912b8a81790d42f39a74efe865b1d0d632

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.3

7 files

This release

0.1.2 This release

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