Python library for converting binary decision diagrams to automata.
Project description
bdd2dfa
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 the label of non-leaf states in the original BDD is None
and
all leaves self loop.
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.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
assert qdd.label([1, 1, 1, 1]) # QDD rejects.
assert qdd dfa.label([0, 1, 1, 1]) # QDD accepts.
assert qdd.label([1, 1]) is None # Non-leaf node.
Each state of the resulting DFA
object has three attribute:
time
: A number between #vars and 0. This number indicates the number of decisions left to be made.node
: A reference to the internal BDD node given bydd
.parity
:dd
supports Edge NegatedBDD
s, where some edges point to a Boolean function that is the negation of the Boolean function the node would point to in a standardBDD
. Parity value determines whether or not the node
For example,
assert qdd.start.parity is True
assert qdd.start.time == 3
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
time attribute.
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 import write_dot
write_dot(qdd, "qdd.dot")
write_dot(bdd, "bdd.dot")
Compiling using the dot
command yields the following for qdd.dot
and the following for bdd.dot
:
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
File details
Details for the file bdd2dfa-0.2.1.tar.gz
.
File metadata
- Download URL: bdd2dfa-0.2.1.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.3 CPython/3.8.1 Linux/5.5.0-1-MANJARO
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98bfc20fb594473c57421c0e50c0960093a32af6c59d1e1cb91d6b8b49427e47 |
|
MD5 | dbe12ab24a871a4e72b52f5e721bcb2a |
|
BLAKE2b-256 | f9bc6d07de2759b7a01c117b56f021920241b262b37ffce07e859e0e36f1cddd |
File details
Details for the file bdd2dfa-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: bdd2dfa-0.2.1-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.3 CPython/3.8.1 Linux/5.5.0-1-MANJARO
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2acacb02c55f6c53f56260e149e70acdf9b755dd1a7768acacba008c72d8dc26 |
|
MD5 | d708ed4cc2c718d5791e1f99b35fa1b2 |
|
BLAKE2b-256 | 8be290b6d93698d4cb8e2a58298ab1ce72de185651edadd9b8e014e0239bfa15 |