pyeda.boolalg.bfarray
— Boolean Function Arrays¶
The pyeda.boolalg.bfarray
module implements multi-dimensional arrays
of Boolean functions.
Interface Functions:
bddzeros()
— Return a multi-dimensional array of BDD zerosbddones()
— Return a multi-dimensional array of BDD onesbddvars()
— Return a multi-dimensional array of BDD variablesexprzeros()
— Return a multi-dimensional array of expression zerosexprones()
— Return a multi-dimensional array of expression onesexprvars()
— Return a multi-dimensional array of expression variablesttzeros()
— Return a multi-dimensional array of truth table zerosttones()
— Return a multi-dimensional array of truth table onesttvars()
— Return a multi-dimensional array of truth table variablesuint2bdds()
— Convert unsigned num to an array of BDDsuint2exprs()
— Convert unsigned num to an array of expressionsuint2tts()
— Convert unsigned num to an array of truth tablesint2bdds()
— Convert num to an array of BDDsint2exprs()
— Convert num to an array of expressionsint2tts()
— Convert num to an array of truth tablesfcat()
— Concatenate a sequence of farrays
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 astr
or tuple ofstr
.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 astr
or tuple ofstr
.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 astr
or tuple ofstr
.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 (binary0b11010110
):>>> 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 (binary0b11010110
):>>> 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 (binary0b11010110
):>>> int2tts(42, 8) farray([0, 1, 0, 1, 0, 1, 0, 0]) >>> int2tts(-42, 8) farray([0, 1, 1, 0, 1, 0, 1, 1])
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 forobjs=[]
(an empty array).-
__lshift__
(obj)[source]¶ Left shift operator
The obj argument may either be an
int
, or(int, farray)
. Theint
argument is num, and thefarray
argument is cin.See also
-
__rshift__
(obj)[source]¶ Right shift operator
The obj argument may either be an
int
, or(int, farray)
. Theint
argument is num, and thefarray
argument is cin.See also
-
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.
-
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.
-
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.
-