11# SPDX-License-Identifier: PMPL-1.0-or-later
22# Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk >
33
4- # KQL : A Knot-Theoretic Query Language for Topological Data
4+ # KRL : A Knot-Theoretic Query Language for Topological Data
55
66** Author:** Jonathan D.A. Jewell
77** Version:** 1.0
1212
1313## Abstract
1414
15- We present KQL (Knot Query Language), a domain-specific query language for
15+ We present KRL (Knot Resolution Language), a domain-specific query language for
1616QuandleDB that treats mathematical equivalence as a first-class query primitive.
1717Traditional database query languages (SQL, GraphQL, Cypher) model equality as a
1818binary predicate: two values are either equal or not. This model is fundamentally
1919inadequate for topological data, where two objects (e.g., knot diagrams) may be
2020equivalent via multiple distinct paths (Reidemeister moves), and the space of
21- equivalences itself has mathematical structure. KQL addresses this by grounding
21+ equivalences itself has mathematical structure. KRL addresses this by grounding
2222its semantics in Homotopy Type Theory (HoTT), where equality is not a boolean
2323but a * type* —the type of paths between two objects. The result is a query language
2424where equivalence queries return not just matching objects but the * derivations*
@@ -73,7 +73,7 @@ SQL's relational model fails for knot data in several fundamental ways:
7373
7474This paper presents:
7575
76- 1 . ** KQL 's semantic model** grounded in HoTT identity types, where equivalence
76+ 1 . ** KRL 's semantic model** grounded in HoTT identity types, where equivalence
7777 queries return types, not booleans (Section 3).
78782 . ** E-graph-backed execution** using equality saturation (egglog) to compactly
7979 represent equivalence classes (Section 4).
@@ -137,14 +137,14 @@ structure.
137137
138138---
139139
140- ## 3. KQL Semantic Model
140+ ## 3. KRL Semantic Model
141141
142142### 3.1 Equivalence as a Type
143143
144- KQL 's fundamental departure from SQL is that equivalence queries return * types* ,
144+ KRL 's fundamental departure from SQL is that equivalence queries return * types* ,
145145not booleans:
146146
147- ``` kql
147+ ``` krl
148148from knots
149149| where equivalent_to("3_1")
150150| return equivalences
@@ -164,9 +164,9 @@ matching knot K, the *equivalence evidence*:
164164}
165165```
166166
167- ### 3.2 Identity Types in KQL
167+ ### 3.2 Identity Types in KRL
168168
169- KQL models three levels of identity:
169+ KRL models three levels of identity:
170170
1711711 . ** Definitional equality** (` == ` ): Identical representations (same Gauss code).
172172 Decidable, trivial.
@@ -177,15 +177,15 @@ KQL models three levels of identity:
1771773 . ** Path equality** (` ~ ` ): Equivalent via explicit isotopy (sequence of
178178 Reidemeister moves). Returns the path itself.
179179
180- ``` kql
180+ ``` krl
181181from knots
182182| where K ≅ "3_1" via [jones, genus, crossing_number]
183183| return K, proof
184184```
185185
186186### 3.3 Quotient Types
187187
188- KQL represents equivalence classes as quotient types:
188+ KRL represents equivalence classes as quotient types:
189189
190190```
191191Knot / ≅ = { [K] | K ∈ Knot }
@@ -201,12 +201,12 @@ data.
201201
202202### 4.1 Equality Saturation
203203
204- KQL queries are executed against an * e-graph* (equivalence graph), a data
204+ KRL queries are executed against an * e-graph* (equivalence graph), a data
205205structure that compactly represents equivalence classes. Following the egglog
206- paradigm (Willsey et al., PLDI 2023), KQL combines Datalog-style recursive
206+ paradigm (Willsey et al., PLDI 2023), KRL combines Datalog-style recursive
207207queries with equality saturation:
208208
209- ``` kql
209+ ``` krl
210210# Define equivalence rules
211211rule jones_equivalent(K1, K2) :-
212212 knot(K1), knot(K2),
@@ -226,7 +226,7 @@ from knots
226226
227227### 4.2 Stratified Invariant Evaluation
228228
229- Not all invariants are equally expensive to compute. KQL 's query planner
229+ Not all invariants are equally expensive to compute. KRL 's query planner
230230evaluates invariants in order of increasing cost:
231231
232232| Stratum | Invariants | Cost |
@@ -248,7 +248,7 @@ evidence for equivalence.
248248
249249### 5.1 Semiring Annotations
250250
251- Following the provenance semiring framework (Green et al., 2007), KQL annotates
251+ Following the provenance semiring framework (Green et al., 2007), KRL annotates
252252every result with provenance information recording how the result was derived:
253253
254254```
@@ -277,15 +277,15 @@ Provenance = Semiring(
277277
278278### 6.1 Schema as Category
279279
280- Following Spivak (2014), KQL models the database schema as a category C:
280+ Following Spivak (2014), KRL models the database schema as a category C:
281281
282282- ** Objects:** Entity types (Knot, Invariant, Isotopy, Diagram).
283283- ** Morphisms:** Relationships (has_invariant, has_diagram, isotopy_between).
284284- ** Functors:** Data instances (I : C → Set) mapping schema to data.
285285
286286### 6.2 Queries as Functors
287287
288- A KQL query is a functor Q : C → C' between schema categories. This provides:
288+ A KRL query is a functor Q : C → C' between schema categories. This provides:
289289
290290- ** Compositionality:** Queries compose as functors compose.
291291- ** Type safety:** Functors preserve categorical structure, preventing ill-typed
@@ -298,9 +298,9 @@ A KQL query is a functor Q : C → C' between schema categories. This provides:
298298
299299### 7.1 Pipeline Syntax
300300
301- KQL adopts PRQL's pipeline approach for readability:
301+ KRL adopts PRQL's pipeline approach for readability:
302302
303- ``` kql
303+ ``` krl
304304from knots
305305| filter crossing_number <= 10
306306| filter genus == 1
@@ -311,7 +311,7 @@ from knots
311311
312312### 7.2 Equivalence Queries
313313
314- ``` kql
314+ ``` krl
315315from knots
316316| find_equivalent "3_1" via [jones, genus]
317317| return equivalences with provenance
@@ -322,7 +322,7 @@ from knots
322322For navigating relationships between knots (e.g., knots related by specific
323323operations like connected sum):
324324
325- ``` kql
325+ ``` krl
326326from knots as K1
327327| match (K1)-[:CONNECTED_SUM]->(K2)
328328| where K2.crossing_number < K1.crossing_number
@@ -331,7 +331,7 @@ from knots as K1
331331
332332### 7.4 Reidemeister Move Queries
333333
334- ``` kql
334+ ``` krl
335335from diagrams as D1
336336| find_path D1 ~> "3_1" via reidemeister
337337| return path, move_count
@@ -346,7 +346,7 @@ from diagrams as D1
346346| Layer | Language | Purpose |
347347| -------| ----------| ---------|
348348| Engine | Julia (Skein.jl) | Knot storage, invariant computation |
349- | Query Parser | Julia | KQL parsing and AST construction |
349+ | Query Parser | Julia | KRL parsing and AST construction |
350350| E-graph Engine | Julia | Equality saturation, equivalence classes |
351351| API | Julia (HTTP.jl) | REST API for queries |
352352| Frontend | ReScript + React | Interactive query interface |
@@ -379,39 +379,39 @@ end
379379 structured equivalences.
380380- ** Cypher** (Robinson et al., 2015): Graph pattern matching. Useful for
381381 navigating knot relationships but no equivalence semantics.
382- - ** PRQL** (PRQL Project, 2022): Pipeline syntax for SQL. KQL adopts its
382+ - ** PRQL** (PRQL Project, 2022): Pipeline syntax for SQL. KRL adopts its
383383 ergonomics but not its relational semantics.
384384- ** HoTTSQL** (Chu et al., PLDI 2017): SQL semantics via HoTT. Proves
385- equivalence of SQL queries, not of data. KQL adapts HoTT for data equivalence.
385+ equivalence of SQL queries, not of data. KRL adapts HoTT for data equivalence.
386386- ** egglog** (Willsey et al., PLDI 2023): Equality saturation + Datalog.
387- KQL 's execution engine.
388- - ** CQL** (Spivak, 2014): Categorical Query Language. KQL 's schema model.
387+ KRL 's execution engine.
388+ - ** CQL** (Spivak, 2014): Categorical Query Language. KRL 's schema model.
389389
390390### 9.2 Knot Theory Software
391391
392392- ** SnapPy** (Culler et al.): 3-manifold topology. Computations, not queries.
393- - ** KnotInfo** (Livingston & Moore): Web database. SQL backend, no KQL .
393+ - ** KnotInfo** (Livingston & Moore): Web database. SQL backend, no KRL .
394394- ** Knot Atlas** : Wiki-based. No structured query language.
395- - ** Skein.jl** (hyperpolymath): Julia knot engine. KQL 's computation backend.
395+ - ** Skein.jl** (hyperpolymath): Julia knot engine. KRL 's computation backend.
396396
397397### 9.3 Type Theory and Equality
398398
399- - ** HoTT** (Univalent Foundations, 2013): Identity types as paths. KQL 's
399+ - ** HoTT** (Univalent Foundations, 2013): Identity types as paths. KRL 's
400400 semantic foundation.
401401- ** Cubical Agda** (Vezzosi et al., 2019): Computational HoTT. Potential
402402 future implementation target.
403- - ** Lean 4 mathlib** (mathlib Community): Formal quandle definitions. KQL 's
403+ - ** Lean 4 mathlib** (mathlib Community): Formal quandle definitions. KRL 's
404404 proof library.
405405
406406---
407407
408408## 10. Conclusion
409409
410- KQL demonstrates that domain-specific query languages can and should respect
410+ KRL demonstrates that domain-specific query languages can and should respect
411411the mathematical structure of their data. For topological data, binary equality
412412is the wrong abstraction. By grounding query semantics in HoTT identity types,
413413executing queries via equality saturation, and carrying provenance through
414- results, KQL provides a query language that is mathematically honest about
414+ results, KRL provides a query language that is mathematically honest about
415415what it means for two knots to be "the same."
416416
417417The broader lesson is that the choice of equality model is a fundamental design
0 commit comments