Primary Operators¶
- pyeda.boolalg.expr.Not(arg, simplify=True)[source]¶
Expression negation operator
If simplify is True, return a simplified expression.
The pyeda.boolalg.expr module implements Boolean functions represented as expressions.
Data Types:
A nested tuple of entries that represents an expression. It is defined recursively:
ast := ('const', bool)
| ('var', names, indices)
| ('not', ast)
| ('implies', ast, ast)
| ('ite', ast, ast, ast)
| (func, ast, ...)
bool := 0 | 1
names := (name, ...)
indices := (index, ...)
func := 'or'
| 'nor'
| 'and'
| 'nand'
| 'xor'
| 'xnor'
| 'equal'
| 'unequal'
| 'onehot0'
| 'onehot'
| 'majority'
| 'achillesheel'
Interface Functions:
Interface Classes:
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 an 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 single str, it will be converted to (name, ). The index parameter is optional; when empty, it will be converted to an empty tuple (). If the index parameter is a single int, 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.
Convert an arbitrary object into an Expression.
Convert an expression into an equivalent DIMACS CNF.
Convert an untyped point to an Expression point.
Expression negation operator
If simplify is True, return a simplified expression.
Expression NOR (not OR) operator
If simplify is True, return a simplified expression.
Expression NAND (not AND) operator
If simplify is True, return a simplified expression.
Expression exclusive or (XOR) operator
If simplify is True, return a simplified expression.
Expression exclusive nor (XNOR) operator
If simplify is True, return a simplified expression.
Expression equality operator
If simplify is True, return a simplified expression.
Expression inequality operator
If simplify is True, return a simplified expression.
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.
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.
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.
Boolean function represented by a logic expression
See also
This is a subclass of pyeda.boolalg.boolfunc.Function
An expression is a tree data structure with operators at the branches, and constants/literals at the leaves. A literal is a variable or its complement.
There are two ways to construct an expression:
Use the exprvar function to create expression variables, and use the Python ~|&^ operators for NOT, OR, AND, XOR. Additionally, expressions overload >> for IMPLIES.
For example:
>>> a, b, c, d, p, q = map(exprvar, 'abcdpq')
>>> f = ~a | b & c ^ d
>>> g = p >> q
To create unsimplified expressions, use class constructors:
>>> ExprOr(0, a)
Or(0, a)
To create simplified expressions, use function form operators with simplify=True, or Python ~|&^ operators:
>>> Or(0, a)
a
>>> 0 | a
a
Boolean implication operator
\(f\) | \(g\) | \(f \implies g\) |
---|---|---|
0 | 0 | 1 |
0 | 1 | 1 |
1 | 0 | 0 |
1 | 1 | 1 |
Return a factored expression.
A factored expression is one and only one of the following:
Parameters
Return the depth of the expression tree.
Expression depth is defined recursively:
Return the Shannon expansion with respect to a list of variables.
Return a factored, flattened expression.
Use the distributive law to flatten all nested expressions: