Skip to content

Commit 35bd93b

Browse files
hyperpolymathclaude
andcommitted
feat(tropical-bridge): wire Isabelle tropical proofs into VCL ProofConsonance
Adds the first live connection between the formally verified tropical matrix theorems in tropical-resource-typing/ and the VeriSimDB/KRL stack. New files: - impl/tropical/TropicalMatrix.jl — min-plus semiring + bellman_ford_matrix; direct Julia mirror of tropm_mat_pow and bellman_ford (Tropical_Matrices_Full.thy) - impl/tropical/TangleGraph.jl — TangleIR DT-code → tropical adjacency matrix; Reidemeister-I neighbourhood (RI⁻); RII/RIII stubs for KnotTheory.jl wire-up - docs/TROPICAL-BRIDGE.adoc — formal correspondence table, gap register, next steps Updated: - impl/vcl/Query.jl — adds ProofConsonance clause (two octad ids + depth bound) - impl/vcl/Prover.jl — prove(ProofConsonance) dispatches to Bellman-Ford path search - examples/krladapter_integration.jl — demo_consonance() exercises all four cases All four demo cases pass: trivial identity, DT-code match, RI-equivalent path (1 move), and correct FAIL for trefoil vs figure-eight at RI-only depth. Formal backing: bellman_ford (OFFICIAL SORRY 2) is still pending in Isabelle; the Julia implementation is algorithmically justified by tropm_mat_pow_eq_sum_walks (proved). Certificate upgrades to machine-checked once the sorry is closed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d562fc1 commit 35bd93b

File tree

6 files changed

+707
-0
lines changed

6 files changed

+707
-0
lines changed
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
// SPDX-License-Identifier: PMPL-1.0-or-later
2+
// SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell
3+
= Tropical Bridge: Isabelle Proofs ↔ Julia Consonance Checker
4+
Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
5+
2026-04-11
6+
:toc:
7+
:toc-placement: preamble
8+
:sectnums:
9+
:icons: font
10+
11+
[.lead]
12+
This document is the formal correspondence table between the Isabelle/HOL
13+
theorems in `tropical-resource-typing/` and the Julia implementation in
14+
`impl/tropical/`. It specifies what the Julia code is *justified by* and
15+
what gaps remain.
16+
17+
== The Claim
18+
19+
`ProofConsonance` in VCL checks tangle equivalence by asking:
20+
21+
____
22+
Is the minimum number of Reidemeister moves from tangle A to tangle B
23+
finite (within the modelled move set)?
24+
____
25+
26+
The answer is computed by `bellman_ford_matrix` in `TropicalMatrix.jl`,
27+
which is a direct Julia mirror of the Isabelle `bellman_ford` theorem.
28+
29+
== Formal Correspondence Table
30+
31+
[cols="1,2,2"]
32+
|===
33+
|Isabelle (tropical-resource-typing/) |Julia (impl/tropical/) |Notes
34+
35+
|`tropical_min` type +
36+
`PosInf`, `Fin' n`
37+
|`Tropical` struct +
38+
`TROP_ZERO` (Inf), `Tropical(n)`
39+
|Min-plus carrier. `Tropical_v2.thy`.
40+
41+
|`a + b = min a b` on `tropical_min`
42+
|`trop_add(a, b) = min(a.val, b.val)`
43+
|`tropm_add_idem: a ⊕ a = a` guarantees idempotency.
44+
45+
|`a * b = a + b` on `tropical_min` +
46+
(∞ absorbing)
47+
|`trop_mul(a, b)` — returns TROP_ZERO if either is ∞
48+
|`Tropical_v2.thy` instances.
49+
50+
|`tropm_mat_id n`
51+
|`trop_mat_id(n)`
52+
|Diagonal TROP_ONE, off-diagonal TROP_ZERO.
53+
54+
|`tropm_mat_mul n A B i j ≡ ∑ k. A i k * B k j`
55+
|`trop_mat_mul(A, B)[i,j] = min_k(A[i,k] + B[k,j])`
56+
|Direct transliteration.
57+
58+
|`tropm_mat_pow n A k`
59+
|`trop_mat_pow(A, k)`
60+
|Right-iterated product; `A^0 = I`.
61+
62+
|`tropm_mat_close n A i j ≡ A i j + tropm_mat_id n i j`
63+
|`trop_mat_close(A)`
64+
|Entry-wise min with identity.
65+
66+
|`tropm_mat_pow_eq_sum_walks` +
67+
(proved — was OFFICIAL SORRY 1)
68+
|Used implicitly: `bellman_ford_matrix` correctness rests on this.
69+
|`A^k[i,j]` = sum over walks of length k.
70+
71+
|`bellman_ford` +
72+
(OFFICIAL SORRY 2 — pending)
73+
|`bellman_ford_matrix(A)` — returns `(I ⊕ A)^{n-1}`
74+
|**See gap table below.**
75+
|===
76+
77+
== Gap Table
78+
79+
[cols="1,3,1"]
80+
|===
81+
|Gap |Impact |Mitigation
82+
83+
|`bellman_ford` sorry not yet closed
84+
|Julia `bellman_ford_matrix` is algorithmically correct but lacks
85+
machine-checked correctness certificate for the closed-form claim.
86+
The algorithm is correct by the matrix-power walk interpretation
87+
(`tropm_mat_pow_eq_sum_walks`, proved); only the no-negative-cycle
88+
optimality claim is unverified.
89+
|Planned Session 2 of tropical proof work.
90+
91+
|RI only (no RII/RIII)
92+
|`TangleGraph.v0.1` models RI moves only. Two tangles related by RII
93+
or RIII moves will receive INCONCLUSIVE (FAIL with reason string), not PASS.
94+
|`_rii_neighbors` and `_riii_neighbors` stubs in `TangleGraph.jl`; wire
95+
to `KnotTheory.jl` once KRLAdapter is linked.
96+
97+
|Infinite Reidemeister graph
98+
|The full Reidemeister move graph is infinite. `build_consonance_graph`
99+
bounds the BFS at `depth` hops. Deep equivalences are undecidable in
100+
general; the prover is sound but not complete.
101+
|Use knot invariants (Jones polynomial via `KnotTheory.jl`) as a
102+
fast-fail before the tropical path search.
103+
|===
104+
105+
== The Architecture
106+
107+
----
108+
Isabelle/HOL Julia (this package) VCL layer
109+
------------------ ---------------------- ---------
110+
Tropical_v2.thy TropicalMatrix.jl Query.jl
111+
tropical_min type ───► Tropical struct ProofConsonance
112+
add / mul ops trop_add / trop_mul
113+
114+
Tropical_Matrices_Full.thy TropicalMatrix.jl
115+
tropm_mat_pow ───► trop_mat_pow
116+
tropm_mat_close trop_mat_close
117+
bellman_ford ─ ─ ► bellman_ford_matrix Prover.jl
118+
(sorry pending) (implemented; prove(ProofConsonance)
119+
formal cert pending)
120+
TangleGraph.jl
121+
build_consonance_graph
122+
dt_codes_from_blob
123+
----
124+
125+
== Usage
126+
127+
[source,julia]
128+
----
129+
# Construct ProofConsonance and evaluate
130+
clause = ProofConsonance(octad_id_trefoil, octad_id_fig8, 3)
131+
result = prove(clause, store, manager)
132+
# → VerdictPass("Reidemeister path: 1 move(s) [tropical Bellman-Ford, ...]")
133+
# or VerdictFail("no path found within depth=3 [RI only; ...]")
134+
----
135+
136+
== Next Steps
137+
138+
1. *Close `bellman_ford` sorry* (Session 2, `tropical-resource-typing/`).
139+
This upgrades the formal status from "algorithmically justified" to
140+
"machine-checked."
141+
2. *Wire RII/RIII* — implement `_rii_neighbors` and `_riii_neighbors` in
142+
`TangleGraph.jl` using `KnotTheory.jl` PD-code manipulations.
143+
3. *Tropical determinant* — add `Tropical_Determinants.thy` (tropical
144+
permanent = max-weight perfect matching); expose as `ProofOptimalAssignment`
145+
in VCL for optimal tangle adapter chain selection.
146+
4. *Jones fast-fail* — before Bellman-Ford, check `Jones(dt_a) ≠ Jones(dt_b)`
147+
via `KnotTheory.jl` for an immediate disequivalence certificate.

verisim-modular-experiment/examples/krladapter_integration.jl

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@ include(joinpath(@__DIR__, "..", "impl", "Crypto.jl"))
2020
include(joinpath(@__DIR__, "..", "impl", "drift", "Metrics.jl"))
2121
include(joinpath(@__DIR__, "..", "impl", "VerisimCore.jl"))
2222
include(joinpath(@__DIR__, "..", "impl", "FederationManager.jl"))
23+
# Tropical modules must be loaded before VCLProver (Prover dispatches to them)
24+
include(joinpath(@__DIR__, "..", "impl", "tropical", "TropicalMatrix.jl"))
25+
include(joinpath(@__DIR__, "..", "impl", "tropical", "TangleGraph.jl"))
2326
include(joinpath(@__DIR__, "..", "impl", "vcl", "Query.jl"))
2427
include(joinpath(@__DIR__, "..", "impl", "vcl", "Prover.jl"))
2528

2629
using .Crypto
2730
using .VerisimCore
2831
using .Metrics
2932
using .FederationManager
33+
using .TropicalMatrix
34+
using .TangleGraph
3035
using .VCLQuery
3136
using .VCLProver
3237

@@ -132,7 +137,76 @@ function demo()
132137
println("\n=== Client satisfied by Core alone. No Federable shapes needed. ===")
133138
end
134139

140+
# -----------------------------------------------------------------------
141+
# Phase 5: Tropical consonance demo
142+
# -----------------------------------------------------------------------
143+
144+
"""
145+
demo_consonance()
146+
147+
Demonstrates PROOF CONSONANCE using tropical Bellman-Ford:
148+
149+
1. Trivial case: same octad id → immediate PASS.
150+
2. Same DT code (same tangle, different provenance) → fast-path PASS.
151+
3. RI-equivalent tangles (differ by one isolated crossing) → tropical PASS.
152+
4. Unrelated tangles (trefoil vs figure-eight) → tropical FAIL (RI only).
153+
154+
Formal backing: `bellman_ford` in Tropical_Matrices_Full.thy.
155+
See impl/tropical/TropicalMatrix.jl for the Julia mirror of the Isabelle proof.
156+
"""
157+
function demo_consonance()
158+
println("\n=== PROOF CONSONANCE — tropical Bellman-Ford demo ===\n")
159+
160+
store = Store()
161+
manager = Manager()
162+
163+
# Helper: store a tangle and return its octad id
164+
function store_tangle(t::TangleIRSurrogate)
165+
id = tangle_octad_id(t)
166+
blob = tangle_to_semantic(t)
167+
enrich!(store, id, :semantic, blob, "krl-demo")
168+
id
169+
end
170+
171+
# Case 1: same octad — trivially consonant
172+
println("--- Case 1: same octad id ---")
173+
trefoil = TangleIRSurrogate("trefoil", [4, 6, 2], :user, "B_1^3")
174+
id_t = store_tangle(trefoil)
175+
r1 = prove(ProofConsonance(id_t, id_t), store, manager)
176+
println(" Result: ", r1)
177+
178+
# Case 2: same DT code, different provenance — fast-path match
179+
println("\n--- Case 2: same DT code, different provenance ---")
180+
trefoil2 = TangleIRSurrogate("trefoil-rewritten", [4, 6, 2], :rewritten,
181+
"Reidemeister III applied")
182+
id_t2 = store_tangle(trefoil2)
183+
r2 = prove(ProofConsonance(id_t, id_t2), store, manager)
184+
println(" Result: ", r2)
185+
186+
# Case 3: RI-equivalent — trefoil with one RI⁺ crossing added then removed
187+
# Simulated: DT code [4, 6, 2] vs [4, 6, 2] with an extra RI pair ±8
188+
# In practice RI⁺ on trefoil gives a 4-crossing diagram with an ear
189+
println("\n--- Case 3: RI-equivalent tangles ---")
190+
# Synthetic RI⁺ of trefoil: prepend an isolated ±2 pair
191+
trefoil_ri = TangleIRSurrogate("trefoil-ri", [2, -2, 4, 6, 2], :derived,
192+
"trefoil + RI ear")
193+
id_ri = store_tangle(trefoil_ri)
194+
r3 = prove(ProofConsonance(id_t, id_ri, 3), store, manager)
195+
println(" Result: ", r3)
196+
197+
# Case 4: different knots — trefoil [4,6,2] vs figure-eight [4,8,12,2,10,6]
198+
println("\n--- Case 4: trefoil vs figure-eight (expected FAIL at RI depth) ---")
199+
fig8 = TangleIRSurrogate("figure-eight", [4, 8, 12, 2, 10, 6], :user,
200+
"figure-eight knot")
201+
id_f8 = store_tangle(fig8)
202+
r4 = prove(ProofConsonance(id_t, id_f8), store, manager)
203+
println(" Result: ", r4)
204+
205+
println("\n=== Consonance demo complete ===")
206+
end
207+
135208
# Run the demo when executed as a script.
136209
if abspath(PROGRAM_FILE) == @__FILE__
137210
demo()
211+
demo_consonance()
138212
end

0 commit comments

Comments
 (0)