elegans 1.0.0

C. elegans nervous system — 302 undifferentiated neurons develop into a functional worm brain through imaginal disc developmental phases
Documentation
# Elegans Hand-Off — 2026-02-07


## Where We Are


### The Worm Lives

302 undifferentiated neurons scatter in 3D space, wire by proximity, and
develop through four phases (Genesis, Exposure, Differentiation,
Crystallization). Fiber tracts connect brain to body. The body has 10
segments with 4 muscles each, touch sensors, proprioception, and
chemosensory head. **49/49 tests pass.**

### Key Numbers (current run)

| Metric | Value |
|--------|-------|
| Body displacement during development | **90.99** (was 0.000) |
| Touch withdrawal displacement | **9.93** (was 0.000) |
| Motor frames with signal | **200/200** (was 0/200) |
| Peak muscle activation | **0.62** |
| Total spikes | **135,560** (was 117) |
| Role distribution | 193 sensory, 52 motor, 57 inter |
| Food distance | 20.0 -> 91.5 (moving AWAY) |
| Head angle variance | 0.000 (no steering) |
| Test suite time | ~365 seconds |

### What Works

- Imaginal disc differentiation (302/302 neurons commit)
- Fiber tract adaptation (myelination, sensitization emerge from use)
- Tonic receptor mode (body wall, proprioception, chemosensory)
- Sensory -> brain -> motor signal flow (complete loop)
- Body physics (traveling wave = 2.8 units displacement)
- Touch withdrawal response (9.93 units)

### What Doesn't Work

- **Chemotaxis**: worm moves away from food, not toward it
- **Steering**: motor output is uniform (d=0.62, v=0.62, l=0.62, r=0.62), no asymmetry
- **Locomotion pattern**: no traveling wave, just uniform thrust
- **Role balance**: 64% sensory is pathological (real C. elegans: 26%)

---

## Why It's So CPU Heavy (The Seizure)


The brain is seizing. Here's the math:

- 193/302 neurons are sensory (64% of the brain)
- Tonic input floods ALL sensory neurons EVERY frame
- Most sensory neurons fire -> propagate to interneurons -> propagate to motor
- **75 spikes per frame**, 25% firing rate
- Healthy cortical firing rate: 1-5% per time window
- Each spike generates ~12 synaptic events = **900 cascade events/frame**
- Over 1800 development frames = **1.6M cascade events**

The brain has no sparsity. Every neuron fires every frame. The cascade
does maximum work because there's no inhibitory structure creating quiet
periods. This is the computational equivalent of a tonic-clonic seizure.

**Fix**: This is the same problem as the metabolism problem. A metabolic
budget naturally creates sparsity pressure — neurons that fire too much
deplete energy and must rest. The role balance (too many sensory) also
contributes: with 64% of neurons receiving direct input, the processing
population is too small to create structured patterns.

---

## Next Steps: Metabolism


### The Problem

The worm has no internal state. Moving costs nothing. Food proximity
gives nothing. There's no interoceptive signal distinguishing "thriving"
from "starving." Mastery learning strengthens whatever fires together,
equally — there's no selection pressure for beneficial vs harmful
behavior.

### The Biological Mechanism

Real C. elegans doesn't "know" what food is. It uses a **biased random
walk**: concentration increasing -> extend forward run, concentration
decreasing -> trigger omega turn. The bias comes from internal state
modulating motor patterns.

### Implementation: Metabolic Body State


Add to `WormBody`:

```rust
pub struct MetabolicState {
    /// Energy level (0.0 = dead, 1.0 = full). Starts at 0.5.
    pub energy: f32,
    /// Basal metabolic drain per tick (living costs energy).
    pub basal_rate: f32,
    /// Movement cost per tick (proportional to muscle activation).
    pub movement_cost_rate: f32,
    /// Feeding rate when near food (proportional to concentration).
    pub feeding_rate: f32,
    /// Distress signal (0.0 = fine, 1.0 = starving). Derived from energy.
    pub distress: f32,
}
```

**Each tick:**
1. `energy -= basal_rate` (existing costs energy)
2. `energy -= movement_cost_rate * total_muscle_activation` (moving costs more)
3. `energy += feeding_rate * food_concentration_at_head` (food restores energy)
4. `distress = (1.0 - energy).max(0.0)` (low energy = high distress)
5. Clamp energy to [0.0, 1.0]

**Emit through interoceptive tract:**
The distress signal goes through the existing Interoceptive fiber tract
on the head bundle (already exists). High distress = strong interoceptive
signal reaching the brain. Low distress (near food, fed) = weak signal.

This creates the asymmetry mastery learning needs:
- Moving toward food -> energy increases -> distress drops -> neural
  activity pattern changes -> mastery learning captures this
- Moving away -> energy decreases -> distress rises -> different
  activity pattern -> mastery weakens those synapses

No hand of god. The brain discovers that certain motor patterns correlate
with reduced distress. Same mechanism as any organism.

### Food vs Objects


Currently the chemosensory system reports gradient direction as i32
values. This already distinguishes food from obstacles:

- **Chemosensory** (Interoceptive tract, head): [left_gradient,
  right_gradient, dorsal_gradient, concentration]. These are ONLY
  generated by the food source. Obstacles don't emit them.
- **Touch** (Mechanoreceptive tracts, per-segment): [dorsal, ventral,
  left, right]. These are ONLY triggered by obstacle proximity and
  ground contact. Food doesn't trigger them.

The labeled-line principle already separates them. The brain receives
chemosensory and touch on DIFFERENT tracts going to DIFFERENT spatial
anchors activating DIFFERENT neurons. The worm doesn't need to
"distinguish" food from objects — they arrive on different neural
channels by construction.

What's missing is the MOTIVATION to approach the chemical gradient.
That's the metabolism. The gradient tells the worm WHERE; the metabolism
tells it WHY.

---

## Next Steps: Fixing the Seizure (Role Balance)


The 64% sensory ratio is caused by disc competition dynamics. Sensory
discs win because:
1. Sensory channels are active during development (tonic input)
2. Motor channels start inactive (chicken-and-egg before adaptation)
3. Activity correlation pressure overwhelmingly favors sensory discs

**Potential fixes (in order of biological plausibility):**

1. **Metabolic pressure on sensory neurons**: Neurons receiving constant
   input deplete energy faster. Some naturally quiet down or fail to
   differentiate, leaving room for motor/interneuron commitment.

2. **Disc saturation**: Once enough sensory neurons exist for a given
   channel, additional neurons near that anchor face diminishing
   pressure. "The niche is full."

3. **Inhibitory differentiation**: Some neurons should become inhibitory
   interneurons that suppress the excitatory avalanche. Currently all
   undifferentiated neurons are excitatory (pyramidal). A disc program
   for inhibitory interneurons would create the missing GABAergic
   population.

---

## Commit State


- **elegans-rs**: main branch, 49/49 tests pass
- **fibertract-rs**: main branch, 34/34 + 1 doctest pass
- **neuropool-rs**: v1 branch, unchanged this session

### Files Modified This Session


**fibertract-rs:**
- `tract.rs``input_density` field, `update_input_density()`, tracking in transmit methods
- `adapt.rs` — input-driven myelination + sensitization, `sensitization_rate`/`desensitization_rate`

**elegans-rs:**
- `coupling.rs` — removed all hardcoded overrides, added `adapt()` method, `AdaptationConfig`
- `sim.rs` — added `coupling.adapt()` in tick loop
- `test.rs` — two diagnostic probe tests (efferent + physics traveling wave)