-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSet Theory Theorem Visual Proof Generator.py
More file actions
98 lines (77 loc) · 2.99 KB
/
Set Theory Theorem Visual Proof Generator.py
File metadata and controls
98 lines (77 loc) · 2.99 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import tkinter as tk
from tkinter import messagebox
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import matplotlib.pyplot as plt
from matplotlib_venn import venn2
def parse_set(input_text):
try:
return set(map(int, input_text.split(',')))
except:
messagebox.showerror("Input Error", "Enter numbers separated by commas (e.g., 1,2,3)")
return None
def show_union():
A = parse_set(entry_A.get())
B = parse_set(entry_B.get())
if A is None or B is None:
return
result = A.union(B)
result_label.config(text=f"A ∪ B = {result}")
draw_venn(A, B, "Union (A ∪ B)")
def show_intersection():
A = parse_set(entry_A.get())
B = parse_set(entry_B.get())
if A is None or B is None:
return
result = A.intersection(B)
result_label.config(text=f"A ∩ B = {result}")
draw_venn(A, B, "Intersection (A ∩ B)")
def show_difference():
A = parse_set(entry_A.get())
B = parse_set(entry_B.get())
if A is None or B is None:
return
result = A.difference(B)
result_label.config(text=f"A − B = {result}")
draw_venn(A, B, "Difference (A − B)")
def show_demorgan():
A = parse_set(entry_A.get())
B = parse_set(entry_B.get())
if A is None or B is None:
return
universal = set(range(1, 21))
left = universal - (A.union(B))
right = (universal - A).intersection(universal - B)
result_label.config(text=f"De Morgan Verified: {left == right}")
draw_venn(A, B, "De Morgan's Law")
def draw_venn(A, B, title):
for widget in frame_graph.winfo_children():
widget.destroy()
fig = plt.Figure(figsize=(4,4))
ax = fig.add_subplot(111)
venn2([A, B], set_labels=('A', 'B'), ax=ax)
ax.set_title(title)
canvas = FigureCanvasTkAgg(fig, master=frame_graph)
canvas.draw()
canvas.get_tk_widget().pack()
# GUI Setup
root = tk.Tk()
root.title("Set Theory Theorem Visual Proof Generator")
root.geometry("600x650")
root.resizable(False, False)
tk.Label(root, text="Set Theory Theorem Visual Proof Generator",
font=("Arial", 14, "bold")).pack(pady=10)
tk.Label(root, text="Enter Set A (e.g., 1,2,3)").pack()
entry_A = tk.Entry(root, width=40)
entry_A.pack(pady=5)
tk.Label(root, text="Enter Set B (e.g., 2,3,4)").pack()
entry_B = tk.Entry(root, width=40)
entry_B.pack(pady=5)
tk.Button(root, text="Union (A ∪ B)", command=show_union, bg="blue", fg="white").pack(pady=5)
tk.Button(root, text="Intersection (A ∩ B)", command=show_intersection, bg="green", fg="white").pack(pady=5)
tk.Button(root, text="Difference (A − B)", command=show_difference, bg="orange", fg="white").pack(pady=5)
tk.Button(root, text="Verify De Morgan's Law", command=show_demorgan, bg="purple", fg="white").pack(pady=5)
result_label = tk.Label(root, text="", font=("Arial", 12, "bold"))
result_label.pack(pady=10)
frame_graph = tk.Frame(root)
frame_graph.pack(pady=10)
root.mainloop()