0

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])
Tharun
  • 1
  • 1

1 Answers1

0

The documentation of the to_dnf function explicitly states that it will:

Return an equivalent expression in disjunctive normal form.

In your expected output, you state you want:

or(and(X[0],X[1],X[3]), and(X[0],X[2],X[3]), and(X[0],X[3])

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 or can be reduces to the third operand.

Since to_dnf is only obliged to return an equivalet expression, you cannot fault it for doing this kind of reduction, and the result is correct.

Amitai Irron
  • 1,973
  • 1
  • 12
  • 14