Bit Vectors With Xes
Project description
Bit Vectors With Xes
BVWX (pronounced bih-vuh-wax, like "bivouacs") is a Python library that implements a family of hardware-oriented, bit vector data types and operators.
Read the docs! (WIP)
Features
Data Types
The fundamental BVWX data type is an ordered collection of "bits".
Unlike standard Boolean algebra where bit values are restricted to {0, 1},
BVWX extends this to include hardware-oriented values W (don't care),
and X (exception).
This lifted, four-state logic consists of:
0- False1- TrueW- Weak Unknown: either True or False, propagates optimisticallyX- Strong Unknown: neither True nor False, propagates pessimistically
W may also be denoted by - in string literals.
The - character is a convention from the Espresso PLA file format.
Wherever it hampers readability, we will instead use W.
Collections of bits can be organized into arbitrary shapes using the
multi-dimensional Array and one-dimensional Vec class factories.
Enum, Struct, and Union class factories can be extended to create
user-defined abstract date types.
Operators
BVWX implements several operators necessary for implementing Boolean algorithms. This includes standard NOT, OR, AND, XOR, ITE (if-then-else), and MUX functions, but also efficient implementations of arithmetic, comparison, shift, rotate, extend, concatenate, pack, encode/decode, and bit count.
See Operators section of the reference documentation for a full list.
Example
>>> from bvwx import *
>>> x0 = bits(["4b----", "4b1111", "4b0000", "4bXXXX"])
>>> x1 = bits(["4b-10X", "4b-10X", "4b-10X", "4b-10X"])
>>> # Bitwise Operators
>>> ~x0
bits(["4b----", "4b0000", "4b1111", "4bXXXX"])
>>> ~x1
bits(["4b-01X", "4b-01X", "4b-01X", "4b-01X"])
>>> x0 | x1
bits(["4b-1-X", "4b111X", "4b-10X", "4bXXXX"])
>>> x0 & x1
bits(["4b--0X", "4b-10X", "4b000X", "4bXXXX"])
>>> x0 ^ x1
bits(["4b---X", "4b-01X", "4b-10X", "4bXXXX"])
>>> # Enums
>>> class Color(Enum):
... RED = "2b00"
... GREEN = "2b01"
... BLUE = "2b10"
...
>>> Color.GREEN & Color.BLUE
Color.RED
>>> # Structs
>>> class Pixel(Struct):
... r: Vec[8]
... g: Vec[8]
... b: Vec[8]
...
>>> maize = Pixel(r="8hFF", g="8hCB", b="8h05")
>>> blue = Pixel(r="8h00", g="8h27", b="8h4C")
>>> maize & blue
Pixel(
r=bits("8b0000_0000"),
g=bits("8b0000_0011"),
b=bits("8b0000_0100"),
)
>>> # And much more ...
Installing
BVWX is available on PyPI:
$ pip install bvwx
It requires Python 3.12+
Developing
BVWX's repository is on GitHub:
$ git clone https://github.com/cjdrake/bvwx.git
It is 100% Python, and has no runtime dependencies.
Development dependencies are listed in requirements-dev.txt.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bvwx-0.20.0.tar.gz.
File metadata
- Download URL: bvwx-0.20.0.tar.gz
- Upload date:
- Size: 37.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0892891ef3b4081be8faf1a0f44d2296021ce822a8a9bc04992270829194e46
|
|
| MD5 |
824ed6dd0e1aed51d0f63612434545cd
|
|
| BLAKE2b-256 |
186f40d09249b9f366a61c9d759266c00f088d24605a372f1119bef172ec5730
|
File details
Details for the file bvwx-0.20.0-py3-none-any.whl.
File metadata
- Download URL: bvwx-0.20.0-py3-none-any.whl
- Upload date:
- Size: 30.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99ba41110242984acdfca3b397d68e07126dabf5712c74802af758dbc0e01b0f
|
|
| MD5 |
342317472f141495b3a4bcc195cebef8
|
|
| BLAKE2b-256 |
fe98263ff328da4dccadb6bfec8af8aa6f2b106111bb52b2056f4314baf38286
|