boolean_normal_forms

bit_count(i)

Count set bits of the input.

functions2mindnf(functions: Dict[str, callable]) Dict[str, str]

Generates and returns a minimal disjunctive normal form (DNF) for the Boolean network represented by functions. The algorithm uses Prekas2012, a Python implementation of the Quine-McCluskey algorithm.

arguments:
  • functions: keys are component names and values are Boolean functions

returns:
  • min_dnf: keys are component names and values are minimal DNF expressions

example:

>>> funcs = {"v1": lambda v1,v2: v1 or not v2, "v2": lambda: 1}
>>> mindnf = functions2primes(funcs)
>>> mindnf["v1"]
((! v2) | v1)
functions2primes(functions: Dict[str, callable]) dict

Generates and returns the prime implicants of a Boolean network represented by functions.

arguments:
  • functions: keys are component names and values are Boolean functions

returns:
  • primes: primes implicants

example:

>>> funcs = {"v1": lambda v1, v2: v1 or not v2,
...          "v2": lambda v1, v2: v1 + v2 == 1}
>>> primes = functions2primes(funcs)
get_dnf(one_implicants: List[dict]) str

Returns a disjunctive normal form for name by converting each prime implicant into a conjunction.

arguments:
  • one_implicants: the 1-implicants of a component

returns:
  • dnf: the dnf of one_implicants

example:

>>> get_dnf(primes["MEK"][1])
RAF&ERK | TGF
is_power_of_two_or_zero(x)

Determine if an input is zero or a power of two. Alternative, determine if an input has at most 1 bit set.

merge(i, j)

Combine two minterms.

primes2mindnf(primes: dict) Dict[str, str]

Creates a minimal disjunctive normal form (DNF) expression for the Boolean network represented by primes. The algorithm uses Prekas2012, a Python implementation of the Quine-McCluskey algorithm.

arguments:
  • primes: prime implicants

returns:
  • min_dnf: keys are names and values are minimal DNF expressions

example:

>>> primes["v1"][1]
[{'v1':1,'v2':0}]
>>> mindnf = primes2mindnf(primes)
>>> mindnf["v1"]
((! v2) | v1)