# pyeda.boolalg.bfarray — Boolean Function Arrays¶

The pyeda.boolalg.bfarray module implements multi-dimensional arrays of Boolean functions.

Interface Functions:

Interface Classes:

## Interface Functions¶

pyeda.boolalg.bfarray.bddzeros(*dims)[source]

Return a multi-dimensional farray of BDDZERO.

BDDZERO is the BDD representation of the number zero.

The variadic dims input is a sequence of dimension specs. A dimension spec is a two-tuple: (start index, stop index). If a dimension is given as a single int, it will be converted to (0, stop).

The dimension starts at index start, and increments by one up to, but not including, stop. This follows the Python slice convention.

For example, to create a 4x4 farray of BDD zeros:

>>> zeros = bddzeros(4, 4)
>>> zeros
farray([[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]])

pyeda.boolalg.bfarray.bddones(*dims)[source]

Return a multi-dimensional farray of BDDONE.

BDDONE is the BDD representation of the number one.

The variadic dims input is a sequence of dimension specs. A dimension spec is a two-tuple: (start index, stop index). If a dimension is given as a single int, it will be converted to (0, stop).

The dimension starts at index start, and increments by one up to, but not including, stop. This follows the Python slice convention.

For example, to create a 4x4 farray of BDD ones:

>>> ones = bddones(4, 4)
>>> ones
farray([[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]])

pyeda.boolalg.bfarray.bddvars(name, *dims)[source]

Return a multi-dimensional farray of BDD variables.

The name argument is passed directly to the pyeda.boolalg.bdd.bddvar() function, and may be either a str or tuple of str.

The variadic dims input is a sequence of dimension specs. A dimension spec is a two-tuple: (start index, stop index). If a dimension is given as a single int, it will be converted to (0, stop).

The dimension starts at index start, and increments by one up to, but not including, stop. This follows the Python slice convention.

For example, to create a 4x4 farray of BDD variables:

>>> vs = bddvars('a', 4, 4)
>>> vs
farray([[a[0,0], a[0,1], a[0,2], a[0,3]],
[a[1,0], a[1,1], a[1,2], a[1,3]],
[a[2,0], a[2,1], a[2,2], a[2,3]],
[a[3,0], a[3,1], a[3,2], a[3,3]]])

pyeda.boolalg.bfarray.exprzeros(*dims)[source]

Return a multi-dimensional farray of EXPRZERO.

EXPRZERO is the expression representation of the number zero.

The variadic dims input is a sequence of dimension specs. A dimension spec is a two-tuple: (start index, stop index). If a dimension is given as a single int, it will be converted to (0, stop).

The dimension starts at index start, and increments by one up to, but not including, stop. This follows the Python slice convention.

For example, to create a 4x4 farray of expression zeros:

>>> zeros = exprzeros(4, 4)
>>> zeros
farray([[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]])

pyeda.boolalg.bfarray.exprones(*dims)[source]

Return a multi-dimensional farray of EXPRONE.

EXPRONE is the expression representation of the number one.

The variadic dims input is a sequence of dimension specs. A dimension spec is a two-tuple: (start index, stop index). If a dimension is given as a single int, it will be converted to (0, stop).

The dimension starts at index start, and increments by one up to, but not including, stop. This follows the Python slice convention.

For example, to create a 4x4 farray of expression ones:

>>> ones = exprones(4, 4)
>>> ones
farray([[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]])

pyeda.boolalg.bfarray.exprvars(name, *dims)[source]

Return a multi-dimensional farray of expression variables.

The name argument is passed directly to the pyeda.boolalg.expr.exprvar() function, and may be either a str or tuple of str.

The variadic dims input is a sequence of dimension specs. A dimension spec is a two-tuple: (start index, stop index). If a dimension is given as a single int, it will be converted to (0, stop).

The dimension starts at index start, and increments by one up to, but not including, stop. This follows the Python slice convention.

For example, to create a 4x4 farray of expression variables:

>>> vs = exprvars('a', 4, 4)
>>> vs
farray([[a[0,0], a[0,1], a[0,2], a[0,3]],
[a[1,0], a[1,1], a[1,2], a[1,3]],
[a[2,0], a[2,1], a[2,2], a[2,3]],
[a[3,0], a[3,1], a[3,2], a[3,3]]])

pyeda.boolalg.bfarray.ttzeros(*dims)[source]

Return a multi-dimensional farray of TTZERO.

TTZERO is the truth table representation of the number zero.

The variadic dims input is a sequence of dimension specs. A dimension spec is a two-tuple: (start index, stop index). If a dimension is given as a single int, it will be converted to (0, stop).

The dimension starts at index start, and increments by one up to, but not including, stop. This follows the Python slice convention.

For example, to create a 4x4 farray of truth table zeros:

>>> zeros = ttzeros(4, 4)
>>> zeros
farray([[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]])

pyeda.boolalg.bfarray.ttones(*dims)[source]

Return a multi-dimensional farray of TTONE.

TTONE is the truth table representation of the number one.

The variadic dims input is a sequence of dimension specs. A dimension spec is a two-tuple: (start index, stop index). If a dimension is given as a single int, it will be converted to (0, stop).

The dimension starts at index start, and increments by one up to, but not including, stop. This follows the Python slice convention.

For example, to create a 4x4 farray of truth table ones:

>>> ones = ttones(4, 4)
>>> ones
farray([[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]])

pyeda.boolalg.bfarray.ttvars(name, *dims)[source]

Return a multi-dimensional farray of truth table variables.

The name argument is passed directly to the pyeda.boolalg.table.ttvar() function, and may be either a str or tuple of str.

The variadic dims input is a sequence of dimension specs. A dimension spec is a two-tuple: (start index, stop index). If a dimension is given as a single int, it will be converted to (0, stop).

The dimension starts at index start, and increments by one up to, but not including, stop. This follows the Python slice convention.

For example, to create a 4x4 farray of truth table variables:

>>> vs = ttvars('a', 4, 4)
>>> vs
farray([[a[0,0], a[0,1], a[0,2], a[0,3]],
[a[1,0], a[1,1], a[1,2], a[1,3]],
[a[2,0], a[2,1], a[2,2], a[2,3]],
[a[3,0], a[3,1], a[3,2], a[3,3]]])

pyeda.boolalg.bfarray.uint2bdds(num, length=None)[source]

Convert num to an farray of BDDs.

The num argument is a non-negative integer.

If no length parameter is given, the return value will have the minimal required length. Otherwise, the return value will be zero-extended to match length.

For example, to convert the byte 42 (binary 0b00101010):

>>> uint2bdds(42, 8)
farray([0, 1, 0, 1, 0, 1, 0, 0])

pyeda.boolalg.bfarray.uint2exprs(num, length=None)[source]

Convert num to an farray of expressions.

The num argument is a non-negative integer.

If no length parameter is given, the return value will have the minimal required length. Otherwise, the return value will be zero-extended to match length.

For example, to convert the byte 42 (binary 0b00101010):

>>> uint2exprs(42, 8)
farray([0, 1, 0, 1, 0, 1, 0, 0])

pyeda.boolalg.bfarray.uint2tts(num, length=None)[source]

Convert num to an farray of truth tables.

The num argument is a non-negative integer.

If no length parameter is given, the return value will have the minimal required length. Otherwise, the return value will be zero-extended to match length.

For example, to convert the byte 42 (binary 0b00101010):

>>> uint2tts(42, 8)
farray([0, 1, 0, 1, 0, 1, 0, 0])

pyeda.boolalg.bfarray.int2bdds(num, length=None)[source]

Convert num to an farray of BDDs.

The num argument is an int. Negative numbers will be converted using twos-complement notation.

If no length parameter is given, the return value will have the minimal required length. Otherwise, the return value will be sign-extended to match length.

For example, to convert the bytes 42 (binary 0b00101010), and -42 (binary 0b11010110):

>>> int2bdds(42, 8)
farray([0, 1, 0, 1, 0, 1, 0, 0])
>>> int2bdds(-42, 8)
farray([0, 1, 1, 0, 1, 0, 1, 1])

pyeda.boolalg.bfarray.int2exprs(num, length=None)[source]

Convert num to an farray of expressions.

The num argument is an int. Negative numbers will be converted using twos-complement notation.

If no length parameter is given, the return value will have the minimal required length. Otherwise, the return value will be sign-extended to match length.

For example, to convert the bytes 42 (binary 0b00101010), and -42 (binary 0b11010110):

>>> int2exprs(42, 8)
farray([0, 1, 0, 1, 0, 1, 0, 0])
>>> int2exprs(-42, 8)
farray([0, 1, 1, 0, 1, 0, 1, 1])

pyeda.boolalg.bfarray.int2tts(num, length=None)[source]

Convert num to an farray of truth tables.

The num argument is an int. Negative numbers will be converted using twos-complement notation.

If no length parameter is given, the return value will have the minimal required length. Otherwise, the return value will be sign-extended to match length.

For example, to convert the bytes 42 (binary 0b00101010), and -42 (binary 0b11010110):

>>> int2tts(42, 8)
farray([0, 1, 0, 1, 0, 1, 0, 0])
>>> int2tts(-42, 8)
farray([0, 1, 1, 0, 1, 0, 1, 1])

pyeda.boolalg.bfarray.fcat(*fs)[source]

Concatenate a sequence of farrays.

## Interface Classes¶

class pyeda.boolalg.bfarray.farray(objs, shape=None, ftype=None)[source]

Array of Boolean functions

size[source]

Return the size of the farray.

offsets[source]

Return a tuple of dimension offsets.

ndim[source]

Return the number of dimensions.

reshape(*dims)[source]

Return an equivalent farray with modified dimensions.

flat[source]

Return a 1D iterator over the farray.

restrict(point)[source]

Return the farray that results from applying the restrict method to all functions.

vrestrict(vpoint)[source]

Expand all vectors before applying restrict.

to_uint()[source]

Convert vector to an unsigned integer, if possible.

to_int()[source]

Convert vector to an integer, if possible.

zext(num)[source]

Return a flat copy of this array, zero-extended by N bits.

sext(num)[source]

Return a flat copy of this array, sign-extended by N bits.

__invert__()[source]

Return the bit-wise NOT of the farray.

__or__(other)[source]

Return the bit-wise OR of the farray and other.

__and__(other)[source]

Return the bit-wise AND of the farray and other.

__xor__(other)[source]

Return the bit-wise XOR of the farray and other.

__lshift__(obj)[source]

Return the farray left-shifted by obj.

The obj argument may either be an int, or (int, farray). The int argument is num, and the farray argument is cin.

lsh()

__rshift__(obj)[source]

Return the farray right-shifted by obj.

The obj argument may either be an int, or (int, farray). The int argument is num, and the farray argument is cin.

rsh()

uor()[source]

Return the unary OR of a array of functions.

unor()[source]

Return the unary NOR of a array of functions.

uand()[source]

Return the unary AND of a array of functions.

unand()[source]

Return the unary NAND of a array of functions.

uxor()[source]

Return the unary XOR of a array of functions.

uxnor()[source]

Return the unary XNOR of a array of functions.

lsh(num, cin=None)[source]

Return the farray left-shifted by num places.

The num argument must be a non-negative int.

If the cin farray is provided, it will be shifted in. Otherwise, the carry-in is zero.

Returns a two-tuple (farray fs, farray cout), where fs is the shifted vector, and cout is the “carry out”.

rsh(num, cin=None)[source]

Return the farray right-shifted by num places.

The num argument must be a non-negative int.

If the cin farray is provided, it will be shifted in. Otherwise, the carry-in is zero.

Returns a two-tuple (farray fs, farray cout), where fs is the shifted vector, and cout is the “carry out”.

arsh(num)[source]

Return the farray arithmetically right-shifted by num places.

The num argument must be a non-negative int.

The carry-in will be the value of the most significant bit.

decode()[source]

Return symbolic logic for an $$N \rightarrow 2^N$$ binary decoder.

Example Truth Table for a 2:4 decoder:

$$A_1$$ $$A_0$$ $$D_3$$ $$D_2$$ $$D_1$$ $$D_0$$
0 0 0 0 0 1
0 1 0 0 1 0
1 0 0 1 0 0
1 1 1 0 0 0