Worked examples — State-space models (Mamba, S4)
This page is a drill. The parent note built the machinery; here we run it through every situation it can face. Before each example, you forecast the answer — guess the sign, the size, the behaviour — then we grind the steps.
Everything below uses only three moving parts you already met:
- a state (a short list of numbers the model carries forward — its memory),
- a decay (how much of yesterday's memory survives to today),
- an input push (how much the new token adds to memory),
and one readout (what we actually output). If any of those words feels shaky, reread the parent's State-Space Foundation first.
The scenario matrix
Every question this topic throws at you lands in one of these cells. Each example below is tagged with the cell it hits.
| Cell | What makes it special | Example |
|---|---|---|
| A. Stable decay () | memory fades smoothly | Ex 1 |
| B. Perfect memory () | nothing forgotten, running sum | Ex 2 |
| C. Dead memory () | forgets instantly, no history | Ex 3 |
| D. Unstable / diverging () | memory blows up | Ex 4 |
| E. Sign-flip / oscillation () | memory alternates sign | Ex 5 |
| F. Multi-dim state (, mixed rates) | fast + slow channels together | Ex 6 |
| G. Convolution view (kernel from recurrence) | unroll to | Ex 7 |
| H. Discretization (continuous discrete) | turn into | Ex 8 |
| I. Selective (Mamba) ( per token) | model chooses to remember | Ex 9 |
| J. Real-world word problem | reason about behaviour, not just arithmetic | Ex 10 |

Look at the red curve: it is the impulse response — feed a single spike at time 0, then watch how the state remembers it. Slow decay = long red tail; = flat red line (never forgets); = red bars flipping above/below zero. Keep this picture in mind for every example.
Cell A — Stable decay ()
- State after the push. . Why this step? Only is nonzero, so this is the only injection of new information.
- Silent steps decay the state. , , . Why this step? With the input term vanishes; each step just multiplies by .
- Readout. , so : . Why this step? The observation matrix is identity-like here, so output equals state.
Verify: . At : . Matches the forecast (~0.25). Geometric decay confirmed — this is the classic "leaky memory."
Cell B — Perfect memory ()
- . Why? Full carry-over of past () plus new input.
- . Why? The input subtracts from stored memory.
- . Why? Still no decay; keep accumulating.
Verify: . When an SSM is a prefix-sum machine — the degenerate boundary between forgetting and diverging.
Cell C — Dead memory ()
- . Why? The term wipes the past — is annihilated.
- . Why? Again no memory; output tracks the current input only.
Verify: . The 7 vanished, confirming forecast. With the SSM degenerates to a per-token linear layer — no sequence modelling at all.
Cell D — Unstable / diverging ()
- . Why? The single injected spike.
- , , . Why? Each silent step amplifies because .
Verify: , so . Over 100 steps this reaches — numerical explosion. This is exactly why S4/Mamba constrain the real part of to be negative so that .
Cell E — Sign-flip / oscillation ()
- . Why? The spike enters.
- ; ; . Why? Multiplying by a negative each step swings the state above and below zero while shrinks it.
Verify: . Sign alternates, magnitude halves — a damped oscillation. Real SSMs use complex so a single channel can oscillate and decay smoothly; this real negative case is the crudest version of that.
Cell F — Multi-dim state, mixed rates ()
- Decay each channel independently: . Why? is diagonal, so channels do not talk to each other during decay — each has its own memory length.
- Add the input push : . Why? Same scalar input enters both channels but scaled differently by .
- Readout: . Why? The negative weight lets the output say "high when channel 1 high and channel 2 low."
Verify: . Matches. Two channels = two memory timescales in parallel; stack of them and you get a rich filter bank.
Cell G — Convolution view (kernel from the recurrence)
- Entry 0: . Why? This is the immediate response of the output to a spike at the current step.
- Entry 1: . Why? How much a spike one step ago still contributes.
- Entries 2,3: , . Why? Older spikes contribute less — the kernel is the impulse response.
So .
- Cross-check via the recurrence. Feed a spike : outputs are , i.e. exactly . Why? Convolving any signal with gives the same output as running the recurrence — the two views agree.
Verify: from both the kernel formula and the impulse response. This equivalence is why S4 can train with a parallel FFT convolution but generate with the cheap recurrence.

The red stems are : a decaying comb. Convolving the input with this comb slides the comb along the sequence — no per-token loop needed.
Cell H — Discretization (continuous discrete)
- . Why exponential and not ? The matrix exponential is the exact solution of for constant input; Euler () is only a first-order approximation that drifts over long sequences.
- . Why this form? It is the exact integral — the accumulated effect of a constant input over one timestep.
Verify: . (For this "gain sums to 1" is a useful sanity check.) — stable, exactly why Mamba parametrizes . Because , a larger pushes toward 0 (fast forgetting) and a smaller pushes toward 1 (long memory) — the exact knob Mamba turns per token (Ex 9).
Cell I — Selective (Mamba, per-token )
- Important token: . Why? Small means we barely advance the continuous clock, so almost nothing decays — the state holds this token's contribution for many future steps.
- Filler token: . Why? A big jumps the clock far forward, so shrinks toward 0 — memory of this token evaporates.
- Interpretation. Same , but is now a function of the input (). This is precisely the parent's "John" () vs "and" () split. Why it matters: fixed S4 must pick one decay for all tokens; Mamba tunes decay token-by-token, which is why it beats S4 on selective-copy and long-context tasks.
Verify: , . The important token retains of memory per step, the filler only — the "choose what to remember" behaviour, made of nothing but the exponential from Ex 8.
Cell J — Real-world word problem
- Model the decay. After silent steps the memory is . Why? No new input on this channel, so each step just multiplies by (Cell A behaviour).
- Set the threshold. We want . Why? "Below 10% strength" is the retention cutoff the problem asks for.
- Solve with logs. Take of both sides (logs turn the exponent into a product we can isolate): Why logarithms? The unknown is stuck in an exponent; the logarithm is the exact tool that "brings it down."
- Round up. After about 114 tokens the fact has faded below 10%.
Verify: ✓, while . So 114 is the first token past the threshold. A "half-life" version: tokens — memory halves every ~34 tokens. This is the concrete meaning of "long-range memory."
Recall
Recall What single number decides whether a scalar SSM forgets, remembers forever, or explodes?
The decay ::: forgets (stable), is a running sum, diverges, oscillates.
Recall Why does Mamba parametrize
with ? It guarantees for any positive ::: so the model is always stable, and becomes a clean per-token memory-length knob.
Recall How do the recurrent and convolutional views relate?
The convolution kernel is the impulse response ::: convolving with it gives identical output to running the recurrence — used for parallel training vs cheap generation.
See also: RNNs and LSTMs (recurrence and gating), Convolutional Neural Networks (the kernel view), Linear Attention (another route).