Turing-Complete Computation on the Drosophila Hemibrain Connectome
Compiling a Vector Programming Language to the Drosophila Hemibrain Connectome
Emma Leonhart
Abstract
We compile programs written in Sutra, a vector programming language, to execute on a spiking neural network model of the Drosophila melanogaster mushroom body, wired with real synaptic connectivity from the Janelia hemibrain v1.2.1 connectome (Scheffer et al. 2020). Sutra's primitive set — conditional branching, unbounded data-dependent iteration, and addressable read/write memory via VSA bind/unbind — is compiled onto the connectome-derived circuit and measured running there. The language provides the primitive set needed for general-purpose programming; the particular 140-D fly mushroom body used here is a bounded finite-state machine, as is any physical computer with finite memory — the programmability claim is about the language primitives, not the tape. Conditional branching is realized as fuzzy weighted superposition per the language specification; across five independent hemibrain simulations the four-way conditional program achieves 80/80 correct decisions (standard deviation zero, all four program permutations distinct on every run). Iteration is realized as eigenrotation through vector space with KC-space prototype match as the termination signal, and across the same five-seed scaling it achieves 20/20 on the convergence, counting, and ordering tests combined; addressable memory is realized through sign-flip bind with codebook cleanup. Bundle, bind, and rotation all run as spiking circuits — bundle and rotation additionally validated on real FlyWire v783 wiring. For iteration specifically, the rotation operator Q is the nearest-orthogonal matrix to a real FlyWire v783 subset weight matrix W (polar decomposition of the central-complex EPG→EPG recurrent projection plus an hDelta recurrent subset, 140-D block-diagonal total; ‖W − Q‖_F / ‖W‖_F = 0.983, so Q is derived from real connectome wiring but is not identical to it — we report this explicitly rather than claim "the biology rotates"), and the termination readout runs on the real hemibrain MB (PN→KC wiring), with counting and ordering passing 5/5 + 5/5 end-to-end real-wiring and a target-k sweep at k ∈ {1, 2, 3, 5, 8, 12} × 5 seeds passing 30/30. Scaling to the full ~130k-neuron FlyWire connectome is explicit future work, not a current result. The earlier synthetic-Givens and random-PN→KC caveats are therefore closed for loops; we retain them in the record as wrong-discriminator baselines. Programming the connectome is harder than programming silicon because the tape cannot be grown on demand; we present the operational primitives and argue that tape virtualization — scaling to FlyWire, chaining mushroom bodies, or a neuromorphic substrate with the same motifs — is an engineering extension, not a new mechanism. To our knowledge, this is the first demonstration of a vector programming language, with the primitive set needed for general-purpose computation, compiled to a real connectome-derived circuit and evaluated there.
The Substrate
The execution substrate is the right mushroom body of an adult Drosophila melanogaster, as reconstructed in the Janelia hemibrain v1.2.1 connectome. The circuit consists of:
| Component | Count | Role |
|---|---|---|
| Projection Neurons (PNs) | 140 | Input layer (connectome-derived) |
| Kenyon Cells (KCs) | 1,882 | Sparse coding layer (connectome-derived) |
| APL neuron | 1 | Graded feedback inhibition (enforces ~7.8% sparsity) |
| MBONs | 20 | Learned readout layer |
The PN→KC connectivity is loaded directly from the connectome — it is the actual synaptic wiring of a real fly, not a random approximation. The APL neuron provides dynamical feedback inhibition following the biology described in Papadopoulou et al. 2011 and Lin et al. 2014. The readout layer uses a learned linear map from KC firing patterns to output vectors, fitted via ridge regression — the same shape of computation a real MBON performs via dopamine-gated plasticity. The circuit is simulated in Brian2 using leaky integrate-and-fire neurons.
The mushroom body is a natural substrate for vector symbolic architecture (VSA) because its core operation — sparse random projection from 140 PNs to 1,882 KCs — is structurally identical to VSA encoding. The dimensionality expansion from 140 to 1,882 provides the capacity for clean pattern discrimination that VSA requires.
What runs where. Sutra has two kinds of things in a program: scaffolding (scalars, tuples, bounded iteration counters — the bookkeeping that surrounds vector work) and vector operations (bundle, bind, rotation, similarity, projection, snap). Every vector operation runs on the substrate at runtime; there is no class of vector op that is allowed to run on host numpy. bundle(a, b) = a + b is two Poisson input populations converging on leaky-integrator output neurons via excitatory synapses (literal EPSP summation), validated both on synthetic weights (cos=0.96 at dim=32, 500 ms) and on real FlyWire v783 wiring — the real 685-ALPN → 517-LHLN convergent projection with weights = syn_count × NT-sign reproduces W·(a+b) at cos=0.94, no weight tuning (fly-brain/neural_vsa_flywire.py). bind(a, role) = a * sign(role) is a Poisson input projecting through role-signed synapses plus a shared bias rail (cos=0.94, sign-match=0.94 at dim=32, 500 ms). For rotation we use real FlyWire wiring as the operator, not a synthetic Givens composition: the rotation operator Q is the polar-decomposition nearest-orthogonal matrix to a real FlyWire v783 weight matrix (central-complex EPG→EPG recurrent in 51-D, plus an FB hDelta-subset recurrent projection in 89-D, block-diagonally composed to 140-D total), and v → Q · v runs as a Brian2 feedforward LIF circuit whose synaptic weight matrix is Q itself (positive entries excitatory, negative inhibitory). The circuit then executes sparse projection into 1,882-D KC space, APL-enforced sparsity, and Jaccard prototype match. Program-level decisions — which conditional branch is taken, when a loop terminates — are made by the circuit's response in KC space. The earlier synthetic-Givens spiking circuit (fly-brain/neural_vsa.py, cos=0.99 at dim=32) is retained as a baseline for the rotation primitive but is not the operator used in the loop results below; the real-FlyWire Q is.
Result 1: Conditional Branching
The compiler translates Sutra conditional programs into sequences of VSA operations that execute on the spiking substrate. The reference program (fly-brain/fuzzy_conditional.py, spec-aligned per planning/sutra-spec/03-control-flow.md) encodes four distinct decision-making programs using bind, bundle, snap, and similarity, each mapping two binary inputs (odor presence × hunger state) to one of four behavioral outputs (approach, ignore, search, idle).
| Program A | Program B | Program C | Program D | |
|---|---|---|---|---|
| vinegar + hungry | approach | search | ignore | idle |
| vinegar + fed | ignore | idle | approach | search |
| clean_air + hungry | search | approach | idle | ignore |
| clean_air + fed | idle | ignore | search | approach |
How branching is compiled. Per the Sutra control-flow specification, a fuzzy conditional is realized as weighted superposition rather than a discrete if: result = Σ w_i · branch_i, where w_i are the clipped cosine scores of the snapped query against the four pre-compiled joint prototypes (smell × hunger → PH, PF, AH, AF). All four branches execute simultaneously on the substrate; the prototype-matching circuit determines the weights; the argmax against a behavior codebook defuzzifies. The four programs share the same prototype table and the same decision pipeline — they differ only in the prototype-to-behavior map (a compile-time table). There is no host-side if, no sign-flip on the query, and no program-dependent surgery of the input; the branch chosen on any given trial is a consequence of the circuit's KC-space similarity scores, not of a Python conditional.
Result: across five independent hemibrain simulations (different Brian2 seeds, independent Poisson spike trains), the four-way conditional program produced 80/80 correct decisions, standard deviation zero, with all four program permutations distinct on every run (per-program accuracy 100% for A, B, C, and D). The substrate is a reliable four-way discriminator once branching is compiled as the specification prescribes rather than as a permutation trick on the query. For reproducibility: python fly-brain/scale_eval_conditional.py --n-runs 5 (harness parameters: hemibrain v1.2.1, 140 PN → 1,882 KC, fixed-frame PN→KC seed, 300 ms simulation per snap, Brian2 2.10.1 LIF).
The binding operation computes a * sign(b) in the PN input space — an input transformation analogous to antennal lobe lateral processing (Wilson 2013). The PN→KC synaptic weights remain fixed throughout; no synapse modification occurs during computation.
Result 2: Iteration via Geometric Loops
Iteration is implemented as geometric rotation in vector space. A loop body is an orthogonal matrix Q. Each iteration applies Q to the state vector, projects the result through the mushroom body circuit, and compares the resulting KC activation pattern against pre-compiled prototype patterns via Jaccard overlap. The loop terminates when a prototype match exceeds a threshold. The brain counts by accumulating rotation: N iterations of rotation by angle θ accumulates Nθ total rotation, and target prototypes placed at known angles act as stopping conditions.
The pipeline that produces the results below is real-connectome end-to-end. The rotation operator Q is the polar-decomposition nearest-orthogonal matrix to a 140-D block-diagonal slice of real FlyWire v783 wiring — Q = block_diag(Q_{EPG, 51}, Q_{hDelta, 89}), where Q_{EPG} is the polar decomposition of the central-complex EPG→EPG recurrent weight matrix (51 neurons, effective rank 49) and Q_{hDelta} is the polar decomposition of an hDelta-subset recurrent projection (FB hDelta types J+K+A+D+E, 30+31+12+8+8 = 89 neurons). Both blocks satisfy Q^T Q = I to Frobenius residual ~10⁻¹⁴, det Q = +1, norm preservation to machine precision (fly-brain/real_rotation_epg.py, real_rotation_140D_jaccard.py). The readout is the real hemibrain PN→KC projection (140 → 1,882) with APL-enforced sparsity. The termination signal is Jaccard overlap on KC patterns against a compiled prototype, threshold = 0.5 (measurement-justified — gap probes show off-target Jaccard ≤ 0.373 and target Jaccard = 1.000, bimodal with no ambiguity in (0.25, 0.95); see §Honest Limits). There is no synthetic Givens matrix in this pipeline, no random PN→KC mock, and no host-side cosine readout. Both the rotation operator and the readout are real connectome wiring.
Results across five independent seeds (20/20 PASS):
| Test | Description | Result (5 seeds) |
|---|---|---|
| Convergence | Target at step 3, rotation across 20 2D planes | 5/5 matched target; iters mean=1.00 σ=0 (the large per-step angle covers multiple logical steps) |
| Counting to 3 | Prototype at step 3 | 5/5 matched THREE when targeted |
| Counting to 6 | Prototype at step 6 | 5/5 matched SIX when targeted |
| Ordering | Prototypes at steps 2, 5, 8; no specified target | 5/5 hit EARLY first (nearest prototype in geometric order) |
A separate target-k sweep at k ∈ {1, 2, 3, 5, 8, 12} × 5 seeds on the same 140-D real-wiring loop passes 30/30, with every loop terminating at exactly n_iters == target_k and peak Jaccard at target = 1.000 out to k = 12 — four times the originally tested horizon — confirming the readout is not specific to a lucky k (fly-brain/real_rotation_140D_jaccard_ksweep.py, planning/findings/2026-04-13-jaccard-target-k-sweep-30-of-30.md). Combined across both harnesses the real-wiring loop is 50/50 at n=5 seeds, σ=0.
All prototype compilations and loop iterations share the same PN→KC projection (the fixed-frame invariant), ensuring KC patterns from different iterations are comparable. Nested loops are rotations in orthogonal subspaces — with 140 input dimensions, there is room for up to 70 independent nesting levels. Reproducibility: python fly-brain/scale_eval_loop.py --n-runs 5 for the 20/20 table; python fly-brain/real_rotation_140D_jaccard_ksweep.py for the 30/30 sweep (same harness shape as scale_eval_conditional.py).
Language Primitives vs Substrate Boundedness
Two claims need to be cleanly separated, because conflating them is what drives most of the skepticism around connectionist "general-purpose computation" results.
Claim 1 (the language): Sutra provides the primitive set needed for general-purpose programming. Conditional branching on computed state, unbounded data-dependent iteration, and addressable read/write memory are the operations every general-purpose language needs; Sutra defines all three (see planning/sutra-spec/02-operations.md, 03-control-flow.md, 04-defuzzification.md) and a compiler (sdk/sutra-compiler/) emits real code for them. This claim is about the language, not the hardware — the same way C supports general-purpose computation irrespective of whether you run it on a 486 or an ARM Cortex-M0.
Claim 2 (the substrate): this specific 140-D fly mushroom body is a bounded finite-state machine. So is every physical computer ever built. The relevant question is whether the finite bound is load-bearing against the primitive set — and for the programs we compile here (4-way conditionals, small-integer loops, small key-value stores), it is not. Scaling to the full ~130k-neuron FlyWire circuit, chaining mushroom bodies, or deploying on a neuromorphic substrate with the same motifs is an engineering extension of the same primitive set, not a new mechanism.
The paper below is about Claim 1. We demonstrate that each of Sutra's three primitives compiles to operations executing on the real hemibrain connectome — not that an individual fly brain is itself a universal computer. That language-vs-substrate distinction is the same one anyone writing a compiler lives with every day.
The three primitives required:
Conditional branching — decisions gated on computed state. Demonstrated in §Result 1: four permutation programs, each realized on the substrate via fuzzy weighted superposition (
result = Σ w_i · branch_i) perplanning/sutra-spec/03-control-flow.md. The branch selection is made by KC-space similarity, not a host-side test. 80/80 across five independent hemibrain runs, σ=0.Unbounded iteration — repeat computation an arbitrary number of times with data-dependent termination. Demonstrated in §Result 2: geometric loops traverse the vector space as an eigenrotation (helix R^i·v₀), and termination is triggered by KC-space prototype match — not by a counter hitting a preset limit.
loop (N)with a literal N unrolls at compile time and needs no runtime iteration at all (spec03-control-flow.md).Read/write addressable memory — store, retrieve, and address intermediate state. The codebook + bind/unbind gives us this. A hypervector
record = bind(k₁, v₁) + bind(k₂, v₂) + ... + bind(k_n, v_n)superposes n key–value slots in a single D-dimensional vector. Reading slot i — "what is the value bound to key k_i?" — isunbind(record, k_i), which for sign-flip binding is self-inverse:sign(k_i) * record ≈ v_i + crosstalk_from_other_slots. The crosstalk is suppressed bysnapto the nearest codebook entry, so the readout returns the clean storedv_i. Writing to slot i isrecord' = record + bind(k_i, v_i_new) - bind(k_i, v_i_old)— again all realized as vector operations on the substrate. This is addressable memory in the VSA sense (Plate 1995, Kanerva 2009), not a static lookup: any key can be used to index, keys and values are themselves vectors in the same space, and the memory is composable with other ops.
What is on the substrate, what is on the host. We separate these cleanly because the paper's value depends on it, and because past iterations of this work did hide host arithmetic behind architectural labels. We do not do that here.
Conditional branching — on the substrate. The four-way decision that routes (smell, hunger) to one of four behaviors is
snap(bind(smell, hunger))→ Jaccard similarity against the four joint-input prototypes, entirely in KC space. The branch that "fires" is the prototype with the highest KC-pattern overlap. No host-side test selects the branch. What the host does after the circuit finishes is a four-wayargmaxover four scalar scores — a readout, not branching. Readout is trivially not on the substrate the same way reading a CPU register onto a monitor is trivially not on the CPU; every biological system has readout.Rotation — the operator is derived from real FlyWire wiring. The rotation step runs on spiking neurons in one pipeline and on host numpy in another; we report both and label which is which. We surveyed eleven FlyWire v783 connectome motifs for near-orthogonality (
fly-brain/survey_rotation_candidates.py) and selected the central-complex EPG→EPG recurrent projection (51 neurons, effective rank 49, off-diagonal fraction 0.508 — an order of magnitude closer to orthogonal than the ALPN→LHLN feedforward projection we first tried). Polar decompositionW = Q Pof the real 51×51 EPG→EPG weight matrix (fly-brain/real_rotation_epg.py) yields a proper orthogonalQ(Q^T Q = Ito Frobenius residual 1.68×10⁻¹⁴, detQ= +1, norm preservation to machine precision).Qis the nearest orthogonal matrix to the biologicalW, notWitself — the biological matrix lies 98.3% of its Frobenius norm away fromQ, so the honest framing is "the rotation operator is derived from real FlyWire EPG wiring via polar decomposition," not "the biology is a rotation." Two run paths exist in the repo and the paper cites numbers from both. (A) Spiking-rotation pipeline (fly-brain/real_rotation_epg_loop_spiking.py):v → Q · vruns as a Brian2 circuit (Qas synapse weights, state as Poisson rates, output decoded from steady-state membrane voltage vianeural_linear_mapinfly-brain/neural_vsa.py) followed by a host-side cosine argmax readout. (B) Jaccard-readout pipeline (fly-brain/real_rotation_140D_jaccard.py, drivingFlyBrainVSA.loopatvsa_operations.py:550):state ← R^i · v₀is host-sidenumpy.matmul, and the MB PN→KC projection + Jaccard-on-KC termination run on the substrate. Pipeline (A) is substrate-compliant for the rotation step but not for the readout. Pipeline (B) is the inverse. Neither is fully substrate-compliant per the current spec (planning/sutra-spec/02-operations.mdSubstrate Rule). §Honest Limits reports the numbers from each pipeline under its correct label; the previously-claimed "no numpystate = Q @ vin the run path we report here" was wrong for pipeline (B) and is retracted.The outer loop sequencer — currently on host. Calling the substrate with the next state vector, checking whether the termination predicate has fired, and dispatching control flow between iterations runs in host Python. This is the one genuine piece of control flow that does not yet execute on the connectome. Lifting it onto the substrate (a lateral-inhibition winner-take-all over prototype-match signals, feeding back into the next iteration's rotation input) is open engineering work (
planning/open-questions/conditional-branching-on-remote.md). We flag this rather than hide it.
In-Repo Specification and Compiler
To address concerns about external documentation and reproducibility, the Sutra language surface, operation model, control-flow semantics, and VSA math axioms are fully specified in the project repository under planning/sutra-spec/. The load-bearing files are 02-operations.md (the scaffolding-vs-vector-operation model and the substrate rule referenced throughout this paper), 03-control-flow.md (the loop (N) / loop (condition) semantics including eigenrotation, and the fuzzy-weighted-superposition conditional form used in §Result 1), 04-defuzzification.md (the is_true recursive-threshold control), 11-vsa-math.md (the eight VSA axioms and the vector-space structure they define), and 19-substrate-candidates.md (the substrate-compatibility rules for each operation). The compiler is at sdk/sutra-compiler/; the .su programs cited here compile through that pipeline into Python that calls the fly-brain/vsa_operations.py runtime. Everything named in this paper is therefore inspectable, runnable, and separate from the paper text — it is a specified language with an implementation, not a label attached to an ad-hoc script.
Methods
Encoding. Hypervectors are encoded as PN input currents via centered rate coding: zero components map to a baseline current (1.2), positive components to above-baseline (more spikes), negative components to below-baseline (fewer spikes).
Decoding. A learned linear readout W maps KC firing rates to output vectors. W is fitted once via ridge regression on ~80 (hypervector, KC firing pattern) pairs collected by running random inputs through the circuit — a program-independent calibration step, not a task-specific classifier. The same W is reused across all four conditional programs and all loop tests without refitting. This is the same computation shape a real MBON acquires via associative learning: a linear map from KC population activity to readout, learned from experience without access to the connectivity matrix.
Binding, bundling, and rotation. All three are Brian2 spiking circuits (fly-brain/neural_vsa.py). bundle(a, b) = a + b uses two Poisson input populations at rates f(a_i) and f(b_i) projecting one-to-one onto a leaky-integrator output population through unit excitatory synapses; steady-state membrane voltage reads out a + b. bind(a, role) = a * sign(role) uses a single Poisson input per dimension projecting onto an output neuron through a synapse whose sign is fixed by sign(role_i), with a shared bias rail so role-negative dimensions have headroom for inhibition. rotate(v, R) = R · v generalizes: a feedforward two-population network where output neuron i receives a synapse from every input j with per-connection weight R[i, j] · W — excitatory if R[i, j] > 0, inhibitory if negative. The rotation matrix R is itself constructed at compile time as a composition of Givens rotations, analogous to how the PN→KC projection is fixed at compile time by FlyWire. In each case the operand vectors are consumed by synaptic integration; no host-side elementwise product, sum, or matmul is computed. The PN→KC connectome weights remain fixed and untouched by these per-operation circuits; the two networks are stacked (per-op circuit feeds its output into PN→KC), not merged into one.
Conditional branching (fuzzy weighted superposition). The four-way conditional compiles to a prototype table compiled via snap() on the MB circuit, a fuzzy-weight computation in KC space, and a linear blend of behavior vectors indexed by the program's prototype-to-behavior map. Query construction is q = bind(smell_vec, hunger_vec); brain_query = snap(q); weights w_i = relu(cos(brain_query, prototype_i)) normalized to sum to one; result = Σ w_i · behavior_vec[program_map[prototype_i]]; winner is argmax_j cos(result, behavior_vec_j). Program identity enters only at the prototype-to-behavior table; the substrate-side pipeline is program-independent. See fly-brain/fuzzy_conditional.py and fly-brain/scale_eval_conditional.py.
Sparsity. A single graded APL neuron integrates KC activity and feeds back continuous inhibitory current to all KCs, producing ~7.8% KC activation — within the 2–10% range observed in vivo (Lin et al. 2014). Sparsity emerges from the circuit dynamics, not from a hand-coded override.
Geometric loops. Per planning/sutra-spec/03-control-flow.md, loop (N) with a literal bound unrolls at compile time into a flat algebraic expression — no runtime iteration, no rotation needed. loop (condition) with data-dependent termination compiles to eigenrotation: there is no integer loop counter at runtime, and the "counter" is the angular position on the helix Q^i · v₀ traced through the substrate's state space. The rotation operator Q is the 140-D block-diagonal polar-decomposition nearest-orthogonal matrix to a real FlyWire v783 weight matrix (EPG→EPG recurrent in 51-D plus FB hDelta-subset recurrent in 89-D), and Q · v is realized as a Brian2 LIF rotation circuit whose synapse matrix is Q itself. The rotated state is presented to the real hemibrain PN→KC projection (140 → 1,882) with APL-enforced sparsity, and termination is decided by Jaccard overlap on KC patterns against a compiled prototype, threshold = 0.5 (measurement-justified, gap-probed). Both the rotation operator and the readout are real connectome wiring; no synthetic Givens, no random PN→KC mock, no host-side cosine readout — see §Honest Limits for the gap probe and the wrong-discriminator baselines we ruled out before adopting KC-Jaccard. The host sequences the iterations in a Python loop that presents the current rotated state to the circuit and checks the termination signal; the control-flow decision itself is made on the substrate. We flag this sequencing as a framing caveat: every step of the loop body runs on neurons, but the outer for-loop that threads sequential presentations together currently runs in host Python. A substrate-intrinsic trajectory (recurrent connectome dynamics sustaining Q^i · v₀ without host polling) is out of scope for this paper.
Reproducibility
All experiments run on commodity hardware (Windows 11, Python 3.13, Brian2 2.10.1) without GPU. The hemibrain connectivity matrix (0.1 MB) is committed to the source repository. The full validation suite (conditional branching across five hemibrain seeds + loop tests) executes in under 45 minutes on a single CPU core.
Honest Limits of the Current Substrate
The real-wiring loop pipeline passes the numeric tests; one compliance gap remains and is flagged here. The end-to-end pipeline in §Result 2 — 140-D real-FlyWire Q (polar decomposition of EPG→EPG recurrent in 51-D plus FB hDelta-subset recurrent in 89-D, block-diagonal), real hemibrain PN→KC (140 → 1,882) with APL-enforced sparsity, KC-Jaccard termination at threshold 0.5 — passes 5/5 counting to k=3, 5/5 ordering (EARLY first at k=2 given prototypes at k=2,5,8), and a 30/30 target-k sweep at k ∈ {1, 2, 3, 5, 8, 12} × 5 seeds, with every loop terminating at exactly n_iters == target_k and peak Jaccard at target = 1.000 out to k = 12 (fly-brain/real_rotation_140D_jaccard.py, real_rotation_140D_jaccard_ksweep.py; findings in planning/findings/2026-04-13-jaccard-140D-real-hemibrain.md and …-jaccard-target-k-sweep-30-of-30.md). The threshold is gap-probe-justified, not tuned: off-target iterates concentrate at Jaccard ≤ 0.373 and the target iterate sits at 1.000 — bimodal with order-of-magnitude separation, no overlap, threshold 0.5 cleanly separates. The rotation operator Q and the MB PN→KC readout are real FlyWire / hemibrain wiring. Compliance caveat — retraction of the earlier "no numpy Q@v" claim. In this 140-D pipeline the rotation application state ← Q^i · v₀ is host-side numpy.matmul (see vsa_operations.py:550, where R_power = rotation @ R_power; state = R_power @ initial_state). This violates the Substrate Rule in planning/sutra-spec/02-operations.md, which requires every vector operation (rotation included) to run on the substrate at runtime. The earlier version of this section described the split as "the spec-prescribed tier-2 / tier-3 split"; that framing is retired repo-wide and is retracted here. The numbers are honest measurements, but they come from a pipeline where rotation application runs on host numpy and KC+Jaccard runs on the substrate — not a substrate-only pipeline. STATUS.md queue item 1 tracks the fix (substrate-only rotation on top of the Jaccard readout). The earlier "the eigenrotation gap" framing of this paper was honest at v17 (Strong Reject, Gemini 3 Flash, 2026-04-12) but is no longer current as of 2026-04-13. We retain the wrong-discriminator baselines below not as "honest limits" but as the diagnostic record that explains why the current pipeline uses the operator and readout it does.
Why KC-Jaccard rather than cosine. The cosine readout's discrimination power scales as (‖signal‖ / ‖noise‖) ∝ 1/√D because Poisson decode noise is per-dimension i.i.d. and the signal at the target k is concentrated, not spread — this is why moving from 51-D to 713-D collapsed peak cos from ~0.7 to ~0.1 in the spiking-cosine baseline below. The MB readout converts the comparison into a sparse binary pattern overlap: APL-gated KC activity is ~5–10% sparse in a ~2000-D code, so a random off-target state and the target prototype have expected Jaccard ~0.05–0.10 (chance coincidence of two independent 5–10% masks), while a true match drives the same KC subset to fire and produces Jaccard near 1.0. The resulting distribution is bimodal with an order-of-magnitude gap, and Poisson spike noise has to cross the whole gap to flip the decision rather than just nudge a scalar. A 200 ms window suffices for Jaccard where 3000 ms wasn't enough for cosine: the readout is no longer integrating noise, it is checking pattern identity. This is the theoretical reason planning/sutra-spec/03-control-flow.md prescribes KC-Jaccard as the termination signal for loop (condition) — the mushroom body is specifically an anti-correlator, and the spec uses it as one. Independent confirmation: running the same Jaccard-on-KC loop at the 713-D composed-Q scale gives off-target Jaccard 0.049 (actually wider than the 0.237 gap at 51-D) because KC sparsity normalizes both modes against total KC count rather than substrate dimension (planning/findings/2026-04-13-jaccard-713D-dim-independence.md). The readout survives at D ∈ {51, 140, 713} without re-tuning, which directly addresses the "140-D is too narrow for VSA" concern — the mechanism does not depend on operating in the 140-D PN layer specifically.
Why polar-decomposition Q rather than the raw FlyWire W. Q is the nearest orthogonal matrix to the biological W in Frobenius norm, with Q^T Q = I to ~10⁻¹⁴ and det Q = +1 — but ‖W − Q‖_F / ‖W‖_F = 0.983, so the biological matrix is far from orthogonal even in the near-orthogonal motifs we selected. The honest framing is "rotation in the subspace spanned by the EPG (and hDelta) recurrent projections, derived via polar decomposition from the real FlyWire weights," not "the biology is a rotation." This is the deeper point for downstream deployment: Sutra must compile within the eigenstructure the substrate's connectome provides; the rotation operator is fixed by anatomy, not chosen by the programmer. We surveyed eleven FlyWire v783 motifs (fly-brain/survey_rotation_candidates.py) and selected the central-complex EPG→EPG recurrent (51 neurons, effective rank 49, off-diagonal fraction 0.508 — an order of magnitude closer to orthogonal than the ALPN→LHLN feedforward projection we first tried) plus the FB hDelta-subset (types J+K+A+D+E, 89 neurons total) for the second 89-D block. That the orthogonality-friendly motif lives in the central complex — anatomically the fly's orientation-tracking ring attractor — is the right biological story for "where rotation lives in this brain."
Wrong-discriminator baselines (retained for the diagnostic record). Three earlier configurations failed in informative ways and shaped the choice of the current pipeline:
- Real ALPN→LHLN feedforward projection as the rotation operator. A 685-ALPN → 517-LHLN feedforward projection (weights = syn_count × NT-sign) simulates its own linear map faithfully (cos=0.94 vs. numpy
W·vreference) but the matrix is rank 415, condition number ~10¹⁶, column-orthonormality RMS off-diagonal 0.059. It is a compressive non-orthogonal projection, consistent with olfactory biology. This is what motivated the survey for near-orthogonal motifs and the polar decomposition step. - Spiking
rotate(v, Q)with cosine readout. IteratingQas a Brian2 LIF circuit (51×51 synapse pattern, Poisson rate-coded state, steady-state membrane decode) at SIM_MS = 3000 ms per step hits 3/5 seeds at targetk=3(fly-brain/real_rotation_epg_loop_spiking.py). Failures occur becausecos(Qv, Q³v) = cos(v, Q²v)by orthogonality, and for the EPG recurrentQthat quantity is numerically close to 1 on some seeds (a signature of the biological ring-attractor spectrum, whose eigenvalue phases cluster around a small number of rotation angles); Poisson spike noise then flips argmax across the narrow gap. Full analysis inplanning/findings/2026-04-13-spiking-Q-rotation-3-of-5.md. This is what motivated routing termination through KC-Jaccard rather than a direct cosine on the rotated state. - Numpy iteration of the real-wiring
Q(no spiking). In pure numpy, iterating the real-wiringQpasses the full counting/ordering suite — 10/10 counting (k=3 and k=6 × 5 seeds, peak cos = 1.000) and 5/5 ordering (fly-brain/real_rotation_epg_loop.py). Block-diagonally composingQfrom four near-orthogonal FlyWire motifs — CX EPG→EPG (51-D), LH→LH (116-D), FB vDelta→vDelta (357-D), FB hDelta→hDelta (189-D) — scales to 713-D with orthogonality residual 5.34×10⁻¹⁴ and passes the same suite at every cumulative composition stage (fly-brain/real_rotation_composed.py). This established that the operator scales cleanly; the remaining engineering was the spiking + readout pipeline that became the §Result 2 result.
Scope of "runs on the connectome." This paper is a computational model, not a physical deployment. We use the real hemibrain wiring as the substrate graph and simulate it in Brian2; we do not claim to have executed anything on living tissue or a neuromorphic chip. Physical deployment — stimulating real neurons at prescribed sites (e.g., via an optogenetic or Neuralink-style interface) to drive program state, and reading state back out — is substantially harder engineering work and is out of scope here. Nothing in this paper should be read as a claim about in-vivo execution. The value of the present result is that the programming model survives contact with a real connectome graph at all; the hardware bridge is separate future work.
Scope of the eigenrotation limitation. Sutra's loop (N) with a literal bound unrolls at compile time into a flat algebraic expression (planning/sutra-spec/03-control-flow.md) — no runtime iteration, no eigenrotation required. Eigenrotation is invoked only for loop (condition) with data-dependent termination. The real-wiring rotation gap above therefore affects indefinite-termination loops, not the common case of bounded iteration; the majority of the Sutra surface (conditionals, fuzzy defuzzification, bundle, bind, snap, bounded loops) is unaffected.
Other concrete limits. The 140-PN input layer is narrow by VSA standards (typical VSA operates at 1k–10k dimensions); the planned KC-space promotion (1,882-D) would widen the operating space by an order of magnitude. Both the conditional and loop evaluations are scaled to 5 independent hemibrain seeds (80/80 and 20/20 respectively, σ=0 on both); larger trial counts are straightforward — the harnesses take --n-runs. The MBON readout uses ridge regression; replacing it with a dopamine-gated plasticity rule is planned and does not affect the substrate-level claims. A prior implementation of conditional branching used a sign-flip "NOT key" applied to the query as a proxy for semantic negation; this was a category error (a random ±1 pattern has no principled relationship to the other polarity of a feature axis) and is superseded by the spec-aligned fuzzy-weighted-superposition form reported here. The failure record is retained on disk at fly-brain/permutation_conditional.py with a deprecation banner.
The Sutra language surface, operation model, and compiler are specified in planning/sutra-spec/ (canonical files: 02-operations.md, 03-control-flow.md, 11-vsa-math.md) and implemented in sdk/sutra-compiler/; the .su programs cited here compile through that pipeline to the fly-brain runtime — it is not an ad-hoc DSL built for this paper.
Future Work
- FlyWire scale. The Princeton FlyWire connectome (~140,000 neurons) would increase memory capacity from ~300 to ~10,000–15,000 prototypes.
- KC-space promotion. Moving all operations into the 1,882-D KC space (where binding achieves perfect decorrelation) rather than the 140-D PN I/O layer.
- Biological learning rule. Replacing ridge regression with dopamine-gated plasticity for the MBON readout.
- Real-wiring rotation, end-to-end. Closed. Rotation operator is polar decomposition of real FlyWire EPG + hDelta-subset wiring (140-D); readout is real hemibrain PN→KC with APL sparsification; termination is KC-Jaccard against a compiled prototype. Counting and ordering pass 5/5 + 5/5, and a target-k sweep at k ∈ {1, 2, 3, 5, 8, 12} × 5 seeds passes 30/30 (§Honest Limits (iv);
real_rotation_140D_jaccard.py,real_rotation_140D_jaccard_ksweep.py). What remains is physical deployment — stimulating real neurons at prescribed sites rather than simulating them in Brian2 — which is out of scope for this paper.
Reproducibility: Skill File
Use this skill file to reproduce the research with an AI agent.
---
name: sutra-fly-brain
description: Compile and run Sutra programs on a simulated Drosophila mushroom body. Reproduces the result from "Running Sutra on the Drosophila Hemibrain Connectome" — 4 program variants × 4 inputs = 16/16 decisions correct on a Brian2 spiking LIF model of the mushroom body (50 PNs → 2000 KCs → 1 APL → 20 MBONs), via the AST → FlyBrainVSA codegen pipeline.
allowed-tools: Bash(python *), Bash(pip *)
---
# Running Sutra on the Drosophila Hemibrain Connectome
**Author: Emma Leonhart**
This skill reproduces the results from *"Running Sutra on the Drosophila Hemibrain Connectome: Methodology and Results"* — the first known demonstration of a programming language whose conditional semantics compile mechanically onto a connectome-derived spiking substrate. The target substrate is a Brian2 leaky-integrate-and-fire simulation of the *Drosophila melanogaster* mushroom body: 50 projection neurons → 2000 Kenyon cells → 1 anterior paired lateral neuron → 20 mushroom body output neurons, with APL-enforced 5% KC sparsity.
**Source:** `fly-brain/` (runtime), `fly-brain-paper/` (this paper), `sdk/sutra-compiler/` (the reference compiler used for codegen).
## What this reproduces
1. **A four-state conditional program compiles end-to-end to the mushroom body.** `fly-brain/permutation_conditional.su` is parsed and validated by the same Sutra compiler used for the silicon experiments, mechanically translated by a substrate-specific backend (`sdk/sutra-compiler/sutra_compiler/codegen_flybrain.py`) into Python calls against the spiking circuit, then executed.
2. **Four program variants × four input conditions = sixteen decisions, all correct.** Each variant differs only by which permutation keys multiply into the query before `snap` runs through the mushroom body — the compiled prototype table is identical across variants. The four variants yield four *distinct* permutations of the underlying behavior mapping (`approach`, `ignore`, `search`, `idle`).
3. **The fixed-frame runtime invariant.** Every `snap` call in one program execution must share the same PN → KC connectivity matrix, or prototype matching is meaningless. Measured numbers: ~0.53 cosine per-snap fidelity under rolling frames vs. 1.0 under fixed frame; 4-way discrimination requires the fixed frame.
## Prerequisites
```bash
pip install brian2 numpy scipy
```
No GPU required. Full reproduction runs in under two minutes on commodity hardware.
## One-command reproduction
```bash
python fly-brain/test_codegen_e2e.py
```
This script does the full end-to-end pipeline in one file:
1. Parses `fly-brain/permutation_conditional.su` with the Sutra SDK
2. Runs the AST → FlyBrainVSA translator (`codegen_flybrain.translate_module`)
3. `exec()`s the generated Python in a private module namespace so the compile-time `snap()` calls fire on a live mushroom body
4. Calls `program_A`, `program_B`, `program_C`, `program_D` on the four `(smell, hunger)` inputs
5. Compares results against the expected behavior table from `fly-brain-paper/paper.md`
Expected output:
```
Decisions matching expected: 16/16
Distinct program mappings: 4/4
GATE: PASS
```
## Per-demo reproduction
Use the e2e test wrapper. Prior standalone demos (`four_state_conditional.py`, `programmer_control_demo.py`, `permutation_conditional.py`) were removed as superseded during the 2026-04-13 fly-brain sprawl cleanup — the `test_codegen_e2e*` files cover the same pipeline end-to-end from `.su` source through codegen to the live MB simulation.
```bash
python sdk/sutra-compiler/test_codegen_e2e.py
python sdk/sutra-compiler/test_codegen_e2e_fuzzy.py
```
## What you should see
- **`test_codegen_e2e_fuzzy.py`**: compiles `fly-brain/fuzzy_conditional.su` through the pipeline and runs the resulting program against the live MB simulation. 16/16 pass across 4 program variants × 4 input conditions, with four distinct behavior mappings emerging from one-character `!` edits at the source level. This is the combined "programmer agency + compile-to-brain" result.
## Generating the compiled Python from the `.su` source
If you want to watch the codegen step directly:
```bash
cd sdk/sutra-compiler
python -m sutra_compiler --emit-flybrain ../../fly-brain/permutation_conditional.su > /tmp/generated.py
```
The resulting `/tmp/generated.py` is a 93-line Python module targeting `FlyBrainVSA` that you can import and run against the same mushroom-body circuit.
## Dependencies between files
- **`fly-brain/mushroom_body_model.py`** — the Brian2 circuit: PN group, KC group, APL inhibition, MBON readout, synaptic connectivity with 7-PN fan-in per KC
- **`fly-brain/spike_vsa_bridge.py`** — encode hypervectors as PN input currents, decode KC population activity back to hypervectors via pseudoinverse
- **`fly-brain/vsa_operations.py`** — `FlyBrainVSA` class exposing the Sutra VSA primitives (`bind`, `unbind`, `bundle`, `snap`, `similarity`, `permute`, `make_permutation_key`)
- **`fly-brain/permutation_conditional.{ak,py}`** — the compile-to-brain demo program (source + hand-written reference form)
- **`fly-brain/test_codegen_e2e.py`** — end-to-end parse-to-brain test
- **`sdk/sutra-compiler/sutra_compiler/codegen_flybrain.py`** — the `.su` → `FlyBrainVSA`-targeted Python translator
## Limitations stated honestly in the paper
- **50-dim hypervectors** limit bundling capacity. Biological mushroom bodies use ~2000-dim (KC count), not 50 (PN count). Scaling up the input dimensionality to match KC count would help materially.
- **Loops are intentionally unsupported** by the V1 codegen. A `while` compilation path probably needs recurrent KC → KC connections that the current circuit doesn't have. See `fly-brain/STATUS.md` §Loops for why this is framed as a research question rather than a codegen bug.
- **Non-permutation boolean composition** (`&&`, `||`) has no known VSA-to-substrate compilation scheme yet. Source-level `!` compiles cleanly because sign-flip permutation keys are involutive and distribute over `bind`; general boolean operations don't have that structure.
- **Bind / unbind / bundle run in numpy**, not on the mushroom body. The MB has no natural analogue for sign-flip multiplication — only `snap` executes on the biological substrate. The hybrid design reflects this honestly.
## Reading order for the paper
1. `fly-brain-paper/paper.md` — the paper itself (this SKILL's subject)
2. `fly-brain/STATUS.md` — honest running status, technical insights (fixed-frame invariant, negation-as-permutation, MB-as-VSA-substrate caveats)
3. `fly-brain/DEMO.md` — audience-facing summary of the programmer-agency result
4. `fly-brain/DOOM.md` — gap analysis writeup: "how far are we from playing Doom on this?"
Discussion (0)
to join the discussion.
No comments yet. Be the first to discuss this paper.