Update app.py
Browse files
app.py
CHANGED
|
@@ -31,11 +31,15 @@ def draw_graph(G, pos=None, title="Graph Visualization"):
|
|
| 31 |
nx.draw(G, pos=pos, with_labels=True, node_color='lightblue', node_size=500, font_size=10, font_weight='bold')
|
| 32 |
st.pyplot(plt)
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
# Function to convert the circuit to an equivalent formula.
|
| 41 |
def circuit_to_formula(circuit):
|
|
@@ -154,7 +158,7 @@ def algorithms_circuits():
|
|
| 154 |
st.write("### Create Your Own Circuit")
|
| 155 |
|
| 156 |
# Text input for the Boolean expression
|
| 157 |
-
boolean_expression = st.text_input("Enter a Boolean expression (e.g., ((x
|
| 158 |
|
| 159 |
# Generate button
|
| 160 |
if st.button("Generate Circuit"):
|
|
@@ -163,9 +167,12 @@ def algorithms_circuits():
|
|
| 163 |
# Define symbols
|
| 164 |
x, y, z = symbols('x y z')
|
| 165 |
|
|
|
|
|
|
|
|
|
|
| 166 |
# Use eval to parse the input expression and replace symbols
|
| 167 |
expr = eval(boolean_expression, {}, {
|
| 168 |
-
"
|
| 169 |
|
| 170 |
# Convert the formula to a circuit
|
| 171 |
circuit = formula_to_circuit(expr)
|
|
|
|
| 31 |
nx.draw(G, pos=pos, with_labels=True, node_color='lightblue', node_size=500, font_size=10, font_weight='bold')
|
| 32 |
st.pyplot(plt)
|
| 33 |
|
| 34 |
+
# Define custom operators for logical OR, AND, and NOT
|
| 35 |
+
def custom_or(a, b):
|
| 36 |
+
return Or(a, b)
|
| 37 |
+
|
| 38 |
+
def custom_and(a, b):
|
| 39 |
+
return And(a, b)
|
| 40 |
+
|
| 41 |
+
def custom_not(a):
|
| 42 |
+
return Not(a)
|
| 43 |
|
| 44 |
# Function to convert the circuit to an equivalent formula.
|
| 45 |
def circuit_to_formula(circuit):
|
|
|
|
| 158 |
st.write("### Create Your Own Circuit")
|
| 159 |
|
| 160 |
# Text input for the Boolean expression
|
| 161 |
+
boolean_expression = st.text_input("Enter a Boolean expression (e.g., ((x or y) and (y or not(z)))):")
|
| 162 |
|
| 163 |
# Generate button
|
| 164 |
if st.button("Generate Circuit"):
|
|
|
|
| 167 |
# Define symbols
|
| 168 |
x, y, z = symbols('x y z')
|
| 169 |
|
| 170 |
+
# Replace the custom characters with logical operators
|
| 171 |
+
boolean_expression = boolean_expression.replace("∨", " or ").replace("∧", " and ").replace("¬", " not ")
|
| 172 |
+
|
| 173 |
# Use eval to parse the input expression and replace symbols
|
| 174 |
expr = eval(boolean_expression, {}, {
|
| 175 |
+
"or": custom_or, "and": custom_and, "not": custom_not, "x": x, "y": y, "z": z})
|
| 176 |
|
| 177 |
# Convert the formula to a circuit
|
| 178 |
circuit = formula_to_circuit(expr)
|