0

I've been using SymPy to do logic simplification (using their sympy logic module and it's working well with boolean expressions.

I'm now trying to tackle a trickier problem, but I'm having troubles framing the problem in a way that is solvable from SymPy:

Let's say I have a logical expression made of equivalences:

x == 1 or x == 3

In the general case, that's already the simplest form for this expression. In my specific case though, I have access to the domains of the variables, such as:

x = [1, 3]

So in this case, knowing that x can only have 1 or 3 as possible values, we could conclude that the expression:

x == 1 or x == 3

is always true, and thus can be simplified.

On the other hand, if x could have 1,2,3 as values, then the above expression couldn't be simplified further.

I'm trying to generalise the above problem to handle multiple variables, do you have any idea of how I could frame this problem?

Even some pointers to existing algorithms or similar problems would be extremely helpful

Things I've tried

I've already looked at the Quine–McCluskey algorithm, but I'm having troubles framing the problem in a way that takes value domains in consideration.

For example, given our previous expression:

x == 1 or x == 3

We could decide that:

A = x == 1
B = x == 3

so that the above expression is equivalent to the binary:

A or B

But how could I take into account the possible values of X? (1,2,3)

Thanks!

1 Answers1

1

You could try, for a univariate expression, something like this:

>>> from sympy import Interval, FiniteSet, Or, Eq, S
>>> from sympy.abc import x
>>> Interval(1,3)-Or(Eq(x,1),Eq(x,3)).as_set()
(1, 3)
>>> FiniteSet(1,3)-Or(Eq(x,1),Eq(x,3)).as_set() is S.EmptySet
True
smichr
  • 16,948
  • 2
  • 27
  • 34