Skip to main content

Python library for converting binary decision diagrams to automata.

Project description

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 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:

  1. time: A number between #vars and 0. This number indicates the number of decisions left to be made.
  2. node: A reference to the internal BDD node given by dd.
  3. 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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bdd2dfa-0.3.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

bdd2dfa-0.3.2-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file bdd2dfa-0.3.2.tar.gz.

File metadata

  • Download URL: bdd2dfa-0.3.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.1 Linux/5.5.0-1-MANJARO

File hashes

Hashes for bdd2dfa-0.3.2.tar.gz
Algorithm Hash digest
SHA256 dd8d873560a3148d2fe6299c818c85e2140d39a46e0ac261625608734dd0ff55
MD5 c679d6995aac62297af24ce898e389d5
BLAKE2b-256 eb59ef37675b12e645e1f4c410228f88bf5b44b102a3aa9997f9e7775685d604

See more details on using hashes here.

File details

Details for the file bdd2dfa-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: bdd2dfa-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.1 Linux/5.5.0-1-MANJARO

File hashes

Hashes for bdd2dfa-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 152835e4e4b317a625b1ad42cb148eb5b821ece21b9a92600002f6a49496d11a
MD5 bd8cab7e9a190be074b217c4dc823049
BLAKE2b-256 664b840436e96b3769827abc3a4172f18d007ab72c844cf369e06077e9dcaeb9

See more details on using hashes here.

Supported by

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