Skip to main content

High-performance binary arithmetic.

Project description

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.

Project details


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.1-cp39-abi3-win_arm64.whl (216.1 kB view details)

Uploaded CPython 3.9+Windows ARM64

binar-0.1.1-cp39-abi3-win_amd64.whl (227.3 kB view details)

Uploaded CPython 3.9+Windows x86-64

binar-0.1.1-cp39-abi3-manylinux_2_34_x86_64.whl (320.2 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.34+ x86-64

binar-0.1.1-cp39-abi3-manylinux_2_34_aarch64.whl (300.6 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.34+ ARM64

binar-0.1.1-cp39-abi3-macosx_11_0_arm64.whl (282.5 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

binar-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl (295.1 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

binar-0.1.1-cp38-abi3-win_amd64.whl (256.5 kB view details)

Uploaded CPython 3.8+Windows x86-64

binar-0.1.1-cp38-abi3-manylinux_2_34_x86_64.whl (309.4 kB view details)

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

binar-0.1.1-cp38-abi3-manylinux_2_34_aarch64.whl (294.3 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.34+ ARM64

binar-0.1.1-cp38-abi3-macosx_11_0_arm64.whl (275.6 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

binar-0.1.1-cp38-abi3-macosx_10_12_x86_64.whl (287.1 kB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file binar-0.1.1-cp39-abi3-win_arm64.whl.

File metadata

  • Download URL: binar-0.1.1-cp39-abi3-win_arm64.whl
  • Upload date:
  • Size: 216.1 kB
  • Tags: CPython 3.9+, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: RestSharp/106.13.0.0

File hashes

Hashes for binar-0.1.1-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 c6485109b8fe2074ab3458adc9fc9db772d52a723a3f7d6face33084fad4c469
MD5 451bdce4fbc86032f2935b5da59682b8
BLAKE2b-256 b7b8dc06e8f9a9070da43bffcadee8aa22f1638cb5d0084253acbc51322a197f

See more details on using hashes here.

File details

Details for the file binar-0.1.1-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: binar-0.1.1-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 227.3 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: RestSharp/106.13.0.0

File hashes

Hashes for binar-0.1.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 0ea927de2142c5da241528d6d2b47027d4e7a5bafa6d1d77303109de861e24d7
MD5 81d95740a1e9bf6b11b612dc0035a259
BLAKE2b-256 dd4182a11b5a3561af2215b9ae816146372cd5afa957e729b31233d2c5e3ff1e

See more details on using hashes here.

File details

Details for the file binar-0.1.1-cp39-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for binar-0.1.1-cp39-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 88a299a0ecfea80439c47f4dc95731b276db2264388f72cbfcda2b290c6a0e78
MD5 5dd2523ac8b255b21682ff051e3cd705
BLAKE2b-256 bfcc21cbbeb0fb20197eac6c408dc66bc264447ea6c122223a965282e795c67b

See more details on using hashes here.

File details

Details for the file binar-0.1.1-cp39-abi3-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for binar-0.1.1-cp39-abi3-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 46c0225f4a9b3255c2d0c562ecbc0d4ed837c97206ac74730009ffd01f059682
MD5 81925e0c97235d32f4384a74e784b76e
BLAKE2b-256 1c76d94d622115bc6c7f04ee950b3f4bcb5f66c27d6c2b812c29558369900985

See more details on using hashes here.

File details

Details for the file binar-0.1.1-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for binar-0.1.1-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2eff7a68a90f7941167717b74f751e7f1327391367557c10bce48fedd9d3eead
MD5 19f0246edcf67f89e9fb03954c53d7c0
BLAKE2b-256 2e67edf9efa8ea8ec4a9231ad250aa71458e4563ba1a69000d2509cab75fc942

See more details on using hashes here.

File details

Details for the file binar-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for binar-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7b751526dfd0390646e82279c0cff8b68e795585171f465d765da16c83f05a0c
MD5 45903fe48c314d6323795d4e2147eff2
BLAKE2b-256 fd6be0a364ac4da9ddb6d6cd8ff57c22ed96338b7fd79920c14a8334275680f3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: binar-0.1.1-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 256.5 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.1-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 19aa02ca0e54c47d1a70892cd7bc5126b2c00f22972d0ace380851ba9b63ecc4
MD5 c47731f89ad90d556386c0fa5eb195e1
BLAKE2b-256 1295f63f0237bd4e7caec095d0d95b38d94bf7a40b84702aa364a20a2ef63222

See more details on using hashes here.

File details

Details for the file binar-0.1.1-cp38-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for binar-0.1.1-cp38-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 61fe642c01bd405091ca5c797b453b869052679b2d41ed388b9ea1474a5f4851
MD5 e76ed23c71a3e875d87a65701ed5ffe2
BLAKE2b-256 fd9b2e3c353cff280375fe3254dd8a03f29e1aefface153d5ea8e9cfd8d84a2c

See more details on using hashes here.

File details

Details for the file binar-0.1.1-cp38-abi3-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for binar-0.1.1-cp38-abi3-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 a2c762a37ea6067fc12d3fda8fffd895fcd6efe9cc5d238d82d534b214b2d65f
MD5 ec9d3318e1af40903258bc114dd3cbe5
BLAKE2b-256 f2daa4147d69fb0e2acfece12c5e1c3ad6fa135fa7ff68660a4d8d5ec57e1c0f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for binar-0.1.1-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4b18d5f893d7ee5b883966c47abb85afa0c63c1a1b8c0120bf3136ad27d1fc2d
MD5 d0a24b048ff2f73350bfa822129fa102
BLAKE2b-256 b31cd2e752f89cecae0e6bcd321fced6b4044f2adc4c7673512085f821c6ea66

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for binar-0.1.1-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 280b3b8ef720b06e4ad516730060af27e3785d84a4919e106308a05098f423c4
MD5 634a4ff0fd45c5a3e6654cb6e73bd293
BLAKE2b-256 d73a7d60349f7233accc9a0885bae97b97a08c6d2b3c52358b73d8b7659d079c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page