Skip to content

Commit cee54f6

Browse files
committed
Remediate SageMath-compatible module and add package import check
1 parent 65263d0 commit cee54f6

File tree

4 files changed

+460
-530
lines changed

4 files changed

+460
-530
lines changed
Lines changed: 55 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,69 @@
11
# `sagemath_compatible_tensor_ops.py` documentation
22

3-
## Location
4-
- Script: `experiments/sagemath_compatible_tensor_ops.py`
3+
## Locations
4+
- Package module: `src/simplicial_tensors/sagemath_compatible_tensor_ops.py`
5+
- Experiment entrypoint wrapper: `experiments/sagemath_compatible_tensor_ops.py`
56

67
## Purpose
7-
This script provides a symbolic tensor implementation (`SymbolicTensor`) for simplicial operations and runs symbolic horn/filler checks from `main()`.
8+
This module provides a SageMath-oriented symbolic tensor implementation (`SymbolicTensor`) for simplicial operations.
89

9-
It defines symbolic versions of:
10-
- `face`, `degen`, `bdry`, `horn`, `filler`,
11-
- symbolic degeneracy checks,
12-
- horn filler uniqueness comparison,
13-
- helper checks for symbol support in horns.
10+
The package module is the implementation source. The experiment file is a thin wrapper that imports and runs the package module's `main()`.
11+
12+
## Runtime backend behavior
13+
- Preferred backend: SageMath symbolic API (`sage.all.var`, `sage.all.simplify`).
14+
- Fallback backend: SymPy, used only when Sage is unavailable so the module remains importable in standard Python environments.
1415

1516
## Core operations
16-
- `face(i)`: removes index `i` from each axis.
17-
- `degen(k)`: duplicates index `k` on each axis.
18-
- `bdry()`: alternating sum of faces.
19-
- `horn(k)`: all faces with the `k`-th face replaced by a zero symbolic tensor.
20-
- `filler(horn_list, k)`: Moore-style horn filler construction.
21-
- `n_hypergroupoid_comparison(...)`: for each selected horn, verifies horn consistency and checks whether filler equals original tensor.
22-
23-
## What `main()` runs
24-
1. Builds a symbolic `(3,3)` tensor and evaluates horn/filler comparison.
25-
2. Runs `check_symbolic_corrections(...)` for horn index `1`.
26-
3. Sweeps shapes `build_shape(k)` for `k=3..5` and all horn indices.
27-
4. Runs additional checks on shape `(4,5,6)` and on `build_shape(d)` for `d=2..6`.
28-
29-
## Outputs
30-
The script prints:
31-
- conjecture prediction vs observed filler uniqueness,
32-
- symbolic tensor/filler displays,
33-
- per-shape horn check summaries,
34-
- correction-symbol diagnostics from `check_symbolic_corrections(...)`.
35-
36-
## Logging
37-
- No file logging is configured.
38-
- All output is written to standard output.
17+
`SymbolicTensor` implements:
18+
- tensor construction with symbolic entries (`range`, `zeros`, `ones`),
19+
- `face(i)`, `degen(k)`, `bdry()`,
20+
- `horn(k)`, `filler(horn_list, k)`,
21+
- symbolic degeneracy check `is_degen()`,
22+
- filler uniqueness check `n_hypergroupoid_comparison(...)`,
23+
- arithmetic (`__add__`, `__sub__`) and symbolic helpers (`simplify`, `subs`).
24+
25+
## Uniqueness comparison algorithm
26+
For each selected horn index:
27+
1. Construct horn and candidate filler.
28+
2. Verify non-missing horn faces are reproduced exactly.
29+
3. Compare filler with original tensor entrywise.
30+
4. If any entry differs for that horn, return `False`.
31+
5. If all selected horns match exactly, return `True`.
32+
33+
This is a per-horn check, so each inner horn is validated independently.
34+
35+
## Outputs and logging
36+
- No file logger is configured.
37+
- Verbose diagnostics are printed to standard output when `verbose=True`.
38+
- Non-verbose mode returns booleans/exceptions without extra logging.
3939

4040
## Run
4141
From repository root:
4242

4343
```powershell
4444
.\.venv\Scripts\python.exe experiments\sagemath_compatible_tensor_ops.py
45+
```
46+
47+
Direct package import:
48+
49+
```powershell
50+
.\.venv\Scripts\python.exe -c "import simplicial_tensors.sagemath_compatible_tensor_ops as m; print(m.HAVE_SAGE)"
51+
```
52+
53+
SageMath execution (recommended for Sage backend):
54+
55+
```bash
56+
sage -python -m pytest -q tests/test_sagemath_compatible_tensor_ops.py
57+
```
58+
## Recommended Direct Check (SageMath 10.7+)
59+
Run this from repository root in a SageMath 10.7+ environment:
60+
61+
```bash
62+
sage -python -m pytest -q tests/test_sagemath_compatible_tensor_ops.py
63+
```
64+
65+
Optional backend confirmation:
66+
67+
```bash
68+
sage -python -c "import simplicial_tensors.sagemath_compatible_tensor_ops as m; print('HAVE_SAGE=', m.HAVE_SAGE)"
4569
```

0 commit comments

Comments
 (0)