Understanding How Python Calculates Sets

Asked 2 years ago, Updated 2 years ago, 19 views

Currently, Python is trying to implement the following set of calculations:
If you have any implementation methods or websites that you can refer to, please let me know.

("B" or "D") and("A" or "B" or "C" or "D") and("A" or "B" or "C")

= ("B" or "D") and ("A" or "B" or "C")

= "A" and "D" or "B" or "C" and "D"

I look forward to your kind cooperation.

python

2022-09-30 19:29

1 Answers

Why don't you use sympy?

>>import sympathy
>>> from sympathy.logic.boolalg import to_cnf, to_dnf
>>> A, B, C, D = sympy.symbols ('A, B, C, D')
>>>expr=(B|D)&(A|B|C|D)&(A|B|C)
>>> to_cnf(expr,simplify=True)
And (Or(A,B,C), Or(B,D))
>>> to_dnf(expr,simplify=True)
Or(And(A,D), And(C,D),B)

http://docs.sympy.org/latest/modules/logic.html

for more information.


2022-09-30 19:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.