pyeda.boolalg.expr
— Expressions¶
The pyeda.boolalg.expr
module implements
Boolean functions represented as expressions.
Data Types:
- abstract syntax tree
A nested tuple of entries that represents an expression. It is defined recursively:
ast := ('const', bool) | ('lit', uniqid) | (nary, ast, ...) | ('not', ast) | ('impl', ast, ast) | ('ite', ast, ast, ast) bool := 0 | 1 uniqid := nonzero int nary := 'or' | 'and' | 'xor' | 'eq'
Interface Functions:
exprvar()
— Return a unique Expression variableexpr()
— Convert an arbitrary object into an Expressionast2expr()
— Convert an abstract syntax tree to an Expressionexpr2dimacscnf()
— Convert an expression into an equivalent DIMACS CNFupoint2exprpoint()
— Convert an untyped point into an Expression pointNot()
— Expression negation operatorOr()
— Expression disjunction (sum, OR) operatorAnd()
— Expression conjunction (product, AND) operatorXor()
— Expression exclusive or (XOR) operatorEqual()
— Expression equality operatorImplies()
— Expression implication operatorITE()
— Expression If-Then-Else (ITE) operatorNor()
— Expression NOR (not OR) operatorNand()
— Expression NAND (not AND) operatorXnor()
— Expression XNOR (not XOR) operatorUnequal()
— Expression inequality (not EQUAL) operatorOneHot0()
OneHot()
NHot()
Majority()
AchillesHeel()
Mux()
Interface Classes:
Interface Functions¶
-
pyeda.boolalg.expr.
exprvar
(name, index=None)[source]¶ Return a unique Expression variable.
A Boolean variable is an abstract numerical quantity that may assume any value in the set \(B = \{0, 1\}\). The
exprvar
function returns a unique Boolean variable instance represented by a logic expression. Variable instances may be used to symbolically construct larger expressions.A variable is defined by one or more names, and zero or more indices. Multiple names establish hierarchical namespaces, and multiple indices group several related variables. If the
name
parameter is a singlestr
, it will be converted to(name, )
. Theindex
parameter is optional; when empty, it will be converted to an empty tuple()
. If theindex
parameter is a singleint
, it will be converted to(index, )
.Given identical names and indices, the
exprvar
function will always return the same variable:>>> exprvar('a', 0) is exprvar('a', 0) True
To create several single-letter variables:
>>> a, b, c, d = map(exprvar, 'abcd')
To create variables with multiple names (inner-most first):
>>> fifo_push = exprvar(('push', 'fifo')) >>> fifo_pop = exprvar(('pop', 'fifo'))
See also
For creating arrays of variables with incremental indices, use the
pyeda.boolalg.bfarray.exprvars()
function.
-
pyeda.boolalg.expr.
expr
(obj, simplify=True)[source]¶ Convert an arbitrary object into an Expression.
-
pyeda.boolalg.expr.
upoint2exprpoint
(upoint)[source]¶ Convert an untyped point into an Expression point.
See also
For definitions of points and untyped points, see the
pyeda.boolalg.boolfunc
module.
Operators¶
Primary Operators¶
-
pyeda.boolalg.expr.
Not
(x, simplify=True)[source]¶ Expression negation operator
If simplify is
True
, return a simplified expression.
Secondary Operators¶
-
pyeda.boolalg.expr.
Xor
(*xs, simplify=True)[source]¶ Expression exclusive or (XOR) operator
If simplify is
True
, return a simplified expression.
-
pyeda.boolalg.expr.
Equal
(*xs, simplify=True)[source]¶ Expression equality operator
If simplify is
True
, return a simplified expression.
High Order Operators¶
-
pyeda.boolalg.expr.
Nor
(*xs, simplify=True)[source]¶ Expression NOR (not OR) operator
If simplify is
True
, return a simplified expression.
-
pyeda.boolalg.expr.
Nand
(*xs, simplify=True)[source]¶ Expression NAND (not AND) operator
If simplify is
True
, return a simplified expression.
-
pyeda.boolalg.expr.
Xnor
(*xs, simplify=True)[source]¶ Expression exclusive nor (XNOR) operator
If simplify is
True
, return a simplified expression.
-
pyeda.boolalg.expr.
Unequal
(*xs, simplify=True)[source]¶ Expression inequality operator
If simplify is
True
, return a simplified expression.
-
pyeda.boolalg.expr.
OneHot0
(*xs, simplify=True, conj=True)[source]¶ Return an expression that means “at most one input function is true”.
If simplify is
True
, return a simplified expression.If conj is
True
, return a CNF. Otherwise, return a DNF.
-
pyeda.boolalg.expr.
OneHot
(*xs, simplify=True, conj=True)[source]¶ Return an expression that means “exactly one input function is true”.
If simplify is
True
, return a simplified expression.If conj is
True
, return a CNF. Otherwise, return a DNF.
-
pyeda.boolalg.expr.
Majority
(*xs, simplify=True, conj=False)[source]¶ Return an expression that means “the majority of input functions are true”.
If simplify is
True
, return a simplified expression.If conj is
True
, return a CNF. Otherwise, return a DNF.
Interface Classes¶
Expression Tree Nodes¶
-
class
pyeda.boolalg.expr.
Expression
(node)[source]¶ Boolean function represented by a logical expression
See also
This is a subclass of
pyeda.boolalg.boolfunc.Function
The
Expression
class is useful for type checking, e.g.isinstance(f, Expression)
.Do NOT create an Expression using the
Expression
constructor.-
depth
¶ Return the depth of the expression.
Expression depth is defined recursively:
- An atom node (constant or literal) has zero depth.
- A branch node (operator) has depth equal to the maximum depth of its children (arguments) plus one.
-
simple
¶ Return True if the expression has been simplified.
-
expand
(vs=None, conj=False)[source]¶ Return the Shannon expansion with respect to a list of variables.
-
cover
¶ Return the DNF expression as a cover of cubes.
-