# 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 array of BDD zeros.

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 array 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 array of BDD ones.

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 array 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 array 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 array 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 array of expression zeros.

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 array 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 array of expression ones.

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 array 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 array 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 array 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 array of truth table zeros.

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 array 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 array of truth table ones.

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 array 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 array 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 array 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 unsigned num to an array 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 unsigned num to an array 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 unsigned num to an array 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 array 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 array 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 array 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.

The variadic fs input is a homogeneous sequence of functions or arrays.

## Interface Classes¶

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

Multi-dimensional array of Boolean functions

The objs argument is a nested sequence of homogeneous Boolean functions. That is, both [a, b, c, d] and [[a, b], [c, d]] are valid inputs.

The optional shape parameter is a tuple of dimension specs, which are (int, int) tuples. It must match the volume of objs. The shape can always be automatically determined from objs, but you can supply it to automatically reshape a flat input.

The optional ftype parameter is a proper subclass of Function. It must match the homogeneous type of objs. In most cases, ftype can automatically be determined from objs. The one exception is that you must provide ftype for objs=[] (an empty array).

__invert__()[source]

Bit-wise NOT operator

__or__(other)[source]

Bit-wise OR operator

__and__(other)[source]

Bit-wise AND operator

__xor__(other)[source]

Bit-wise XOR operator

__lshift__(obj)[source]

Left shift operator

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

__rshift__(obj)[source]

Right shift operator

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

__add__(other)[source]

Concatenation operator

The other argument may be a Function or farray.

__mul__(num)[source]

Repetition operator

restrict(point)[source]

Apply the restrict method to all functions.

Returns a new farray.

vrestrict(vpoint)[source]

Expand all vectors in vpoint before applying restrict.

compose(mapping)[source]

Apply the compose method to all functions.

Returns a new farray.

size

Return the size of the array.

The size of a multi-dimensional array is the product of the sizes of its dimensions.

offsets

Return a tuple of dimension offsets.

ndim

Return the number of dimensions.

reshape(*dims)[source]

Return an equivalent farray with a modified shape.

flat

Return a 1D iterator over the farray.

to_uint()[source]

Convert vector to an unsigned integer, if possible.

This is only useful for arrays filled with zero/one entries.

to_int()[source]

Convert vector to an integer, if possible.

This is only useful for arrays filled with zero/one entries.

zext(num)[source]

Zero-extend this farray by num bits.

Returns a new farray.

sext(num)[source]

Sign-extend this farray by num bits.

Returns a new farray.

uor()[source]

Unary OR reduction operator

unor()[source]

Unary NOR reduction operator

uand()[source]

Unary AND reduction operator

unand()[source]

Unary NAND reduction operator

uxor()[source]

Unary XOR reduction operator

uxnor()[source]

Unary XNOR reduction operator

lsh(num, cin=None)[source]

Left shift the farray 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”.

Returns a new farray.

rsh(num, cin=None)[source]

Right shift the farray 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”.

Returns a new farray.

arsh(num)[source]

Arithmetically right shift the farray by num places.

The num argument must be a non-negative int.

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

Returns a new farray.

decode()[source]

Return a $$N \rightarrow 2^N$$ 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