Skip to main content

bdd2dfa

Build Status codecov PyPI version License: MIT

A simple python wrapper around Binary Decision Diagrams (BDDs) to interpret them as Deterministic Finite Automata (DFAs).

The package takes as input a BDD from the dd package and returns a DFA from the dfa package.

Formally, the resulting DFA objects are quasi-reduced BDDs (QDDs) where all leaves self loop and the label of states is a tuple: (int, str | bool), where the first entry determines the number of inputs until this node is active and the second entry is the decision variable of the node or the BDD's truth assignment.

Table of Contents

Installation

If you just need to use bdd2dfa, you can just run:

$ pip install bdd2dfa

For developers, note that this project uses the poetry python package/dependency management tool. Please familarize yourself with it and then run:

$ poetry install

Usage

# Create BDD

from dd import BDD

manager = BDD()
manager.declare('x', 'y', 'z')
x, y, z = map(manager.var, 'xyz')
bexpr = x & y & z


# Convert to DFA

from bdd2dfa import to_dfa

qdd = to_dfa(bexpr)

assert len(qdd.states()) == 7

# End at leaf node.
assert qdd.label([1, 1, 1]) == (0, True)
assert qdd.label([0, 1, 1]) == (0, False)

# End at Non-leaf node.
assert qdd.label([1, 1]) == (0, 'z')
assert qdd.label([0, 1]) == (1, False)

# leaf nodes are self loops.
assert qdd.label([1, 1, 1, 1]) == (0, True)
assert qdd.label([1, 1, 1, 1, 1]) == (0, True)

Each state of the resulting DFA object has three attribute:

  1. node: A reference to the internal BDD node given by dd.
  2. parity: dd supports Edge Negated BDDs, where some edges point to a Boolean function that is the negation of the Boolean function the node would point to in a standard BDD. Parity value determines whether or not the node
  3. debt: Number of inputs needed before this node can transition. Required since BDD edges can skip over irrelevant decisions.

For example,

assert qdd.start.parity is True
assert qdd.start.debt == 0
assert qdd.start.node.var == 'x'

BDD vs QDD

to_dfa also supports exporting a BDD rather than a QDD. This is done by toggling the qdd flag.

bdd = to_dfa(bexpr, qdd=False)

The DFA uses a similar state as the QDD case, but does not have a debt attribute. Useful when one just wants to walk the BDD.

note The labeling alphabet also only returns the decision variable/truth assignment.

If the dfa package was installed with the draw option, we can visualize the difference between qdd and bdd by exporting to a graphviz dot file.

from dfa.draw import write_dot

write_dot(qdd, "qdd.dot")
write_dot(bdd, "bdd.dot")

Compiling using the dot command yields the following for qdd.dot

qdd image

and the following for bdd.dot:

bdd image

Metadata

Release files for bdd2dfa 1.0.10

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

Source distribution (sdist)

Source distribution for bdd2dfa 1.0.10
File Size Uploaded Provenance Actions
bdd2dfa-1.0.10.tar.gz 4.8 kB Without provenance Details for bdd2dfa-1.0.10.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bdd2dfa 1.0.10
File Interpreter ABI Platform Actions
bdd2dfa-1.0.10-py3-none-any.whl Python 3 none any Details for bdd2dfa-1.0.10-py3-none-any.whl

Total release size: 9.4 kB

Release files / bdd2dfa-1.0.10.tar.gz

Download URL bdd2dfa-1.0.10.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e1fe522be5c1ab39918e4f41bb45dadbfc17b255768c81014fb3a7c2de54ccd7
BLAKE2b-256 checksum
How to use checksums
56c1e590a59b15ba45246b2d5156f643895ba5a5fae84b0d7765cffee9479aa6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.14 CPython/3.9.13 Linux/6.0.0

Release files / bdd2dfa-1.0.10-py3-none-any.whl

Download URL bdd2dfa-1.0.10-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
04a63ceab7d5c844bdd422b69b49148f307ea78cd3ecd876f68da058a9b47a75
BLAKE2b-256 checksum
How to use checksums
c6c3f5544dc119181724ff07416452ef2b169c83a78670a4cfeeae305f9d94ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.14 CPython/3.9.13 Linux/6.0.0

Security for bdd2dfa 1.0.10

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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