-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSet Expression Simplifier.py
More file actions
76 lines (59 loc) · 2.44 KB
/
Set Expression Simplifier.py
File metadata and controls
76 lines (59 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import tkinter as tk
from tkinter import messagebox
class SetExpressionSimplifier:
def __init__(self, root):
self.root = root
self.root.title("Set Expression Simplifier")
self.root.geometry("650x500")
tk.Label(root, text="Set Expression Simplifier",
font=("Arial", 18, "bold")).pack(pady=10)
# Universal Set
tk.Label(root, text="Universal Set (comma separated):").pack()
self.universal_entry = tk.Entry(root, width=50)
self.universal_entry.pack()
# Set A
tk.Label(root, text="Set A (comma separated):").pack()
self.setA_entry = tk.Entry(root, width=50)
self.setA_entry.pack()
# Set B
tk.Label(root, text="Set B (comma separated):").pack()
self.setB_entry = tk.Entry(root, width=50)
self.setB_entry.pack()
# Set C
tk.Label(root, text="Set C (comma separated):").pack()
self.setC_entry = tk.Entry(root, width=50)
self.setC_entry.pack()
# Expression Input
tk.Label(root, text="Enter Set Expression:").pack(pady=5)
self.expression_entry = tk.Entry(root, width=50)
self.expression_entry.pack()
tk.Button(root, text="Simplify Expression",
command=self.simplify_expression).pack(pady=10)
self.result_label = tk.Label(root, text="", font=("Arial", 12))
self.result_label.pack(pady=20)
def parse_set(self, entry):
values = entry.get().strip()
if values == "":
return set()
return set(values.split(","))
def simplify_expression(self):
try:
U = self.parse_set(self.universal_entry)
A = self.parse_set(self.setA_entry)
B = self.parse_set(self.setB_entry)
C = self.parse_set(self.setC_entry)
expr = self.expression_entry.get()
# Handle complement using '
expr = expr.replace("A'", "U - A")
expr = expr.replace("B'", "U - B")
expr = expr.replace("C'", "U - C")
result = eval(expr)
self.result_label.config(
text=f"Simplified Result:\n{result}"
)
except Exception as e:
messagebox.showerror("Error", f"Invalid Expression\n{e}")
if __name__ == "__main__":
root = tk.Tk()
app = SetExpressionSimplifier(root)
root.mainloop()