Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -27,13 +27,14 @@ class BasicAgent:
|
|
27 |
|
28 |
|
29 |
def check_commutativity(self):
|
|
|
30 |
S = ['a', 'b', 'c', 'd', 'e']
|
31 |
counter_example_elements = set()
|
32 |
|
33 |
# Define a map for converting letters to table indices
|
34 |
index = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4}
|
35 |
|
36 |
-
# Operation table
|
37 |
self.operation_table = [
|
38 |
['a', 'b', 'c', 'b', 'd'], # a * a, a * b, a * c, a * d, a * e
|
39 |
['b', 'c', 'a', 'e', 'c'], # b * a, b * b, b * c, b * d, b * e
|
@@ -42,17 +43,22 @@ class BasicAgent:
|
|
42 |
['d', 'b', 'a', 'd', 'c'] # e * a, e * b, e * c, e * d, e * e
|
43 |
]
|
44 |
|
45 |
-
# Check for commutativity violations
|
46 |
for x in S:
|
47 |
for y in S:
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
counter_example_elements.add(x)
|
50 |
counter_example_elements.add(y)
|
51 |
|
52 |
# Return the sorted list of elements involved in violations
|
53 |
return sorted(counter_example_elements)
|
54 |
|
55 |
-
|
56 |
|
57 |
def maybe_reversed(self, text: str) -> bool:
|
58 |
words = text.split()
|
|
|
27 |
|
28 |
|
29 |
def check_commutativity(self):
|
30 |
+
# Define the set S
|
31 |
S = ['a', 'b', 'c', 'd', 'e']
|
32 |
counter_example_elements = set()
|
33 |
|
34 |
# Define a map for converting letters to table indices
|
35 |
index = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4}
|
36 |
|
37 |
+
# Operation table as provided
|
38 |
self.operation_table = [
|
39 |
['a', 'b', 'c', 'b', 'd'], # a * a, a * b, a * c, a * d, a * e
|
40 |
['b', 'c', 'a', 'e', 'c'], # b * a, b * b, b * c, b * d, b * e
|
|
|
43 |
['d', 'b', 'a', 'd', 'c'] # e * a, e * b, e * c, e * d, e * e
|
44 |
]
|
45 |
|
46 |
+
# Check for commutativity violations (x * y != y * x)
|
47 |
for x in S:
|
48 |
for y in S:
|
49 |
+
# Convert x and y to their corresponding table indices
|
50 |
+
x_idx = index[x]
|
51 |
+
y_idx = index[y]
|
52 |
+
|
53 |
+
# Check if the operation does not commute
|
54 |
+
if self.operation_table[x_idx][y_idx] != self.operation_table[y_idx][x_idx]:
|
55 |
+
# If not commutative, add both elements to the set
|
56 |
counter_example_elements.add(x)
|
57 |
counter_example_elements.add(y)
|
58 |
|
59 |
# Return the sorted list of elements involved in violations
|
60 |
return sorted(counter_example_elements)
|
61 |
|
|
|
62 |
|
63 |
def maybe_reversed(self, text: str) -> bool:
|
64 |
words = text.split()
|