Skip to content

Add challenge 82: Linear Recurrence (Medium)#217

Open
claude[bot] wants to merge 1 commit intomainfrom
add-challenge-82-linear-recurrence
Open

Add challenge 82: Linear Recurrence (Medium)#217
claude[bot] wants to merge 1 commit intomainfrom
add-challenge-82-linear-recurrence

Conversation

@claude
Copy link
Contributor

@claude claude bot commented Mar 14, 2026

Summary

  • Adds challenge 82: Linear Recurrence (Medium difficulty)
  • Computes h[b,t] = a[b,t] * h[b,t-1] + x[b,t] for batched sequences of shape [B, L]
  • This is the core primitive of State Space Models (Mamba, S4, H3) used in modern LLM inference
  • Naive O(L) sequential scan is correct; solvers are challenged to implement a parallel scan using the associative combine operator (a1,x1)⊕(a2,x2) = (a1·a2, a1·x2+x1) — achieving O(log L) depth
  • Teaches a deeper parallel scan pattern than the existing prefix sum challenge, with direct real-world applicability

Test plan

  • generate_example_test() uses clean illustrative values (exponential decay + prefix sum rows)
  • generate_functional_test() covers: single element, 2-element, zero inputs, a=0 (no recurrence), a=1 (prefix sum), power-of-2 lengths, non-power-of-2 lengths, realistic SSM size
  • generate_performance_test() uses B=64, L=16384 (~12 MB total, fits 5× in 16 GB VRAM)
  • All tests validated on NVIDIA Tesla T4 via run_challenge.py --action submit
  • All 6 starter files present and correct
  • pre-commit run --all-files passes
  • challenge.html starts with <p>, uses <h2> sections, LaTeX \begin{bmatrix} for matrix examples, includes SVG visualization, performance bullet matches generate_performance_test()

🤖 Generated with Claude Code

Introduces a parallel-scan challenge based on the linear recurrence
h[b,t] = a[b,t] * h[b,t-1] + x[b,t], the core computational primitive
of State Space Models (Mamba, S4, H3). Naive sequential execution is
O(L) per batch row; solvers must implement a parallel scan using the
associative combine operator (a1,x1)⊕(a2,x2) = (a1·a2, a1·x2+x1)
to achieve sub-linear depth. Teaches parallel scan beyond simple prefix
sum and is directly applicable to real LLM inference workloads.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants