---
include_toc: true
---

# Tripartite Synapse — Pseudocode v7

## Part 1 — Conventions

```
SCOPE    = { DAY, NIGHT }
CONTEXT  = { AP, NOT_AP, bAP, NOT_bAP, CONTINUOUS }

DAY variable types:
  BUDGET    = combined fast energy + fast consumable materials
              one variable per component
              replenished in NOT contexts (received from upstream)
              consumed in AP/bAP/CONTINUOUS contexts (execution behaviors)

NIGHT variable types:
  ENERGY    = ATP for structural assembly — NOT recoverable after LTD
  MATERIAL  = slow structural proteins — RECOVERABLE after LTD

  STRUCTURE = slow architectural ceiling
              READ in DAY, WRITTEN only in NIGHT

  FAST_TRACE, TAG = as before
```

---

## Part 2 — Fixed Parameters

```
// Thresholds — all FIXED
FIXED  Ca_TAG_threshold         // Ca²⁺ sufficient to set POST CANDIDATE
FIXED  Ca_HIGH                  // LTP-driving Ca²⁺ amplitude
FIXED  Ca_LOW                   // LTD-driving Ca²⁺ amplitude
FIXED  spillover_threshold      // cleft saturation for mGluR activation
FIXED  eligibility_threshold    // minimum fast_trace for tagging eligibility
FIXED  dopamine_threshold       // minimum dopamine for tag stabilization
FIXED  tagging_threshold        // minimum possible_tagging for tag accumulation
FIXED  tag_expiry_threshold     // minimum tag strength to survive to NIGHT
FIXED  homeostatic_ceiling      // max soma firing before global downscale
FIXED  structural_decay_rate    // passive decay rate of all structures per NIGHT
FIXED  recycling_fraction       // fraction of material recovered after LTD

// Organism-level signals — FIXED (externally driven)
FIXED  dopamine_level           // VTA broadcast — reward/save signal
FIXED  NE_level                 // locus coeruleus — arousal/gain
FIXED  ACh_level                // basal forebrain — attention/threshold

// Physical constraints — FIXED
FIXED  vascular_glucose_supply  // hard energy ceiling — astrocyte root
FIXED  branch_geometry          // dendritic topology — bAP decay profile
FIXED  Ca_cooperativity_n       // Hill coefficient for Ca²⁺-driven NT release
FIXED  Ca_half_max_K            // half-maximal Ca²⁺ for NT release
```

---

## Part 3 — Budget, Energy, Material Declarations

```
// ── DAY BUDGETS: one per component ────────────────────────────────────
// Replenished in NOT contexts. Consumed in execution contexts.

VAR astro_budget
    // SOURCE:  vascular_glucose_supply → glycolysis (ROOT — self-produced)
    // COVERS:  EAAT clearance ATP
    //          D-serine synthesis (serine racemase ATP + serine precursor)
    //          lactate production and export
    //          fast process motility
    // REPLENISHED: CONTINUOUS context (self-produced continuously)

VAR pre_budget
    // SOURCE:  astro_lactate × pre_fraction (primary)
    //          axon→pre shipment in AXON NOT_AP (secondary)
    // COVERS:  VGCC opening + vesicle fusion + VATPase refill
    //          fast vesicle membrane lipid turnover
    //          synaptotagmin recycling
    // REPLENISHED: PRE NOT_AP context (receives from AXON)

VAR post_budget
    // SOURCE:  astro_lactate × post_fraction (primary)
    //          dend→post shipment in DEND NOT_bAP (secondary)
    // COVERS:  NaK pump reset + NMDA current handling
    //          AMPA lateral diffusion + rapid recycling
    //          actin monomers for transient spine changes
    //          PKA phosphorylation (minor)
    // REPLENISHED: POST NOT_bAP context (receives from DEND)

VAR dend_budget
    // SOURCE:  astro_lactate × dend_fraction (primary)
    //          soma→dend shipment in SOMA NOT_AP (secondary)
    // COVERS:  bAP propagation along branch (NaK reset at each segment)
    //          local mRNA translation (ribosome running cost)
    //          fast Ca²⁺ handling (SERCA pump)
    //          fast mRNA consumables for local translation
    // REPLENISHED: DEND NOT_bAP context (receives from SOMA)

VAR soma_budget
    // SOURCE:  own mitochondria (self-produced — independent of astrocyte)
    // COVERS:  AP generation (Na⁺/K⁺ currents + NaK reset)
    //          CREB phosphorylation (minor fast cost)
    //          nuclear Ca²⁺ handling
    //          shipping costs to DEND and AXON
    // REPLENISHED: SOMA NOT_AP context (self-replenished from mitochondria)

VAR axon_budget
    // SOURCE:  soma→axon shipment in SOMA NOT_AP (primary)
    //          astro_lactate × axon_fraction along shaft (secondary)
    // COVERS:  AP propagation at nodes of Ranvier (NaK reset)
    //          kinesin/dynein motor running cost
    //          fast myelin maintenance
    // REPLENISHED: AXON NOT_AP context (receives from SOMA)

VAR astro_lactate
    // Fuel exported by astrocyte → all neuronal components
    // = min(glycolysis(vascular_glucose_supply), astro_budget × export_fraction)
    // Distributed continuously in ASTRO CONTINUOUS context

// ── NIGHT ENERGY: ATP for structural assembly — NOT recoverable ────────

VAR astro_energy    // process retraction + ECM secretion + racemase upregulation
VAR pre_energy      // AZ scaffold incorporation + VGCC clustering
VAR post_energy     // CaMKII anchoring + actin polymerization + PSD remodeling
VAR dend_energy     // mitochondria incorporation + cytoskeletal reinforcement
VAR soma_energy     // ribosome biogenesis + ion channel incorporation
VAR axon_energy     // myelination + microtubule stabilization

// ── NIGHT MATERIAL: slow structural proteins — RECOVERABLE after LTD ──

VAR astro_material  // EAAT proteins + racemase enzyme + ECM proteins
                    // + process cytoskeleton
                    // SOURCE: astrocyte cell body synthesis (overnight)
                    // RECOVERY: partially after LTD (recycling_fraction)

VAR pre_material    // RIM + Munc13 + VGCC subunits + structural vesicle proteins
                    // SOURCE: soma_material → axon_material → pre_material
                    // RECOVERY: significantly after LTD → axonal pool

VAR post_material   // AMPA subunits + PSD scaffold + structural actin + CaMKII
                    // SOURCE: soma_material → dend_material → post_material
                    // RECOVERY: significantly after LTD → dendritic reserve

VAR dend_material   // Arc mRNA + plasticity mRNAs + mitochondria
                    // + cytoskeletal proteins + AMPA in transit
                    // SOURCE: soma_material → dend_material
                    // RECOVERY: partially after branch pruning

VAR soma_material   // ALL structural proteins for downstream components
                    // SOURCE: CREB-driven synthesis (peaks in NIGHT, soma_tag driven)
                    // DISTRIBUTES TO: dend_material + axon_material → pre_material

VAR axon_material   // motor proteins + microtubule components + myelin proteins
                    // SOURCE: soma_material → axon_material
                    // RECOVERY: partially after axon structural reduction
```

---

## Part 4 — Structural Variables (NIGHT only)

```
VAR pre_structure   // RRP_capacity + VGCC_coupling + refill_ceiling
VAR post_structure  // anchoring_slots + spine_volume + local_reserve_ceiling
VAR dend_structure  // bAP_fidelity(position) + translation_ceiling + transport_speed
VAR soma_structure  // baseline_threshold + AP_reliability + synthesis_ceiling
VAR axon_structure  // propagation_reliability + transport_rate_ceiling
VAR astro_structure // perisynaptic_distance⁻¹ + EAAT_density
                    // + D_serine_tonic + ECM_integrity
                    // SELF-REINFORCING in both directions
```

---

## Part 5 — Trace Variables

```
// Fast traces (DAY only, decay automatically)
FAST_TRACE  pre_fast_trace      // residual Ca²⁺ — τ ≈ 100ms
FAST_TRACE  post_fast_trace     // spine Ca²⁺ × rise_speed — τ ≈ tens of ms
FAST_TRACE  dend_fast_trace     // branch Ca²⁺ integration — τ ≈ 300ms
FAST_TRACE  soma_fast_trace     // nuclear Ca²⁺ — τ ≈ seconds
FAST_TRACE  axon_fast_trace     // AP propagation load — τ ≈ seconds
FAST_TRACE  astro_fast_trace    // perisynaptic Ca²⁺ from mGluR5 — τ ≈ seconds

// Possible tagging (intermediate — τ ≈ seconds to minutes)
VAR  pre_possible_tagging
VAR  post_possible_tagging      // POST: CANDIDATE lifetime
VAR  dend_possible_tagging
VAR  soma_possible_tagging
VAR  axon_possible_tagging
VAR  astro_possible_tagging

// Tags (slow, DAY→NIGHT bridge — τ ≈ hours)
TAG  pre_tag
TAG  post_tag                   // POST only: CANDIDATE→STABLE before NIGHT
TAG  dend_tag
TAG  soma_tag
TAG  axon_tag
TAG  astro_tag
```

---
---

# SCOPE: DAY
Execution contexts (AP, bAP, CONTINUOUS): behaviors run, budgets consumed, traces deposited
Replenishment contexts (NOT_AP, NOT_bAP): budgets replenished, traces decay, shipments received

---

## PRE

### CONTEXT: AP
```
scope DAY | context AP:

    // Budget gate — behavior requires resources
    if pre_budget < AP_release_cost:
        suppress(NT_flux)
        exit context

    // Fast trace: residual Ca²⁺ deposited
    pre_fast_trace += spike_Ca_influx(input_freq)
    pre_fast_trace *= decay(τ = 100ms)
    pre_budget     -= Ca_handling_cost
    // cost covers: PMCA + NCX pump ATP to remove Ca²⁺

    // NT flux: Hill function Ca²⁺ drive × RRP level
    Ca_drive    = pre_fast_trace^Ca_cooperativity_n /
                  (Ca_half_max_K^Ca_cooperativity_n + pre_fast_trace^Ca_cooperativity_n)

    if RRP_level > 0:
        NT_flux    = RRP_level × Ca_drive
        glutamate += NT_flux × Δt               // cleft concentration rises
        RRP_level -= NT_flux × Δt               // pool depletes
        pre_budget -= NT_flux × fusion_cost
        // cost covers: SNARE_ATP + fast_membrane_lipid_turnover

    // RRP refill — rate limited by pre_budget + pre_structure (READ)
    RRP_refill  = min(refill_rate_constant, pre_structure.refill_ceiling)
    RRP_level  += RRP_refill × Δt
    RRP_level   = clamp(RRP_level, 0, pre_structure.RRP_capacity)
    pre_budget -= RRP_refill × VATPase_cost
    // cost covers: VATPase refilling vesicles with NT

    // Overflow brake: mGluR2/3 Gi — cross-compartment, no pre_budget cost
    if glutamate > spillover_threshold:
        Ca_drive *= mGluR_brake_factor
```

### CONTEXT: NOT_AP
```
scope DAY | context NOT_AP:

    // Fast trace decays — eligibility window closing
    pre_fast_trace *= decay(τ = 100ms)

    // RRP refills during silence — STP recovery
    RRP_refill  = min(refill_rate_constant, pre_structure.refill_ceiling)
    RRP_level  += RRP_refill × Δt
    RRP_level   = clamp(RRP_level, 0, pre_structure.RRP_capacity)
    pre_budget -= RRP_refill × VATPase_cost

    // Budget replenishment — received from AXON shipment
    // (axon ships to pre in AXON NOT_AP context — see below)
    // astro_lactate also delivered here as top-up
    pre_budget += astro_lactate × pre_fraction
    // Note: astro_lactate is the primary continuous supply
    //       axon shipment provides the structural protein transport channel

    // Possible tagging: graded accumulation while eligible
    if pre_fast_trace > eligibility_threshold:
        pre_possible_tagging += pre_fast_trace
    pre_possible_tagging *= decay(τ = seconds)

    // Dopamine decays locally
    dopamine_local *= decay(τ = hundreds_of_ms)

    // Tag: local eligibility AND global validation coincide
    if dopamine_local > dopamine_threshold and
       pre_possible_tagging > tagging_threshold:
        pre_tag += dopamine_local × pre_possible_tagging
    pre_tag *= decay(τ = hours)
```

---

## POST

### CONTEXT: NOT_bAP
```
scope DAY | context NOT_bAP:

    // Budget replenishment — received from DEND shipment
    // (dend ships to post in DEND NOT_bAP context — see below)
    // astro_lactate also delivered as top-up
    post_budget += astro_lactate × post_fraction
    post_budget += dend_shipment_to_post    // received from DEND NOT_bAP

    // AMPA current — occupancy of existing slots, gated by post_structure (READ)
    AMPA_current    = glutamate × post_structure.sensitivity
    Vm             += AMPA_current
    post_budget    -= AMPA_current_cost
    // cost covers: NaK_reset_ATP + fast_receptor_recycling_lipids

    // NMDA gate: depolarization + D-serine + glutamate — three-way coincidence
    if Vm > Mg_eject_threshold and
       astro_D_serine > D_serine_threshold:
        Ca_influx        = NMDA_Ca_influx(glutamate)
        post_fast_trace += Ca_influx × rise_speed(Ca_influx)
        post_budget     -= NMDA_current_cost
        // cost covers: NMDA_handling_ATP + fast_actin_transient_cost

    // Fast trace decays
    post_fast_trace *= decay(τ = tens_of_ms)

    // CANDIDATE tag: Ca²⁺ above threshold — Hebbian anticipation window
    if post_fast_trace > Ca_TAG_threshold:
        post_possible_tagging += post_fast_trace
    post_possible_tagging *= decay(τ = minutes)
    post_budget -= PKA_priming_cost
    // cost covers: PKA phosphorylation of GluA1-Ser845 (minor)

    // Dopamine decays
    dopamine_local *= decay(τ = hundreds_of_ms)

    // STABLE tag: CANDIDATE + dopamine within stabilization window
    if dopamine_local > dopamine_threshold and
       post_possible_tagging > tagging_threshold:
        post_tag += dopamine_local × post_possible_tagging
    post_tag *= decay(τ = hours)
```

### CONTEXT: bAP
```
scope DAY | context bAP:

    // bAP arrives — strength set by dend_structure.bAP_fidelity (READ)
    Vm          += bAP_depolarization × dend_structure.bAP_fidelity
    post_budget -= bAP_reset_cost
    // cost covers: NaK_reset_ATP for bAP-driven depolarization at spine

    // Coincidence confirmation: bAP finds CANDIDATE already set
    if post_possible_tagging > Ca_TAG_threshold:
        post_fast_trace += bAP_Ca_boost()
        // supralinear Ca²⁺ summation — trace amplified above Ca_HIGH
        // no extra budget cost — Ca²⁺ boost driven by voltage, not pumps
```

---

## DEND

### CONTEXT: bAP
```
scope DAY | context bAP:

    // bAP propagates from soma downward through branch
    // strength attenuates with distance — set by dend_structure (READ)
    bAP_local    = propagate_bAP(SOMA.AP_fired,
                                 dend_structure.bAP_fidelity,
                                 branch_geometry)
    dend_budget -= bAP_propagation_cost
    // cost covers: NaK_reset_ATP at each branch segment
    //              Na⁺ channel re-activation along branch length

    // Fast trace: branch Ca²⁺ from bAP
    dend_fast_trace += bAP_Ca_influx(bAP_local)
    dend_fast_trace += spine_Ca_spillover(active_spines)
    dend_fast_trace *= decay(τ = 300ms)
    dend_budget     -= branch_Ca_handling_cost
    // cost covers: SERCA pump re-sequestration of Ca²⁺

    // Integrate spine signals upward toward soma
    branch_Vm    = integrate(POST.Vm, all_spines_on_branch)
    dend_budget -= integration_cost
    // cost covers: passive membrane maintenance during integration
```

### CONTEXT: NOT_bAP
```
scope DAY | context NOT_bAP:

    // Fast trace decays
    dend_fast_trace *= decay(τ = 300ms)

    // Budget replenishment — received from SOMA shipment
    dend_budget += soma_shipment_to_dend    // received from SOMA NOT_AP
    dend_budget += astro_lactate × dend_fraction  // astrocyte top-up

    // Ship budget to POST spines — downstream replenishment
    dend_shipment_to_post = min(dend_budget × post_delivery_fraction,
                                post_demand(active_spines))
    post_budget  += dend_shipment_to_post
    dend_budget  -= dend_shipment_to_post
    // Note: this is fast operational budget (energy + consumables)
    //       structural post_material ships in NIGHT, not here

    // Possible tagging
    if dend_fast_trace > eligibility_threshold:
        dend_possible_tagging += dend_fast_trace
    dend_possible_tagging *= decay(τ = seconds)

    // Dopamine decays
    dopamine_local *= decay(τ = hundreds_of_ms)

    // Tag
    if dopamine_local > dopamine_threshold and
       dend_possible_tagging > tagging_threshold:
        dend_tag += dopamine_local × dend_possible_tagging
    dend_tag *= decay(τ = hours)

    // Local translation: activated when tag set, gated by dend_budget
    if dend_tag > tag_expiry_threshold and dend_budget > translation_cost:
        local_proteins = translate(dend_fast_trace)
        dend_budget   -= translation_cost
        // cost covers: ribosome_running_ATP + fast_mRNA_consumed
        // Note: uses fast mRNA pool (in dend_budget)
        //       slow structural mRNA pool (dend_material) consumed only in NIGHT

    // ACh modulates commit threshold globally
    commit_threshold *= (1 / (1 + ACh_level × ACh_gain))
```

---

## SOMA

### CONTEXT: AP
```
scope DAY | context AP:

    // Firing threshold: structure (READ) × adaptation × neuromodulators × refractory
    AP_threshold = soma_structure.baseline_threshold
                   × (1 + adaptation_factor(soma_fast_trace))
                   × neuromod_factor(NE_level, ACh_level)
                   × refractory_factor(time_since_last_AP)

    if branch_Vm > AP_threshold:
        AP_fired = True
        soma_budget -= AP_generation_cost
        // cost covers: Na⁺/K⁺ current ATP + NaK_reset + fast_signaling_consumables

        // Fast trace: nuclear Ca²⁺
        soma_fast_trace += nuclear_Ca_influx()
        soma_fast_trace *= decay(τ = seconds)
        soma_budget     -= nuclear_Ca_handling_cost
        // cost covers: nuclear Ca²⁺ pump ATP

        // Refractory timer
        refractory_timer = absolute_refractory_duration

        // Possible tagging
        if soma_fast_trace > eligibility_threshold:
            soma_possible_tagging += soma_fast_trace
        soma_possible_tagging *= decay(τ = seconds)

        // Dopamine decays
        dopamine_local *= decay(τ = hundreds_of_ms)

        // Tag: nuclear Ca²⁺ AND dopamine coincidence
        if dopamine_local > dopamine_threshold and
           soma_possible_tagging > tagging_threshold:
            soma_tag += dopamine_local × soma_possible_tagging
        soma_tag *= decay(τ = hours)
        soma_budget -= CREB_phosphorylation_cost
        // cost covers: CREB phospho ATP (minor fast cost)
        // full CREB-driven synthesis is NIGHT operation consuming soma_energy
```

### CONTEXT: NOT_AP
```
scope DAY | context NOT_AP:

    // Fast trace decays — threshold returning to baseline
    soma_fast_trace  *= decay(τ = seconds)
    refractory_timer  = max(0, refractory_timer - Δt)

    // Budget self-replenishment — soma fuels itself from own mitochondria
    soma_budget += mitochondria_output_rate × Δt
    // Note: soma is the only component that self-replenishes
    //       all other components receive from soma or astrocyte

    // Integrate dendritic inputs
    branch_Vm = integrate(DEND.branch_Vm, all_branches)
    soma_budget -= integration_cost

    // Ship budget to DEND — downstream operational replenishment
    soma_shipment_to_dend = min(soma_budget × dend_delivery_fraction,
                                dend_demand(dend_tag))
    dend_budget  += soma_shipment_to_dend
    soma_budget  -= soma_shipment_to_dend + shipping_cost
    // cost covers: fast organelle delivery running cost
    // Note: structural dend_material ships in NIGHT, not here

    // Ship budget to AXON — downstream operational replenishment
    soma_shipment_to_axon = min(soma_budget × axon_delivery_fraction,
                                axon_demand(axon_tag))
    axon_budget  += soma_shipment_to_axon
    soma_budget  -= soma_shipment_to_axon + shipping_cost
    // cost covers: fast axonal fuel delivery
    // Note: structural axon_material and pre_material ship in NIGHT

    // Dopamine decays
    dopamine_local *= decay(τ = hundreds_of_ms)
```

---

## AXON

### CONTEXT: AP
```
scope DAY | context AP:

    // AP propagation — reliability set by axon_structure (READ)
    propagation_reliability = axon_structure.myelination
                              × (1 - failure_rate(axon_fast_trace))
    APs_delivered = AP_fired × propagation_reliability
    axon_budget  -= AP_propagation_cost × APs_delivered
    // cost covers: NaK_reset_ATP at each node of Ranvier

    // Fast trace: propagation load deposited
    axon_fast_trace += APs_delivered
    axon_fast_trace *= decay(τ = seconds)
    // high axon_fast_trace → Na⁺ channel inactivation → propagation failure
    // this is axonal STD — frequency-dependent filtering
```

### CONTEXT: NOT_AP
```
scope DAY | context NOT_AP:

    // Fast trace decays — propagation reliability recovering
    axon_fast_trace *= decay(τ = seconds)

    // Budget replenishment — received from SOMA shipment
    axon_budget += soma_shipment_to_axon    // received from SOMA NOT_AP
    axon_budget += astro_lactate × axon_fraction  // astrocyte top-up along shaft

    // Ship budget to PRE boutons — downstream operational replenishment
    axon_shipment_to_pre = min(axon_budget × pre_delivery_fraction,
                               pre_demand(pre_tag))
    pre_budget   += axon_shipment_to_pre
    axon_budget  -= axon_shipment_to_pre + axon_shipping_cost
    // cost covers: kinesin_ATPase running cost for fast delivery to boutons
    // Note: structural pre_material (AZ proteins) ships in NIGHT, not here

    // Possible tagging
    if axon_fast_trace > eligibility_threshold:
        axon_possible_tagging += axon_fast_trace
    axon_possible_tagging *= decay(τ = seconds)

    // Dopamine decays
    dopamine_local *= decay(τ = hundreds_of_ms)

    // Tag
    if dopamine_local > dopamine_threshold and
       axon_possible_tagging > tagging_threshold:
        axon_tag += dopamine_local × axon_possible_tagging
    axon_tag *= decay(τ = hours)
```

---

## ASTRO

### CONTEXT: CONTINUOUS
```
scope DAY | context CONTINUOUS:

    // ROOT energy production — self-generated from vascular glucose
    astro_budget += glycolysis(vascular_glucose_supply) × Δt
    // hard cap: vascular_glucose_supply (FIXED) — cannot be exceeded
    // cost covers: glycolysis running cost (minimal — glycolysis is the revenue here)

    // Lactate export — distributes to ALL neuronal components continuously
    astro_lactate = min(astro_budget × lactate_export_fraction,
                        vascular_glucose_supply × max_export_fraction)
    astro_budget -= astro_lactate
    // Distribution happens via specific component budgets in their NOT contexts:
    //   pre_budget  += astro_lactate × pre_fraction   (in PRE NOT_AP)
    //   post_budget += astro_lactate × post_fraction  (in POST NOT_bAP)
    //   dend_budget += astro_lactate × dend_fraction  (in DEND NOT_bAP)
    //   axon_budget += astro_lactate × axon_fraction  (in AXON NOT_AP)
    // Note: astro_lactate is the variable; delivery happens when components replenish

    // Glutamate clearance — rate set by astro_structure (READ)
    clearance     = astro_structure.EAAT_density × glutamate × Δt
    glutamate    -= clearance
    astro_budget -= clearance × EAAT_ATP_cost
    // cost covers: EAAT cotransport ATP + secondary NaK pump cost

    // Tonic D-serine baseline — from astro_structure (READ)
    astro_D_serine += astro_structure.D_serine_tonic × Δt
    astro_budget   -= astro_structure.D_serine_tonic × tonic_synthesis_cost
    // cost covers: constitutive racemase ATP + baseline serine fast cost

    // Overflow detection and D-serine pulse release
    if glutamate > spillover_threshold:
        astro_fast_trace += mGluR5_Ca_influx()
        astro_fast_trace *= decay(τ = seconds)

        D_serine_pulse    = min(proportional_to(astro_fast_trace),
                                astro_budget × Ds_fraction)
        astro_budget     -= D_serine_pulse × Ds_synthesis_cost
        astro_D_serine   += D_serine_pulse
        // cost covers: racemase_ATP + serine_precursor_fast_cost

        // Simultaneous presynaptic brake — cross-compartment, no astro cost
        Ca_drive_pre     *= mGluR_brake_factor

        // Possible tagging
        if astro_fast_trace > eligibility_threshold:
            astro_possible_tagging += astro_fast_trace
        astro_possible_tagging *= decay(τ = seconds)

        // Dopamine decays
        dopamine_local *= decay(τ = hundreds_of_ms)

        // Tag
        if dopamine_local > dopamine_threshold and
           astro_possible_tagging > tagging_threshold:
            astro_tag += dopamine_local × astro_possible_tagging
        astro_tag *= decay(τ = hours)

    // Global overload check
    if astro_fast_trace > OVERLOAD_threshold:
        trigger(shockwave_lockdown)
```

---

## Special Case — Shockwave Lockdown

```
scope DAY or NIGHT | context OVERLOAD:

    // Emergency — bypasses all budget gates
    Vm               = HYPERPOLARIZED
    post_budget     -= emergency_reset_cost       // DAY cost
    AMPA_occupancy   = mass_internalization()     // receptors to post reserve
    axon_fast_trace += overdrive_cluster()        // VGCC clustering beneath AZ
    astro_budget    -= emergency_astro_cost
    // Note: in NIGHT, post_energy used if structural receptors affected
```

---
---

# SCOPE: NIGHT
 {component}_energy and {component}_material used — NOT {component}_budget
 Structural variables WRITTEN. Tags evaluated and cleared.
 Budget variables replenished here for next DAY.

---

## Step 1 — Replenish All Budgets, Energy, and Material

```
scope NIGHT | step 1:

    // ── ASTROCYTE: root replenishment ───────────────────────────────
    astro_budget   += overnight_glycolysis(vascular_glucose_supply) × Δt_night
    // replenishes fast operational budget for next DAY
    astro_energy   += overnight_astro_energy_synthesis() × Δt_night
    // replenishes structural assembly ATP
    astro_material += astrocyte_cellbody_synthesis() × Δt_night
    // replenishes: EAAT proteins + racemase + ECM proteins + process cytoskeleton

    // ── SOMA: self-replenishment + material production ───────────────
    soma_budget    += overnight_mitochondria_output() × Δt_night
    // replenishes fast operational budget for next DAY
    soma_energy    += overnight_soma_energy_reserve() × Δt_night
    // replenishes structural assembly ATP
    soma_material  += CREB_driven_synthesis(soma_tag) × Δt_night
    // PRIMARY MATERIAL PRODUCTION — rate set by soma_tag magnitude
    // this is the production bottleneck for ALL downstream structural commits

    // ── MATERIAL DISTRIBUTION: soma → downstream ─────────────────────
    // Soma ships structural material to branches and axon
    dend_material  += soma_material × dend_material_fraction
    axon_material  += soma_material × axon_material_fraction
    soma_material  -= (dend_material_fraction + axon_material_fraction) × soma_material

    // Branch delivers structural material to spines
    post_material  += dend_material × spine_material_fraction
    dend_material  -= spine_material_fraction × dend_material

    // Axon delivers structural material to boutons
    pre_material   += axon_material × bouton_material_fraction
    axon_material  -= bouton_material_fraction × axon_material

    // ── DOWNSTREAM ENERGY REPLENISHMENT ─────────────────────────────
    pre_energy     += soma_energy × pre_energy_fraction
    post_energy    += soma_energy × post_energy_fraction
    dend_energy    += soma_energy × dend_energy_fraction
    axon_energy    += soma_energy × axon_energy_fraction
    // all downstream structural assembly ATP sourced from soma overnight

    // ── DOWNSTREAM BUDGET REPLENISHMENT for next DAY ─────────────────
    pre_budget     += astro_lactate × pre_fraction × Δt_night
    post_budget    += astro_lactate × post_fraction × Δt_night
    dend_budget    += astro_lactate × dend_fraction × Δt_night
    axon_budget    += astro_lactate × axon_fraction × Δt_night
    // Note: budgets partially pre-loaded here so components start DAY operational
```

---

## Step 2 — Structural Commits (Parallel, Independent)

```
scope NIGHT | step 2:

    // Coherence bonus when pre, post, astro all tagged simultaneously
    all_aligned     = (pre_tag   > tag_expiry_threshold and
                       post_tag  > tag_expiry_threshold and
                       astro_tag > tag_expiry_threshold)
    coherence_bonus = all_aligned ? coherence_factor : 1.0

    // ── PRE COMMIT ──────────────────────────────────────────────────
    if pre_tag > tag_expiry_threshold:
        Δpre  = min(AZ_expansion_cost,
                    pre_material,
                    pre_energy × pre_fraction)
        pre_structure  += Δpre × coherence_bonus   // STRUCTURE WRITTEN
        pre_material   -= Δpre                     // consumed — RECOVERABLE
        pre_energy     -= Δpre × assembly_ATP_cost // consumed — NOT recoverable
        if Δpre < AZ_expansion_cost:
            queue(pre_deficit → next NIGHT)

    // ── POST COMMIT ─────────────────────────────────────────────────
    if post_tag > tag_expiry_threshold:
        Δpost = min(AMPA_insertion_cost,
                    post_material,
                    post_energy × post_fraction)
        post_structure  += Δpost × coherence_bonus // STRUCTURE WRITTEN
        post_material   -= Δpost                   // RECOVERABLE
        post_energy     -= Δpost × assembly_ATP_cost // NOT recoverable
        if Δpost < AMPA_insertion_cost:
            queue(post_deficit → next NIGHT)

    // ── DEND COMMIT ─────────────────────────────────────────────────
    if dend_tag > tag_expiry_threshold:
        Δdend = min(branch_expansion_cost,
                    dend_material,
                    dend_energy × dend_fraction)
        dend_structure  += Δdend × coherence_bonus // STRUCTURE WRITTEN
        dend_material   -= Δdend                   // RECOVERABLE (partially)
        dend_energy     -= Δdend × assembly_ATP_cost
        if Δdend < branch_expansion_cost:
            queue(dend_deficit → next NIGHT)

    // ── SOMA COMMIT ─────────────────────────────────────────────────
    if soma_tag > tag_expiry_threshold:
        Δsoma = min(soma_expansion_cost,
                    soma_material,
                    soma_energy × soma_fraction)
        soma_structure  += Δsoma                   // STRUCTURE WRITTEN
        soma_material   -= Δsoma                   // RECOVERABLE (partially)
        soma_energy     -= Δsoma × assembly_ATP_cost

    // ── AXON COMMIT ─────────────────────────────────────────────────
    if axon_tag > tag_expiry_threshold:
        Δaxon = min(axon_expansion_cost,
                    axon_material,
                    axon_energy × axon_fraction)
        axon_structure  += Δaxon                   // STRUCTURE WRITTEN
        axon_material   -= Δaxon                   // RECOVERABLE (partially)
        axon_energy     -= Δaxon × assembly_ATP_cost
        if Δaxon < axon_expansion_cost:
            queue(axon_deficit → next NIGHT)

    // ── ASTRO COMMIT ────────────────────────────────────────────────
    if astro_tag > tag_expiry_threshold:
        Δastro = min(process_retraction_cost,
                     astro_material,
                     astro_energy × astro_fraction)
        astro_structure += Δastro × coherence_bonus // STRUCTURE WRITTEN
        astro_material  -= Δastro                   // RECOVERABLE (recycling_fraction)
        astro_energy    -= Δastro × assembly_ATP_cost
        if Δastro < process_retraction_cost:
            queue(astro_deficit → next NIGHT)
        // SELF-REINFORCING: astro_structure ↑ → D_serine_tonic ↑ +
        //                   perisynaptic_distance ↓ → future LTP easier
```

---

## Step 3 — Passive Depotentiation

```
scope NIGHT | step 3:

    // Potentiation draws material first.
    // Remainder distributed as maintenance.
    // Below maintenance threshold: structure decays passively.
    // Depotentiation = resource neglect, not active depression signal.

    remaining_material      = total_material_pool - material_consumed_by_commits
    maintenance_per_synapse = remaining_material × maintenance_fraction
                              / total_synapse_count

    for each synapse:

        // Structural decay — passive and continuous
        pre_structure   -= structural_decay_rate × Δt_night
        post_structure  -= structural_decay_rate × Δt_night
        dend_structure  -= structural_decay_rate × Δt_night
        astro_structure -= structural_decay_rate × Δt_night

        // Maintenance counters decay where possible
        if maintenance_per_synapse >= maintenance_cost:
            pre_structure   += maintenance_pre    // fully maintained
            post_structure  += maintenance_post
            dend_structure  += maintenance_dend
            astro_structure += maintenance_astro
        else:
            pre_structure   += maintenance_per_synapse × pre_fraction
            post_structure  += maintenance_per_synapse × post_fraction
            dend_structure  += maintenance_per_synapse × dend_fraction
            astro_structure += maintenance_per_synapse × astro_fraction
            // net: structures drift down — DEPOTENTIATION BY NEGLECT

    // LTD material recovery: returned to pools
    // Energy NOT recovered — asymmetry justifies separate energy + material in NIGHT
    for each synapse where net_structure_change < 0:
        recovered        = abs(net_structure_change) × recycling_fraction
        pre_material    += recovered × pre_fraction
        post_material   += recovered × post_fraction
        astro_material  += recovered × astro_fraction × recycling_fraction
```

---

## Step 4 — Homeostatic Scaling

```
scope NIGHT | step 4:

    if soma_tag > homeostatic_ceiling:
        scale_factor = homeostatic_ceiling / soma_tag
        for each synapse:
            post_structure *= scale_factor          // STRUCTURE WRITTEN
            pre_structure  *= scale_factor          // STRUCTURE WRITTEN
        soma_material += sum(structure_reduction) × recycling_fraction
        // energy NOT recovered
```

---

## Step 5 — Clear All Traces

```
scope NIGHT | step 5:

    // Fast traces: confirmed zero
    pre_fast_trace = post_fast_trace = dend_fast_trace = 0
    soma_fast_trace = axon_fast_trace = astro_fast_trace = 0

    // Possible tagging: confirmed zero
    pre_possible_tagging = post_possible_tagging = dend_possible_tagging = 0
    soma_possible_tagging = axon_possible_tagging = astro_possible_tagging = 0

    // Tags: cleared after commit, carried forward if above threshold
    if pre_tag   < tag_expiry_threshold: pre_tag   = 0
    if post_tag  < tag_expiry_threshold: post_tag  = 0
    if dend_tag  < tag_expiry_threshold: dend_tag  = 0
    if soma_tag  < tag_expiry_threshold: soma_tag  = 0
    if axon_tag  < tag_expiry_threshold: axon_tag  = 0
    if astro_tag < tag_expiry_threshold: astro_tag = 0
```

---

## Summary: Budget Shipment Chain (DAY)

```
SELF-PRODUCED:
    vascular_glucose_supply → astro_budget  (astrocyte, CONTINUOUS)
    own_mitochondria        → soma_budget   (soma, NOT_AP)

SHIPMENT CHAIN (DAY operational budgets):
    astro_budget → astro_lactate → delivered to all components in their NOT contexts:
        → pre_budget  (PRE NOT_AP)
        → post_budget (POST NOT_bAP, via astro_lactate + dend shipment)
        → dend_budget (DEND NOT_bAP, via astro_lactate + soma shipment)
        → axon_budget (AXON NOT_AP, via astro_lactate + soma shipment)

    soma_budget → soma_shipment_to_dend → dend_budget  (SOMA NOT_AP → DEND NOT_bAP)
    soma_budget → soma_shipment_to_axon → axon_budget  (SOMA NOT_AP → AXON NOT_AP)
    dend_budget → dend_shipment_to_post → post_budget  (DEND NOT_bAP → POST NOT_bAP)
    axon_budget → axon_shipment_to_pre  → pre_budget   (AXON NOT_AP → PRE NOT_AP)

MATERIAL SHIPMENT CHAIN (NIGHT structural material):
    soma_material → dend_material → post_material  (soma → branch → spine)
    soma_material → axon_material → pre_material   (soma → axon → bouton)
    astrocyte_body → astro_material                (astrocyte cell body → astrosynapse)

ENERGY DISTRIBUTION (NIGHT assembly ATP):
    soma_energy → pre_energy, post_energy, dend_energy, axon_energy
    astro_energy → astro structural commits only
```


# Flows

Per ora abbiamo in DAY il {component}_budget che raggruppa energy e material, e in NIGHT {component}_energy e {component}_material.

This maps onto a real biological distinction. The astrocyte's lactate and the soma's ATP fund the running costs of the cell — everything that needs to happen just to keep the system operating from moment to moment. CREB-driven protein synthesis funds the capital investment — the slow, expensive structural changes that modify what the running system is capable of. These are two different budgets in the biological sense: operating expenditure versus capital expenditure. Combining them within DAY is correct because DAY is entirely operating expenditure. Keeping them separate in NIGHT is correct because NIGHT mixes operating expenditure with capital expenditure, and only the capital component is recoverable.

Combining {component}_energy e {component}_material would hide the fact that dismantling a structure recovers biological building blocks but not the work that was done to assemble them — which is the thermodynamic reality of any construction and deconstruction process.


## Energy flow

```
VASCULAR SUPPLY
    → ASTROCYTE CELL BODY
        glucose → lactate (glycolysis)
        → astro_budget (local ATP for clearance, D-serine, ECM, process motility)
        → lactate exported to:
            → pre_budget  (ATP for VGCC, vesicle fusion, VATPase)
            → post_budget (ATP for NaK pump, AMPA trafficking, actin)
            → dend_budget (ATP for bAP propagation, local translation)
        
    → SOMA
        soma has own mitochondria — partly self-fueled
        soma_budget (ATP for AP generation, CREB, protein synthesis, shipping)
        → dend_budget top-up (organelle delivery)
        → axon_budget top-up (transport machinery)
```

## Material flow

```
SOMA
    protein synthesis (CREB-driven, peaks in NIGHT)
    → soma_material (receptors, scaffold proteins, organelles, mRNA)
        → dend_material (branch receives proteins + mRNA from soma)
            → post_material (spine receives receptors + actin from branch)
        → axon_material (boutons receive AZ proteins + VGCCs from soma via axon)
            → pre_material (bouton active zone proteins)

ASTROSYNAPSE
    ECM proteins synthesized in astrocyte cell body
    → astro_material (Glypicans, Thrombospondins, serine for D-serine)
        → cleft environment (ECM sealing, D-serine availability)
```

Yes, exactly. This is the essential abstract pattern. Let me state it precisely.

# The Abstract Pattern

A component operates within a structure set by the previous NIGHT. During DAY, in each context, it executes behaviors that cost budget and deposit fast traces. Fast traces are local records of recent activity that bias the next behavior and open an eligibility window for tagging. A tag forms when a local eligibility signal coincides with one or more non-local validation signals within the decay window of the trace — the number of required coincidences reflecting the spatial scale at which that component sits in the system. In contexts without triggering input, all traces decay, closing the windows they opened. At NIGHT, the tag magnitude drives a structural commit proportional to available material and energy — material being recoverable and energy not — with the structural change becoming the new ceiling within which the next DAY's behaviors will operate. What is not committed decays for lack of maintenance, and the resources freed by that decay partially fund the potentiation of what was.

## DAY — The General Form

Every DAY behavior follows this template:

```
given:   STRUCTURE        // the architectural ceiling left by NIGHT
in:      CONTEXT          // local or global triggering condition
if:      BUDGET > cost    // operational resources available
then:    behavior executes
         BUDGET  -= cost  // resources consumed
         FAST_TRACE += f(behavior)  // local record deposited
```

The fast trace then drives two parallel processes:

**Within the same context** — the trace biases the next execution of the same behavior. This is the short-term modulation loop. It is entirely local and requires no external signal.

**Across contexts** — the trace accumulates into `possible_tagging` when it exceeds the eligibility threshold. This is the bridge toward long-term change. It requires the trace to be sustained enough to survive into the NOT_AP or CONTINUOUS context.

### The Tag Formation — Where Non-Locality Enters

The abstract pattern for tag formation generalizes across all components but with different **coincidence requirements**:

**PRE, DEND, SOMA, AXON, ASTRO — one non-local coincidence:**
```
if FAST_TRACE > eligibility       // local: this bouton was recently active
   AND dopamine > threshold       // non-local: organism-level reward signal
then: TAG += dopamine × possible_tagging
```
One spatial scale beyond the local component is required. The organism must confirm that the recent activity was worth saving.

**POST — two non-local coincidences:**
```
// First coincidence (NOT_bAP context):
if FAST_TRACE > Ca_TAG_threshold  // local: spine Ca²⁺ was high
   AND D-serine > threshold       // non-local 1: astrosynapse co-agonist
then: post_possible_tagging += FAST_TRACE   // CANDIDATE

// Second coincidence (bAP context):
if post_possible_tagging > threshold  // local: CANDIDATE still present
   AND bAP arrives                    // non-local 2: soma fired
then: FAST_TRACE amplified above Ca_HIGH

// Tag stabilization (any context):
if post_possible_tagging > threshold  // local: confirmed coincidence
   AND dopamine > threshold           // non-local 3: organism validation
then: TAG += dopamine × post_possible_tagging   // STABLE
```
Three spatial scales must align: astrosynapse, soma, organism. The postsynapse is the most constrained component — it requires the most non-local validation before committing.

### Trace Recession — The Temporal Behavior

In every NOT_AP or CONTINUOUS context, all traces decay:

```
FAST_TRACE       *= decay(τ_fast)      // ms to seconds — closes eligibility window
possible_tagging *= decay(τ_mid)       // seconds to minutes — closes tagging window
TAG              *= decay(τ_slow)      // hours — closes commitment window
```

The decay is not a separate behavior — it is the passive consequence of molecular processes. But its effect is behavioral: it enforces that coincidences must happen within specific time windows. The system does not check timing explicitly — timing is enforced by the competition between accumulation and decay.

## NIGHT — The General Form

```
given:   TAG              // strength of DAY evidence for this component
         STRUCTURE        // current architectural state
if:      TAG > threshold  // evidence strong enough to justify investment
then:
         Δstructure = min(expansion_cost,
                          MATERIAL,        // slow structural resources available
                          ENERGY × fraction) // assembly ATP available
         STRUCTURE  += Δstructure × coherence_bonus
         MATERIAL   -= Δstructure          // RECOVERABLE after LTD
         ENERGY     -= Δstructure × ATP_cost  // NOT recoverable
```

The coherence bonus appears when pre, post, and astro tags are all SET simultaneously — the three components of the synapse have all independently gathered evidence for the same structural change, which amplifies the commit beyond what any single tag would produce alone.

What is not potentiated passively decays:

```
STRUCTURE -= decay_rate × Δt_night
STRUCTURE += min(maintenance_allocation, maintenance_cost)
// if maintenance_allocation < decay_rate × Δt_night:
//   structure drifts down — depotentiation by neglect
```

# More details

## SOMA

### The Abstract Pattern Applied to Soma Timing

The abstract pattern says: a behavior deposits a trace, the trace decays, and the trace biases the next behavior. For the soma, the AP is the behavior, and **the refractory period and threshold elevation should both be consequences of a single trace deposited by the AP, decaying back toward baseline**. Neither should be a hardcoded duration — both should emerge from the return of the trace to resting conditions.

---

Yes, this is much more consistent with the rest of the architecture. The soma should not compute an explicit rhythm estimate and predict the next input — that is top-down. Instead, the **mismatch itself leaves a trace**, and that trace adjusts the refractory dynamics. Let me think through this carefully.

---

### The Bottom-Up Mechanism

The key event is: **a dendritic input arrives strong enough to fire the soma, but the soma is still refractory.** This is a missed opportunity — the input wanted to fire the cell, but the cell was not ready. This mismatch is the signal.

Each time this happens, it should leave a trace that biases the refractory dynamics toward recovering faster in that timing window — so that next time an input arrives at that phase, the soma is ready. This is potentiation of the refractory recovery, occurring within DAY, driven entirely by the local coincidence of "input wanted to fire" and "soma was not ready."

```
scope DAY | context NOT_AP (within refractory):

    // Detect the mismatch: suprathreshold input during refractory
    if branch_Vm > effective_threshold and soma_Na_inactivation > inactivation_threshold:
        // Input arrived but soma could not fire — missed coincidence
        refractory_alignment_trace += (branch_Vm - effective_threshold)
                                       × soma_Na_inactivation
        // graded: stronger input + deeper refractory → larger trace
        // this is the "potentiation" signal for faster recovery
```

The `refractory_alignment_trace` then biases the recovery rate of the inactivation trace:

```
    // Recovery rate biased by accumulated alignment trace
    recovery_rate = base_recovery_rate × (1 + refractory_alignment_trace)
    soma_Na_inactivation *= decay(τ_Na / recovery_rate)
    // more alignment trace → faster recovery → soma ready sooner next time
```

---

### Why This Is Bottom-Up

There is no rhythm estimation, no prediction of the next input time, no computed inter-input interval. The soma does not model its input. It simply notices, locally and reactively, that an input arrived when it was not ready, and leaves a trace that makes it recover faster. Over many such mismatches at the same phase, the recovery speeds up at that phase specifically — and the soma ends up aligned with its input rhythm **without ever representing that rhythm**.

The alignment is an emergent statistical consequence of many local mismatch events, exactly as a potentiated synapse becomes tuned to its input without representing what it is tuned to. The phase-coupling appears, but nothing in the soma computed it.

---

### Depotentiation as Neglect — Not Explicit

Now the crucial part you raised: the depotentiation of refractory alignment must occur as a **consequence of not potentiating**, not as an explicit opposing mechanism.

The `refractory_alignment_trace` decays continuously. If mismatches keep happening at a particular phase, the trace is continuously replenished and the fast recovery is maintained. If mismatches stop happening — because the input rhythm changed, or because the alignment succeeded and inputs now arrive when the soma is ready — then the trace is no longer replenished and **decays back toward baseline on its own**.

```
    // No explicit depotentiation — just decay when not reinforced
    refractory_alignment_trace *= decay(τ_alignment)
    // if mismatches continue → trace replenished → fast recovery maintained
    // if mismatches stop → trace decays → recovery returns to baseline
```

This is exactly parallel to synaptic depotentiation by neglect. The soma does not actively slow its recovery when alignment is no longer needed. It simply stops receiving the mismatch signal that was keeping the recovery fast, and the recovery drifts back to baseline because the trace that accelerated it is no longer reinforced.

There is an elegant self-limiting property here. Once the soma is well-aligned, inputs arrive when it is ready, so there are no more mismatches, so the alignment trace stops being replenished and begins to decay. This would slowly de-align the soma — until inputs start arriving during refractory again, regenerating the mismatch and re-potentiating the alignment. The system settles into a dynamic equilibrium where just enough mismatch occurs to maintain just enough alignment. The soma hovers at the edge of alignment, continuously corrected by the residual mismatches that its imperfect alignment produces.

---

### The Full Bottom-Up Soma Timing

```
scope DAY | context AP:

    effective_threshold = soma_structure.baseline_threshold
                          × (1 + soma_adaptation)
                          × neuromod_factor(NE_level, ACh_level)

    can_fire = (soma_Na_inactivation < inactivation_threshold)

    if branch_Vm > effective_threshold and can_fire:
        AP_fired = True
        soma_budget -= AP_generation_cost

        // Deposit traces from the AP
        soma_Na_inactivation += AP_amplitude       // fast — refractory
        soma_adaptation      += AP_contribution     // slow — spike train threshold
        soma_fast_trace      += nuclear_Ca_influx() // slow — plasticity tagging

scope DAY | context NOT_AP:

    // MISMATCH DETECTION — bottom-up alignment signal
    if branch_Vm > effective_threshold and soma_Na_inactivation > inactivation_threshold:
        // input wanted to fire but soma was refractory — missed coincidence
        refractory_alignment_trace += (branch_Vm - effective_threshold)
                                       × soma_Na_inactivation
        // local potentiation of recovery — no prediction, no rhythm model

    // Recovery biased by alignment trace
    recovery_rate = base_recovery_rate × (1 + refractory_alignment_trace)
    soma_Na_inactivation *= decay(τ_Na / recovery_rate)    // faster if aligned
    soma_adaptation      *= decay(τ_adaptation)
    soma_fast_trace      *= decay(τ_nuclear)

    // Alignment trace decays — depotentiation by neglect, not explicit
    refractory_alignment_trace *= decay(τ_alignment)
    // maintained only while mismatches continue
    // self-limiting: good alignment → fewer mismatches → trace decays →
    //                slight de-alignment → mismatches return → re-potentiation

    // ... budget replenishment, shipments, tagging as before ...
```

---

### The Conceptual Payoff

This makes the soma's temporal alignment obey exactly the same principles as everything else in the system:

A behavior leaves a trace — here the missed coincidence leaves the alignment trace.

The trace biases future behavior — here it accelerates recovery so the next input at that phase succeeds.

Potentiation is the active drive — the soma actively speeds up recovery in response to mismatch.

Depotentiation is neglect — the alignment trace decays when mismatches stop, with no explicit opposing process.

The system finds equilibrium through the residual of its own imperfection — just enough mismatch persists to maintain just enough alignment.

And critically, the soma achieves temporal prediction — firing in phase with its input rhythm — **without ever representing the rhythm**. The prediction is implicit in the structure of the recovery dynamics, built up from purely local, reactive, bottom-up trace deposits. This is the same way a potentiated synapse "predicts" that its input will be significant without representing the prediction: the prediction is the physical bias left by past experience, not a computed expectation. The soma's phase-coupling is the temporal version of the synapse's weight — both are implicit predictions encoded as physical bias, both built bottom-up from local coincidence, both maintained by reinforcement and lost by neglect.

## Energy depletion in Presynapse

how does the budget and energy influence the model. If for example a presynapse has no more energy variuos times during day, what happens?

Good question. Let me trace through exactly what happens when energy is repeatedly depleted, following the mechanics already in the pseudocode.

---

### The Immediate Effect — Behavior Suppression

When `pre_budget < AP_release_cost`, the pseudocode does:

```
if pre_budget < AP_release_cost:
    suppress(NT_flux)
    exit context
```

So the immediate consequence of an energy-depleted bouton is **silence** — it does not release neurotransmitter for that AP, regardless of how strong the incoming spike was. The AP arrives, but nothing comes out the other side. This is biologically real: ATP-depleted boutons fail to release because the VATPase cannot refill vesicles and the calcium pumps cannot maintain the gradients that drive release.

---

### The Cascade of Consequences Within DAY

A single depletion is recoverable — the bouton refuels from astrocyte lactate in the next NOT_AP context and resumes. But **repeated depletion during DAY** sets off a cascade that runs through the entire trace and tagging machinery.

**No release means no glutamate means no downstream trace.** When the bouton is silent, no glutamate reaches the cleft. The postsynapse receives no AMPA current, its NMDA channels do not open, and `post_fast_trace` does not rise. The astrosynapse detects no spillover, so `astro_fast_trace` does not rise and no D-serine pulse is released. The entire synaptic event simply does not happen. A bouton that is energy-depleted at the moment a significant pattern arrives causes that pattern to be invisible to the postsynapse — the synapse fails to participate in whatever the network is doing.

**No participation means no eligibility.** Because the bouton did not release, `pre_fast_trace` is not elevated by a release event (it still rises from calcium influx, but without the reinforcing facilitation of successful release). More importantly, the postsynapse, having received no input, accumulates no `post_possible_tagging`. When dopamine arrives to validate the moment, there is nothing to validate at this synapse — the eligibility window is empty. The synapse misses the tagging opportunity entirely.

**Missing the tag means missing the NIGHT commit.** Since no tag was set during DAY, the synapse has nothing to draw structural resources with during NIGHT. It does not potentiate. And because the system's depotentiation is by neglect, **a synapse that fails to potentiate is automatically on the path to depotentiation** — it receives only maintenance allocation, and if other synapses potentiated and drew down the shared pool, even maintenance may be insufficient.

---

### The Deeper Consequence — Energy Depletion Becomes Structural Depression

Here is the important emergent property: **repeated energy depletion at a bouton during DAY leads to its structural depression during NIGHT, even though no depression signal was ever sent.**

The chain is entirely passive:

```
repeated pre_budget depletion in DAY
    → bouton silent during significant events
    → no glutamate release
    → no post_fast_trace, no post_possible_tagging
    → no tag set (pre or post)
    → no NIGHT structural commit at this synapse
    → only maintenance allocation received
    → if pool depleted by other synapses' potentiation:
        maintenance insufficient
    → pre_structure and post_structure decay
    → DEPOTENTIATION
```

The energy-starved synapse is outcompeted not because it was marked for depression but because it could not generate the activity needed to claim resources. Energy availability during DAY therefore directly determines which synapses can even enter the competition for NIGHT potentiation.

---

### The Feedback Loop — Depression Reduces Future Energy Demand

There is a stabilizing feedback here. A depotentiated synapse has smaller `pre_structure` — a smaller active zone, fewer docking slots, lower release probability. This means it costs **less energy to operate**. So a synapse that was energy-starved and consequently depotentiated now has lower energy demands, making it less likely to be energy-starved in the future.

```
energy depletion → depotentiation → smaller structure → lower energy demand
    → less likely to deplete → stabilizes at a low-activity equilibrium
```

The synapse settles into a low-energy, low-structure, low-activity state. It is not dead — it still operates at baseline — but it has been demoted from the pool of synapses competing for potentiation. Energy scarcity has selected it out.

---

### Why This Is Functionally Important

This is not a bug — it is a resource-allocation mechanism with real computational value.

**Energy availability acts as a second gate on plasticity, parallel to the neuromodulatory gate.** Dopamine asks "was this worth saving?" Energy asks "can this synapse afford to participate?" A synapse must pass both gates to be potentiated. This means the system preferentially potentiates synapses that are both behaviorally significant AND metabolically sustainable. A synapse that cannot sustain its own activity is not a good candidate for strengthening, because strengthening it would only increase its energy demand and make it fail more often.

**Local energy competition implements a form of spatial sparsification.** Boutons on the same axon share `axon_budget` and ultimately the same astrocytic lactate supply. When many boutons are active simultaneously, the shared energy is divided among them, and the weakest — those with the least efficient structure or the least reliable input — deplete first and fall silent. This automatically sparsifies activity: under energy pressure, only the most robust synapses keep firing, and they are the ones that get potentiated. The system concentrates its limited resources on its strongest connections.

**The astrocyte's energy delivery becomes a control signal.** Because the astrocyte controls lactate distribution across its territory, it has indirect control over which synapses can sustain activity and therefore which can be potentiated. A region of the astrocyte territory that is well-perfused and well-fueled supports vigorous plasticity. A region that is metabolically stressed — perhaps because of high overall demand or reduced vascular supply — suppresses plasticity in its synapses regardless of their activity. This couples the metabolic state of the tissue directly to its capacity to learn.

---

### What Repeated Depletion Looks Like Over Days

If a bouton is chronically energy-starved across multiple DAY cycles — perhaps because it is in a metabolically compromised region, or because it is competing with many highly active neighbors — the trajectory is:

```
Day 1: depletes occasionally → misses some events → weak tag → partial commit
Day 2: smaller structure → still depletes under load → weaker tag → less commit
Day 3: structure decaying → maintenance insufficient → depotentiation accelerates
...
Equilibrium: minimal structure, minimal energy demand, minimal participation
             synapse survives but is functionally silent
             resources it would have consumed now available to neighbors
```

This is a reasonable model of what happens to synapses in metabolically stressed tissue — they do not die immediately, but they are progressively silenced and depotentiated, freeing their resources for synapses in healthier regions. It is also a model of how chronic metabolic limitation — aging, vascular disease, mitochondrial dysfunction — would manifest as a gradual loss of plasticity capacity: not through any depression signal, but through the simple inability of energy-starved synapses to participate in the activity that would let them claim resources.

The energy budget is therefore not just a constraint that occasionally blocks behavior — it is a continuous selective pressure that shapes which synapses thrive and which fade, operating silently in parallel with the explicit activity-and-reward-driven plasticity, and ultimately determining the metabolic sustainability of whatever the system chooses to remember.

## Three parallel competitive resource economies
The neuronal structural economy — soma produces material, distributed through dendrite to spines and through axon to boutons, competed for by tagged synapses during NIGHT.
The astrocytic energy economy — astrocyte cell body produces lactate, distributed to perisynaptic processes, competed for by active synapses during DAY in proportion to their clearance demand.
The soma's own energy economy — soma mitochondria fuel AP generation and shipping, competed for by the soma's own functions.
All three share the same logic: a central producer with a capped output, distribution to peripheral consumers, demand-weighted allocation, and a self-reinforcing coupling where stronger consumers both demand and receive more. And all three ultimately bottom out at the same vascular glucose ceiling — the astrocyte directly, the soma through its own glucose uptake.
The deep consequence is that a synapse must win on both economies to be potentiated. It must generate enough activity to pull lactate from the astrocyte (energy economy) AND accumulate enough tag to draw material during NIGHT (structural economy). A synapse that wins the structural competition but cannot pull energy will be unable to sustain the activity that justified its potentiation — it will be a large, expensive structure that keeps going silent. A synapse that pulls energy but never accumulates a tag stays metabolically supported but structurally weak. Only synapses that win both — active enough to be fueled, significant enough to be tagged — achieve and maintain full potentiation. The two economies together implement a stringent joint criterion: persistent significant activity that the metabolic infrastructure can sustain.
