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.

  • 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.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for binar 0.1.7
File
binar-0.1.7-cp315-abi3.abi3t-win_arm64.whl CPython 3.15 abi3, abi3t Windows ARM64 Details
binar-0.1.7-cp315-abi3.abi3t-win_amd64.whl CPython 3.15 abi3, abi3t Windows x86-64 Details
binar-0.1.7-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl CPython 3.15 abi3, abi3t Linux glibc 2.28+ x86-64 Details
binar-0.1.7-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl CPython 3.15 abi3t, abi3 Linux glibc 2.28+ ARM64 Details
binar-0.1.7-cp315-abi3.abi3t-macosx_11_0_arm64.whl CPython 3.15 abi3, abi3t macOS 11.0+ ARM64 Details
binar-0.1.7-cp315-abi3.abi3t-macosx_10_12_x86_64.whl CPython 3.15 abi3, abi3t macOS 10.12+ x86-64 Details
binar-0.1.7-cp314-cp314t-win_arm64.whl CPython 3.14 CPython 3.14 free-threading Windows ARM64 Details
binar-0.1.7-cp314-cp314t-win_amd64.whl CPython 3.14 CPython 3.14 free-threading Windows x86-64 Details
binar-0.1.7-cp314-cp314t-manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ x86-64 Details
binar-0.1.7-cp314-cp314t-manylinux_2_28_aarch64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ ARM64 Details
binar-0.1.7-cp314-cp314t-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 Details
binar-0.1.7-cp314-cp314t-macosx_10_12_x86_64.whl CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64 Details
binar-0.1.7-cp314-cp314-pyemscripten_2026_0_wasm32.whl CPython 3.14 CPython 3.14 PyEmscripten 2026.0+ WebAssembly Details
binar-0.1.7-cp39-abi3-win_arm64.whl CPython 3.9 abi3 Windows ARM64 Details
binar-0.1.7-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
binar-0.1.7-cp39-abi3-manylinux_2_28_x86_64.whl CPython 3.9 abi3 Linux glibc 2.28+ x86-64 Details
binar-0.1.7-cp39-abi3-manylinux_2_28_aarch64.whl CPython 3.9 abi3 Linux glibc 2.28+ ARM64 Details
binar-0.1.7-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details
binar-0.1.7-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details

Total release size: 6.4 MB

Release files / binar-0.1.7-cp315-abi3.abi3t-win_arm64.whl

Download URL binar-0.1.7-cp315-abi3.abi3t-win_arm64.whl
Size 256.5 kB
Tags CPython 3.15 Windows ARM64 abi3 abi3t
SHA-256 checksum
How to use checksums
891a125796ddfb4151cfde2b0595593b4c5f5c12372241cb5915da9e13100a3d
BLAKE2b-256 checksum
How to use checksums
c05fb8de2cf8c140d534c3bd13fafcb8f1e9f4cdcf8fbfbab2a502e5b6dbb93e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / binar-0.1.7-cp315-abi3.abi3t-win_amd64.whl

Download URL binar-0.1.7-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
91b6f3ad05a5692c4ee7e648538b82cb1469a42ef78d2fb1c6ea4823a89dff71
BLAKE2b-256 checksum
How to use checksums
c84cbb1fa7b6a509f5ff966746d7f90e254812f892b36fce075b3a7f7ca2141b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / binar-0.1.7-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl

Download URL binar-0.1.7-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
84920d13e0be882e47eb8ba019ff3e8ad425be78eb8d2a91f5611d00612a26a5
BLAKE2b-256 checksum
How to use checksums
75e13dd379a3799411da644b607c6fee5352cf9003ea419b9f62c818d31fc06b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / binar-0.1.7-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl

Download URL binar-0.1.7-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl
Size 322.2 kB
Tags CPython 3.15 Linux glibc 2.28+ ARM64 abi3 abi3t
SHA-256 checksum
How to use checksums
44bf249d8aca505fef61cded99fad94c3fec2c9ec7426f1b381fc0b9ceff887e
BLAKE2b-256 checksum
How to use checksums
78d95c5e1a183a9f1f395d22c2fdf38bca0ae5c7f0a70c9e8ad7946eac5ec895
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / binar-0.1.7-cp315-abi3.abi3t-macosx_11_0_arm64.whl

Download URL binar-0.1.7-cp315-abi3.abi3t-macosx_11_0_arm64.whl
Size 288.9 kB
Tags CPython 3.15 abi3 abi3t macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
f8baa000ca7165d59ade28ffb70d214222df204046615ee1d2cd8b75d8ca6c92
BLAKE2b-256 checksum
How to use checksums
81b14a3745b3dee00a48cefa8928d16fff47d9cacbe42c7b4f24f30b1eee43e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / binar-0.1.7-cp315-abi3.abi3t-macosx_10_12_x86_64.whl

Download URL binar-0.1.7-cp315-abi3.abi3t-macosx_10_12_x86_64.whl
Size 305.0 kB
Tags CPython 3.15 abi3 abi3t macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
b94b84fb62b56336230a6f651691ced136c1ee58a7942fd0dad8a813d32443f2
BLAKE2b-256 checksum
How to use checksums
1baa614f48275c5ed72f1f2c76387128b5da03926c28dd97c0c2b9b4cbbf031e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / binar-0.1.7-cp314-cp314t-win_arm64.whl

Download URL binar-0.1.7-cp314-cp314t-win_arm64.whl
Size 257.2 kB
Tags CPython 3.14 CPython 3.14 free-threading Windows ARM64
SHA-256 checksum
How to use checksums
56a90ebcd23f13545274031b462cd257aff76f3211e2b858a86eea31baac7255
BLAKE2b-256 checksum
How to use checksums
7a04849b0ec0910227e188609a5bb81cca1da70fe1ee5bba6e1280ebabb645bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / binar-0.1.7-cp314-cp314t-win_amd64.whl

Download URL binar-0.1.7-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
69194e7101c4f26740e90ee7877ed32d927a11c1e17e34b3668ad9ab8faa1a86
BLAKE2b-256 checksum
How to use checksums
1b2b12fe851b4031a9a623514edc14d1e5f7d6a336b1a37eb1aaa2f6fc794d1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / binar-0.1.7-cp314-cp314t-manylinux_2_28_x86_64.whl

Download URL binar-0.1.7-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
edbdc200c94317affb9da62c8e10578f46ddd6d90454a4099c18210b2cf014c1
BLAKE2b-256 checksum
How to use checksums
7b2839d5f3f28da218c367764e17fe9055e384b40bbb58b04f5f346dcd92d233
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / binar-0.1.7-cp314-cp314t-manylinux_2_28_aarch64.whl

Download URL binar-0.1.7-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
10616fc306b705f76e4379d3f90397f936226b794219c11d09907c0c765c37fe
BLAKE2b-256 checksum
How to use checksums
e5353d11cb83a7211ac1930590f603416fed4bfbf1bce72b2429089a33889507
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / binar-0.1.7-cp314-cp314t-macosx_11_0_arm64.whl

Download URL binar-0.1.7-cp314-cp314t-macosx_11_0_arm64.whl
Size 276.6 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
768161ce005f741a988a0c4efff87cb6eb539ab69ad2244dd3947f7ced8f20dc
BLAKE2b-256 checksum
How to use checksums
4c610185fbfd025387ab042f3deb699ab327f555ac8052645b55a5a9fcb2cc79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / binar-0.1.7-cp314-cp314t-macosx_10_12_x86_64.whl

Download URL binar-0.1.7-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
3529b2e4c438780ed9966e21c7b11883c64a92d11f03dd833b0e61872aec9a39
BLAKE2b-256 checksum
How to use checksums
170a91940a24fb58b975fb81c978c014680ce55de3ef4c4597af51e76755b8e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / binar-0.1.7-cp314-cp314-pyemscripten_2026_0_wasm32.whl

Download URL binar-0.1.7-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
2a7043faaeb04a7755904ee0ef08af5d6dd21ddc8d32bfaf5f6c88367a1f781b
BLAKE2b-256 checksum
How to use checksums
ecf1c86be93a5017633426d885469dcdb273d42b354dad5aaf56d51b8a39fa17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / binar-0.1.7-cp39-abi3-win_arm64.whl

Download URL binar-0.1.7-cp39-abi3-win_arm64.whl
Size 259.3 kB
Tags CPython 3.9 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
a89d8986895c9831b60433dd7aafd6071b5199d54984a572f3585c71248e465f
BLAKE2b-256 checksum
How to use checksums
13b469fc083ad176f898ad0735159d3435b546c910e3fff1c0a4d132e4999f6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / binar-0.1.7-cp39-abi3-win_amd64.whl

Download URL binar-0.1.7-cp39-abi3-win_amd64.whl
Size 269.6 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
d61bcae8de2df99cde868979e17a226122b70a4ba2cdf235148d707a2f837137
BLAKE2b-256 checksum
How to use checksums
e1097b6f90dae7a894a44a04a0428d5e41caf91f899661126d39c37043c53361
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / binar-0.1.7-cp39-abi3-manylinux_2_28_x86_64.whl

Download URL binar-0.1.7-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
4578359c230318214dcdf5bf4a12877f7740bf7e441ebaa1bc17f9ee86ca635c
BLAKE2b-256 checksum
How to use checksums
eefa78525e732f6336e85c0a451294e63c45e3569888218db2c8f576a1f71566
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / binar-0.1.7-cp39-abi3-manylinux_2_28_aarch64.whl

Download URL binar-0.1.7-cp39-abi3-manylinux_2_28_aarch64.whl
Size 317.2 kB
Tags CPython 3.9 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
f515779d97baac74ca8b178d61a6e3b7ee96814fee39fe24e66b7f09987ce313
BLAKE2b-256 checksum
How to use checksums
556d88c7545b5305b435053572d3394555a575d77b8ab2e46c1500c2d9f69399
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / binar-0.1.7-cp39-abi3-macosx_11_0_arm64.whl

Download URL binar-0.1.7-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
89fae898c19bfa5fe804dd3aebcb992b45fcdf8e1f4bba2c660b4ddac80cc275
BLAKE2b-256 checksum
How to use checksums
eb9a4147acc0f719457db5eb8f289c85b851f59ac7664fb307afdb08fba82cf3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / binar-0.1.7-cp39-abi3-macosx_10_12_x86_64.whl

Download URL binar-0.1.7-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
d18e0e7e8fe22ada38f624546e3df7aa8ea56920026190a4a606d7e40ee712bb
BLAKE2b-256 checksum
How to use checksums
0af3c0bf01c82a122559545be9dcc7edd608eb2bc86cc2e062ff5d7ed8d04121
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release history Release notifications | RSS feed

This release

0.1.7 This release

19 release files

0.1.6

19 release files

0.1.5

19 release files

0.1.4

7 release files

0.1.3

7 release files

0.1.2

7 release files

0.1.1

11 release files

0.1.0

6 release 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