I'm a beginner in Python. I'm tring to convert a text string into its DNF form using PyEDA. My code works fine for this string.
X[0]&(X[1]|X[2]) --> Or(And(X[0],X[1]), And(X[0],X[2]))
But when i try with the string mentioned below, it does not work as intended. Could anyone help me figure out what is going wrong?
Thanks!
input string:
X[0]&(X[1]|X[2])&X[3]|X[0]&X[3]
intended output:
or(and(X[0],X[1],X[3]),and(X[0],X[2],X[3]), and(X[0],X[3])
Code:
import pyeda
from pyeda.inter import *
s = 'X[0]&(X[1]|X[2])&X[3]|X[0]&X[3]'
X=exprvars('x',4)
bs = expr(s)
expression = bs.to_dnf()
expression
Current output:
And(X[0], X[3])
The documentation of the
to_dnffunction explicitly states that it will:In your expected output, you state you want:
However, if you examine this expression, you can see that the last operand of the top conjunction is actually always "truer" than the first two. In other words, if the last operand is true, then the first two also are. This means that the entire
orcan be reduces to the third operand.Since
to_dnfis only obliged to return an equivalet expression, you cannot fault it for doing this kind of reduction, and the result is correct.