0

Simplified example of what I need:

a = banana or apple
b = banana or apple

a is not equal to b
a = apple

b = ?

So we all know b = banana. But can I give those rules to Sympy and let it calculate for me? I have no idea how and thereby no work in progress to present here- been surfing trough docs for now with no luck.

Edit:

Suggestions for other libraries are welcome

trshmanx
  • 600
  • 7
  • 16
  • This is more suited for [z3py](https://ericpony.github.io/z3py-tutorial/guide-examples.htm) – JohanC Aug 12 '20 at 19:17
  • @JohanC can you please post an answer solving this using z3py? – trshmanx Aug 12 '20 at 19:36
  • [Solving Symbolic Boolean variables in Python](https://stackoverflow.com/questions/19699210/solving-symbolic-boolean-variables-in-python) seems to indicate that this kind of operations isn't very straightforward in sympy. – JohanC Aug 12 '20 at 21:55

1 Answers1

0
from z3 import *

p = Int('p')
q = Int('q')

solve(Or(p==1,p==2), Or(q==1,q==2), Not(p==q), p==1)

Assuming a,b = p,q and 1 = banana, 2 = apple (or around). Works! Still want to use sympy, but can't calc this.

Edit:

For sympy can look into Solving Symbolic Boolean variables in Python.

trshmanx
  • 600
  • 7
  • 16