Spaces:
Runtime error
Runtime error
Update tools.py
Browse files
tools.py
CHANGED
|
@@ -86,12 +86,11 @@ def detect_non_commutative_subset(table_text: str) -> str:
|
|
| 86 |
if len(lines) < 3:
|
| 87 |
return "Error: Table format invalid or incomplete."
|
| 88 |
|
| 89 |
-
# Parse headers (elements)
|
| 90 |
headers = [h.strip() for h in lines[0].split('|') if h.strip()]
|
| 91 |
|
| 92 |
-
# Parse operation table into a dict
|
| 93 |
operation = {}
|
| 94 |
-
for line in lines[2:]: # skip header
|
| 95 |
cells = [c.strip() for c in line.split('|') if c.strip()]
|
| 96 |
if len(cells) != len(headers) + 1:
|
| 97 |
continue # skip malformed rows
|
|
@@ -100,7 +99,7 @@ def detect_non_commutative_subset(table_text: str) -> str:
|
|
| 100 |
col_label = headers[col_idx]
|
| 101 |
operation[(row_label, col_label)] = result
|
| 102 |
|
| 103 |
-
#
|
| 104 |
involved = set()
|
| 105 |
for a in headers:
|
| 106 |
for b in headers:
|
|
@@ -108,6 +107,7 @@ def detect_non_commutative_subset(table_text: str) -> str:
|
|
| 108 |
involved.update([a, b])
|
| 109 |
|
| 110 |
return ", ".join(sorted(involved)) if involved else "The operation is commutative."
|
|
|
|
| 111 |
except Exception as e:
|
| 112 |
return f"Error analyzing table: {str(e)}"
|
| 113 |
|
|
|
|
| 86 |
if len(lines) < 3:
|
| 87 |
return "Error: Table format invalid or incomplete."
|
| 88 |
|
| 89 |
+
# Parse headers (set elements)
|
| 90 |
headers = [h.strip() for h in lines[0].split('|') if h.strip()]
|
| 91 |
|
|
|
|
| 92 |
operation = {}
|
| 93 |
+
for line in lines[2:]: # skip header and separator
|
| 94 |
cells = [c.strip() for c in line.split('|') if c.strip()]
|
| 95 |
if len(cells) != len(headers) + 1:
|
| 96 |
continue # skip malformed rows
|
|
|
|
| 99 |
col_label = headers[col_idx]
|
| 100 |
operation[(row_label, col_label)] = result
|
| 101 |
|
| 102 |
+
# Find mismatches: x*y ≠ y*x
|
| 103 |
involved = set()
|
| 104 |
for a in headers:
|
| 105 |
for b in headers:
|
|
|
|
| 107 |
involved.update([a, b])
|
| 108 |
|
| 109 |
return ", ".join(sorted(involved)) if involved else "The operation is commutative."
|
| 110 |
+
|
| 111 |
except Exception as e:
|
| 112 |
return f"Error analyzing table: {str(e)}"
|
| 113 |
|