Skip to content

Commit 4c74d07

Browse files
hyperpolymathclaude
andcommitted
docs(quandledb): add EXPLAINME, TEST-NEEDS, PROOF-NEEDS
Fills 3 doc gaps identified in doc-completeness audit: - EXPLAINME.adoc: one-line summary, honest scope, polyglot architecture, invariants, boundaries, known gaps - TEST-NEEDS.md: 21 assertions today, 12 categories of gaps documented, 5 highest-value next tests identified - PROOF-NEEDS.md: 4 mathematical obligations (quandle axioms, Reidemeister invariance, canonicalisation idempotence, colouring well-definedness) + 3 systems obligations (cross-platform determinism, Idris2↔Zig layout agreement, NIF safety) These are scaffolds with honest content, not complete proofs/tests — they clarify what WOULD need to be done for CRG D → C promotion. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 07bca08 commit 4c74d07

3 files changed

Lines changed: 270 additions & 0 deletions

File tree

quandledb/EXPLAINME.adoc

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// SPDX-License-Identifier: PMPL-1.0-or-later
2+
// Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk>
3+
4+
= EXPLAINME — QuandleDB
5+
Jonathan Jewell (hyperpolymath)
6+
:toc:
7+
8+
== One-line summary
9+
10+
Semantic fingerprint layer of the KRL stack — extracts quandle presentations
11+
from knot diagrams, computes canonical hashes, and indexes them for
12+
equivalence search, built as a polyglot stack (Julia + Idris2 + Zig + V + Elixir).
13+
14+
== Honest scope
15+
16+
This project *does* the following:
17+
18+
* Julia HTTP server wrapping Skein.jl + KnotTheory.jl for knot storage/query
19+
* `QuandleSemantic` Julia module extracting quandle presentations from
20+
`PlanarDiagram` and producing canonical fingerprints
21+
* Maintains a separate SQLite sidecar index (`quandle_semantic_index`)
22+
specifically for semantic queries, keeping raw-diagram storage in Skein
23+
* Idris2 ABI type layer for the semantic API
24+
* Zig FFI layer for the semantic API (C-compatible)
25+
* V-lang API wrappers
26+
* Elixir BEAM NIF bindings
27+
28+
This project *does NOT* do the following:
29+
30+
* Compute invariants (Jones, Alexander, etc. — that's KnotTheory.jl's job)
31+
* Store raw diagrams (that's Skein.jl's job)
32+
* Parse KRL or any knot-specific query language
33+
* Implement Reidemeister moves
34+
35+
== Why it exists
36+
37+
Quandle presentations are a complete invariant for many knot families under
38+
isotopy: two knots with different fundamental quandles are provably distinct.
39+
Unlike polynomial invariants (Jones, Alexander) which can fail to discriminate,
40+
quandle-based fingerprints provide semantic identity — *equivalence search*
41+
rather than just *property lookup*.
42+
43+
Structurally: Skein stores raw diagrams; KnotTheory computes polynomial
44+
invariants; QuandleDB computes algebraic fingerprints derived from the
45+
fundamental quandle. Each layer enforces its own boundary.
46+
47+
== The polyglot architecture
48+
49+
[cols="1,2,2",options="header"]
50+
|===
51+
|Layer |Language |Purpose
52+
53+
|ABI |Idris2 |Dependently-typed interface definitions + layout proofs
54+
|FFI |Zig |C-compatible implementation of semantic API
55+
|API |V |Typed API triples
56+
|Service |Julia |`server/serve.jl` HTTP server with quandle sidecar
57+
|Compute |Julia |`server/quandle_semantic.jl` presentation extraction + hashing
58+
|Client |Elixir/BEAM |NIFs for BEAM-ecosystem consumers
59+
|===
60+
61+
This matches the hyperpolymath estate standard (Idris2 ABI + Zig FFI +
62+
V API triples + Julia/Elixir service layer).
63+
64+
== Invariants (not to be violated)
65+
66+
1. *Raw diagrams live in Skein.* QuandleDB's sidecar SQLite is for semantic
67+
fingerprints only. Do not duplicate Skein's `knots` table here.
68+
2. *Quandle computation is deterministic.* Identical input diagrams must
69+
produce identical fingerprints, regardless of platform or run.
70+
3. *ABI layer never leaks Julia types.* Idris2/Zig/V see only C-compatible
71+
structures.
72+
4. *Never modify KnotTheory.jl or Skein.jl.* They're community libraries
73+
consumed by this project, not targets for modification.
74+
75+
== Boundaries
76+
77+
[cols="2,2",options="header"]
78+
|===
79+
|Concern | Where it belongs
80+
81+
|Crossings, PD codes, Reidemeister moves
82+
|KnotTheory.jl
83+
84+
|Raw diagram storage + invariant cache (Jones, Alexander, determinant)
85+
|Skein.jl
86+
87+
|Quandle presentation extraction from PlanarDiagram
88+
|`server/quandle_semantic.jl` (here)
89+
90+
|Canonical quandle fingerprint hashing
91+
|`server/quandle_semantic.jl` (here)
92+
93+
|Coloring counts into finite quandles
94+
|`server/quandle_semantic.jl` (here, planned)
95+
96+
|TangleIR definition + adapters
97+
|`../../KRLAdapter.jl`
98+
99+
|KRL query language
100+
|`../../krl/` (forthcoming)
101+
|===
102+
103+
== Evidence this works today
104+
105+
* 21 tests passing (9 quandle extraction + 12 semantic index integration)
106+
* `panic-attack assail` 0 findings
107+
* Idris2 ABI types defined
108+
* BEAM NIFs build and load
109+
110+
== Known gaps (honest)
111+
112+
* CRG grade D — tests present but thin coverage, no per-layer READMEs
113+
* No full-stack integration test spanning Idris2 → Zig → V → Julia → BEAM
114+
* No benchmark suite
115+
* No fuzz harness
116+
* `TEST-NEEDS.md` and `PROOF-NEEDS.md` just added as scaffolding; content is thin
117+
* Colouring count implementation not yet wired
118+
* No OpenAPI / contract spec for HTTP endpoints
119+
120+
See `READINESS.md` for the path from D to C.
121+
122+
== Related
123+
124+
* link:README.adoc[README.adoc] — public overview
125+
* link:READINESS.md[READINESS.md] — CRG grade D assessment + path to C
126+
* `../../Skein.jl/` — knot persistence layer
127+
* `../../KnotTheory.jl/` — combinatorial engine
128+
* `../../KRLAdapter.jl/` — TangleIR adapter package
129+
* `../../krl/` — KRL surface language (scaffolded)

quandledb/PROOF-NEEDS.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<!-- SPDX-License-Identifier: PMPL-1.0-or-later -->
2+
<!-- Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk> -->
3+
4+
# PROOF-NEEDS — QuandleDB
5+
6+
Mathematical and systems obligations for the quandle semantic layer.
7+
8+
## Mathematical obligations
9+
10+
### M1. Quandle axioms preserved
11+
Statement: For every `QuandlePresentation` produced by `extract_presentation`,
12+
the derived action satisfies the three quandle axioms:
13+
14+
1. `a ▷ a = a` (idempotence)
15+
2. For every `a`, the map `x ↦ x ▷ a` is a bijection (right-invertibility)
16+
3. `(a ▷ b) ▷ c = (a ▷ c) ▷ (b ▷ c)` (right self-distributivity)
17+
18+
Current status: not proved; not tested. Essential — if presentations don't
19+
satisfy quandle axioms, the fingerprint is meaningless.
20+
21+
### M2. Reidemeister invariance
22+
Statement: If diagrams D₁ and D₂ differ by a single Reidemeister move,
23+
their extracted presentations produce the same fingerprint.
24+
25+
Current status: not proved; not tested on arbitrary R-move pairs.
26+
27+
### M3. Canonicalisation is idempotent
28+
Statement: `canonicalize_presentation(canonicalize_presentation(p)) ==
29+
canonicalize_presentation(p)`.
30+
31+
Current status: expected by construction; not proved. Should be provable
32+
by the canonical-relabelling sort being a total order.
33+
34+
### M4. Colouring count well-definedness
35+
Statement: For a finite quandle Q and a presentation p, the number of
36+
quandle homomorphisms from `fundamental(p)` to Q depends only on the
37+
isomorphism class of `fundamental(p)` — not on the particular presentation.
38+
39+
Current status: this is a standard result; need to verify the
40+
implementation actually respects it.
41+
42+
## Systems obligations
43+
44+
### S1. Fingerprint determinism across platforms
45+
Statement: Given identical input bytes, `quandle_fingerprint` produces
46+
identical output bytes on Linux x86_64, Linux aarch64, macOS, and WebAssembly.
47+
48+
Current status: single-platform tested only.
49+
50+
### S2. Idris2 ABI ↔ Zig FFI layout agreement
51+
Statement: Every record type defined in `src/abi/Types.idr` has a
52+
byte-for-byte identical memory layout in the corresponding Zig struct
53+
in `src/ffi/semantic_ffi.zig`.
54+
55+
Current status: declared, not proved. Idris2's dependent types could
56+
encode the layout directly — this is exactly what the ABI/FFI boundary
57+
discipline is for.
58+
59+
### S3. NIF safety
60+
Statement: BEAM NIFs in `beam/native/quandle_db_nif.zig` never crash the
61+
BEAM VM, even on malformed input from the Elixir side.
62+
63+
Current status: tested on well-formed inputs only. No fuzz on the NIF boundary.
64+
65+
## Proof stack (intended)
66+
67+
- **Idris2** for ABI layout / type-level invariants
68+
- **Property-based tests (Julia)** for mathematical invariants M1-M4 as
69+
empirical evidence
70+
- **Zig's comptime** for layout assertions at the FFI boundary
71+
- **BEAM Dialyzer** for NIF typespec discipline
72+
73+
## How to propose a new obligation
74+
75+
1. State claim precisely.
76+
2. Classify: mathematical, systems, or contract.
77+
3. Either add property-based test as empirical evidence, OR write formal
78+
proof under `verification/` (create that dir if needed).
79+
4. Move to "Currently verified" section (to be created) when discharged.

quandledb/TEST-NEEDS.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<!-- SPDX-License-Identifier: PMPL-1.0-or-later -->
2+
<!-- Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk> -->
3+
4+
# TEST-NEEDS — QuandleDB
5+
6+
Honest accounting of test coverage across the polyglot stack.
7+
8+
## What's tested today (21 assertions total)
9+
10+
| Layer | Tests | Location |
11+
|---|---|---|
12+
| Julia quandle extraction | 9 | `server/test_semantic_index.jl` |
13+
| Julia semantic index integration | 12 | `server/test_semantic_index.jl` |
14+
| Idris2 ABI || none |
15+
| Zig FFI || none |
16+
| V-lang API || none |
17+
| BEAM NIFs | declared | `beam/test/quandle_db_nif_test.exs`, `beam/test/quandle_db_nif_live_integration_test.exs` (not run in estate-wide sweep) |
18+
| Full-stack (Idris → Zig → V → Julia → BEAM) || none |
19+
20+
## What's NOT tested
21+
22+
| Category | Why missing | Priority |
23+
|---|---|---|
24+
| unit (per-layer) | Only Julia has explicit unit tests | high |
25+
| P2P / cross-process | BEAM↔Julia link not stress-tested | medium |
26+
| E2E (polyglot) | No test spans the full stack | high |
27+
| build (all layers) | CI only builds Julia server; ABI/FFI/API/BEAM not verified in CI | high |
28+
| property-based | No property tests for quandle fingerprint determinism, canonicalisation | high |
29+
| mutation | Not set up anywhere | medium |
30+
| fuzz | No fuzz harness for random knot diagrams | medium |
31+
| contract | No OpenAPI / interface contract for HTTP endpoints | medium |
32+
| regression | No named regression suite | medium |
33+
| chaos | No fault injection (e.g. SQLite mid-write) | low |
34+
| compatibility | Single-platform only | low |
35+
| proof-regression | Idris2 ABI has types but no discharged proofs | medium |
36+
37+
## Highest-value tests to add next (for CRG grade D → C)
38+
39+
1. **Quandle fingerprint determinism** (property-based):
40+
Same input diagram → same fingerprint hash, across N=100+ random test diagrams.
41+
2. **Quandle fingerprint canonicalisation**:
42+
For known-equivalent presentations (e.g. Reidemeister moves applied), fingerprint matches.
43+
3. **Colouring count on known knots**:
44+
Trefoil, figure-eight, unknot against expected colouring counts into Z/3, Z/5.
45+
4. **BEAM ↔ Julia NIF handshake**:
46+
BEAM test actually loads the NIF and executes a quandle extraction end-to-end.
47+
5. **Full-stack smoke**:
48+
Idris2-typed call → Zig FFI → V → Julia server → round-trip result.
49+
50+
## How to add new tests
51+
52+
For Julia:
53+
- Add to `server/test_semantic_index.jl` under an appropriate `@testset`.
54+
- Run with `julia --project=server -e 'include("server/test_semantic_index.jl")'`.
55+
56+
For BEAM:
57+
- Add to `beam/test/quandle_db_nif_test.exs`.
58+
- Run with `cd beam && mix test`.
59+
60+
For full-stack integration:
61+
- Create `tests/integration/` at repo root.
62+
- Script the Idris2→Zig→V→Julia→BEAM handshake with assertions at each layer.

0 commit comments

Comments
 (0)