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

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.6
File
binar-0.1.6-cp315-abi3.abi3t-win_arm64.whl CPython 3.15 abi3, abi3t Windows ARM64 Details
binar-0.1.6-cp315-abi3.abi3t-win_amd64.whl CPython 3.15 abi3, abi3t Windows x86-64 Details
binar-0.1.6-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl CPython 3.15 abi3t, abi3 Linux glibc 2.28+ x86-64 Details
binar-0.1.6-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl CPython 3.15 abi3t, abi3 Linux glibc 2.28+ ARM64 Details
binar-0.1.6-cp315-abi3.abi3t-macosx_11_0_arm64.whl CPython 3.15 abi3, abi3t macOS 11.0+ ARM64 Details
binar-0.1.6-cp315-abi3.abi3t-macosx_10_12_x86_64.whl CPython 3.15 abi3t, abi3 macOS 10.12+ x86-64 Details
binar-0.1.6-cp314-cp314t-win_arm64.whl CPython 3.14 CPython 3.14 free-threading Windows ARM64 Details
binar-0.1.6-cp314-cp314t-win_amd64.whl CPython 3.14 CPython 3.14 free-threading Windows x86-64 Details
binar-0.1.6-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.6-cp314-cp314t-manylinux_2_28_aarch64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ ARM64 Details
binar-0.1.6-cp314-cp314t-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 Details
binar-0.1.6-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.6-cp314-cp314-pyemscripten_2026_0_wasm32.whl CPython 3.14 CPython 3.14 PyEmscripten 2026.0+ WebAssembly Details
binar-0.1.6-cp39-abi3-win_arm64.whl CPython 3.9 abi3 Windows ARM64 Details
binar-0.1.6-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
binar-0.1.6-cp39-abi3-manylinux_2_28_x86_64.whl CPython 3.9 abi3 Linux glibc 2.28+ x86-64 Details
binar-0.1.6-cp39-abi3-manylinux_2_28_aarch64.whl CPython 3.9 abi3 Linux glibc 2.28+ ARM64 Details
binar-0.1.6-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details
binar-0.1.6-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.6-cp315-abi3.abi3t-win_arm64.whl

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

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

Download URL binar-0.1.6-cp315-abi3.abi3t-win_amd64.whl
Size 285.3 kB
Tags CPython 3.15 Windows x86-64 abi3 abi3t
SHA-256 checksum
How to use checksums
432a58cf39c920853f6f05802d2e024f36984d970f7040cf833cb5e39a02f253
BLAKE2b-256 checksum
How to use checksums
698a7d6eb9789057257c4155e70f56b776c24b348164d3a6d985ff118bd326c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

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

Download URL binar-0.1.6-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl
Size 344.0 kB
Tags CPython 3.15 Linux glibc 2.28+ x86-64 abi3 abi3t
SHA-256 checksum
How to use checksums
2964b7950d50bf1fc532aba4ce525f73f086425eb854de5cbe461e6457151ad0
BLAKE2b-256 checksum
How to use checksums
63c1dda76fbf0c985f037574c3ab4bee0c90c5cd71aabc56eae3613458ea35bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

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

Download URL binar-0.1.6-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl
Size 321.2 kB
Tags CPython 3.15 Linux glibc 2.28+ ARM64 abi3 abi3t
SHA-256 checksum
How to use checksums
28c1a2d57810b0cbba0357c6d8f941a5ca6cb2b850c05c141644c0a45e2f3cdf
BLAKE2b-256 checksum
How to use checksums
124ce51ed0b6747640d351f3722ba175c5896e51a2aea8f74fb6bd56a992d6fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

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

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

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

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

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

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

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

Download URL binar-0.1.6-cp314-cp314t-win_amd64.whl
Size 268.8 kB
Tags CPython 3.14 CPython 3.14 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
08984f0477fe701d2310d11515c4811ec1e51ec3c2e9da30146573d6bf9aeede
BLAKE2b-256 checksum
How to use checksums
1d553c8443e3505efa552d348b5ccda4b93f77c9fb4674a5de5afa5f4bfc7b39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

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

Download URL binar-0.1.6-cp314-cp314t-manylinux_2_28_x86_64.whl
Size 329.1 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
8d455db4ebd9ca97ccfdc25e3e5f38b3cf5c3b1171dd2c14c01b5b04a493790d
BLAKE2b-256 checksum
How to use checksums
fce8aae66a863111fdc7306421aa2f572bbc8cd9fccc64f06af133a1c3162d50
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

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

Download URL binar-0.1.6-cp314-cp314t-manylinux_2_28_aarch64.whl
Size 309.4 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
7809fda8ff1faabfa4eab2f3a0899221610bf4c1c8280e2c7bff93de119292a7
BLAKE2b-256 checksum
How to use checksums
ed031f2454c11bc11353ad3f6cbc47eccd39c8bc04533a313789020dce9aec33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

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

Download URL binar-0.1.6-cp314-cp314t-macosx_11_0_arm64.whl
Size 276.3 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
8c38b1240eaf07d7a6f17cda87659e7a69839f9d7a44d92535a7d2dd70291a87
BLAKE2b-256 checksum
How to use checksums
1f739e6e82e4b2c6825c0c5fcbc339ac36e2518adc7e3083adda336edfbab8fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

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

Download URL binar-0.1.6-cp314-cp314t-macosx_10_12_x86_64.whl
Size 290.1 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
d22d3489788034ab1ac68e59ef3b0b55d30b2fde946b424658ad13b3ce1bb296
BLAKE2b-256 checksum
How to use checksums
4b8c901a6933876f46891071a8f687857e6c79d837a2e5dec1fa13490df4e947
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

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

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

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

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

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

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

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

Download URL binar-0.1.6-cp39-abi3-manylinux_2_28_x86_64.whl
Size 333.4 kB
Tags CPython 3.9 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
24fe3cecb4eed7efa2c85e5613ea9ddf9bd3f18e3e159dbbffe73e3048035c2c
BLAKE2b-256 checksum
How to use checksums
c7055cc6e15dd36da00bfdf5fe5289d8b8ea1b66fd828dcbc3f2cf844f277711
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

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

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

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

Download URL binar-0.1.6-cp39-abi3-macosx_11_0_arm64.whl
Size 286.6 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
112d8ead83b1a1e263464e8c631b1b27d3517dd4fdcc4ecedfbf6c3e3a852d80
BLAKE2b-256 checksum
How to use checksums
8bdd153f913b3fe5dd44e227a8d59d6f5befd9df3c9ec54ae7fd603364900d6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

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

Download URL binar-0.1.6-cp39-abi3-macosx_10_12_x86_64.whl
Size 300.3 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
b88b8d0791b430521756b231956a420c9f8e880b4275a6a73cc3375faa6e243c
BLAKE2b-256 checksum
How to use checksums
711cfc237b2f143bc915835f63de31949e736fab4cb465b4fb3a2cb31c3a522b
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.6 This release

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