pyeda.boolalg.expr — Expressions¶
The pyeda.boolalg.expr module implements Boolean functions represented as expressions.
Interface Functions:
- exprvar()
- expr()
- ast2expr()
- expr2dimacscnf()
- upoint2exprpoint()
- Not()
- Or()
- And()
- Nor()
- Nand()
- Xor()
- Xnor()
- Equal()
- Unequal()
- Implies()
- ITE()
- OneHot0()
- OneHot()
- Majority()
- AchillesHeel()
- Mux()
Interface Classes:
- Expression
- ExprConstant
- ExprLiteral
- ExprVariable
- ExprComplement
- ExprNot
- ExprOrAnd
- ExprOr
- ExprAnd
- ExprNorNand
- ExprNor
- ExprNand
- ExprExclusive
- ExprXor
- ExprXnor
- ExprEqualBase
- ExprEqual
- ExprUnequal
- ExprImplies
- ExprITE
- NormalForm
- DisjNormalForm
- ConjNormalForm
- DimacsCNF
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 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, we recommend using the pyeda.boolalg.bfarray.exprvars() function.
- pyeda.boolalg.expr.expr(obj, simplify=True)[source]¶
Convert an arbitrary object into an Expression.
- pyeda.boolalg.expr.expr2dimacscnf(expr)[source]¶
Convert an expression into an equivalent DIMACS CNF.
- pyeda.boolalg.expr.upoint2exprpoint(upoint)[source]¶
Convert an untyped point to an Expression point.
Logic Factory Functions¶
Secondary Operators¶
- pyeda.boolalg.expr.Xnor(*args, simplify=True)[source]¶
Factory function for Boolean XNOR expression.
- pyeda.boolalg.expr.Equal(*args, simplify=True)[source]¶
Factory function for Boolean EQUAL expression.
- pyeda.boolalg.expr.Unequal(*args, simplify=True)[source]¶
Factory function for Boolean UNEQUAL expression.
High Order Operators¶
- pyeda.boolalg.expr.OneHot0(*args, simplify=True, conj=True)[source]¶
- Return an expression that means:
- At most one input variable is true.
- pyeda.boolalg.expr.OneHot(*args, simplify=True, conj=True)[source]¶
- Return an expression that means:
- Exactly one input variable is true.
- pyeda.boolalg.expr.Majority(*args, simplify=True, conj=False)[source]¶
- Return an expression that means:
- The majority of the input variables are true.
Interface Classes¶
Expression Tree Nodes¶
- class pyeda.boolalg.expr.Expression[source]¶
Boolean function represented by a logic expression
- factor(conj=False)[source]¶
Return a factored expression.
A factored expression is one and only one of the following:
- A literal.
- A disjunction / conjunction of factored expressions.
Parameters
- conj : bool
- Always choose a conjunctive form when there’s a choice
- depth[source]¶
Return the depth of the expression tree.
Expression depth is defined recursively:
- A leaf node (constant or literal) has zero depth.
- A branch node (operator) has depth equal to the maximum depth of its children (arguments) plus one.
- expand(vs=None, conj=False)[source]¶
Return the Shannon expansion with respect to a list of variables.
- flatten(op)[source]¶
Return a factored, flattened expression.
Use the distributive law to flatten all nested expressions:
\[a + (b \cdot c) = (a + b) \cdot (a + c)\]\[a \cdot (b + c) = (a \cdot b) + (a \cdot c)\]- op : ExprOr or ExprAnd
- The operator you want to flatten. For example, if you want to produce an ExprOr expression, flatten all the nested ExprAnds.