NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Compiling to Recurrent Neurons

Joey Velez-Ginorio, Nada Amin, Konrad P. Kording, Steve Zdancewic

TL;DR

This paper introduces a method to compile discrete programming structures—specifically iteration—into differentiable recurrent neurons. By using a specialized linear programming language called Cajal, the authors demonstrate that "programming" the functional structure of a neural network allows it to learn algorithmic tasks faster and with significantly higher data efficiency than standard architectures.

What Problem Does This Paper Address?

In the world of differentiable programming, discrete structures like if-else conditionals and for loops are often treated as "second-class citizens." Because these structures lack overt derivatives, standard gradient-based learning (backpropagation) can't easily "see" through them. This forces researchers to either avoid discrete logic entirely or use "soft" approximations that can be difficult to train.

While recent work has shown how to compile conditionals into linear neurons, iteration has remained a challenge. Without a way to express first-class iteration, it is difficult to build neural networks that can naturally handle tasks requiring a variable number of steps—like applying a transformation $n$ times where $n$ is determined by the input itself.

Methods

The authors propose a formal bridge between symbolic programming and connectionist learning:

  1. Cajal($\multimap, 2, \mathbb{N}$): A minimal, linearly typed programming language. The choice of a linear type system is crucial; it restricts how variables are used (preventing them from being discarded or duplicated arbitrarily), which creates a direct mathematical mapping to linear algebra.
  2. Compilation to Recurrent Neurons: The authors provide a compiler that translates Cajal programs into linear recurrent neurons (essentially discrete-time linear dynamical systems).
  3. Natural numbers are compiled into an infinite-dimensional sequence space.
  4. Iteration is compiled into a summation over time steps, where the dynamics of the recurrent neuron implement the loop logic.
  5. Formal Correctness: Unlike many neurosymbolic approaches, this paper provides a rigorous proof of compiler correctness. They use logical relations to prove that the behavior of the compiled neurons exactly matches the evaluation of the original discrete program.

Datasets

The researchers evaluated their approach using several image-processing tasks based on the MNIST dataset:

  • Iterative Image Transformation: A network must recognize a digit $n$. If the digit is 0, it returns the image; if the digit is $n$, it must apply a vertical blur exactly $n$ times.
  • Conditional Iteration: A variant where the iterative blur is only applied if the input digit is odd.
  • Logic Benchmarks: Replications of prior work involving binary classification tasks like XOR, EQ, AND, and OR using image inputs.

Key Insights and Ideas

  • Recurrence as a Functional Prior: By compiling a program into the network's architecture, you are effectively setting a "functional prior." The network doesn't have to spend thousands of examples discovering that a task is iterative; the structure of iteration is already there, leaving the network to only learn the specific parameters (like the blur kernel).
  • The Power of Linearity: The paper highlights that linear recurrent neurons, when observed over a finite timeframe, are equivalent to linear maps between finite-dimensional vector spaces. This makes them inherently differentiable and compatible with standard deep learning frameworks like PyTorch.
  • One-Hot Encoding in Time: For natural numbers, the compiler uses "one-hot" encodings that occur across time steps. This allows a single recurrent neuron to represent the concept of "counting" to $n$ in a way that the rest of the network can utilize.

Key Results

The authors compared three models: Model D (Directly programmed via Cajal), Model T (Type-preserving but with random initialization), and Model I (An indirect baseline CNN).

  • Superior Learning Speed: Model D learned the iterative blur task almost immediately, while the standard CNN (Model I) struggled to capture the multi-step nature of the transformation, often resulting in a blurry "average" instead of the correct number of iterations.
  • Data Efficiency: Model D reached high Peak Signal-to-Noise Ratio (PSNR) values with far fewer training steps than the alternatives.
  • Stability: While Model D was highly effective, the authors noted it could be less stable in early training if the learned weights (like the blur kernel) grew too large, suggesting that "programming" a network requires careful initialization or normalization.

Limitations and Future Work

  • Linearity Constraints: The current framework relies on linear recurrent neurons. While mathematically elegant and easier to prove correct, most state-of-the-art RNNs use non-linearities (like Sigmoid or Tanh). Extending this theory to non-linear recurrence is a major next step.
  • Numerical Stability: The authors observed that linking compiled neurons with vectors of large norms can destabilize gradient descent. They suggest that future compilers might need to automatically bound these norms.
  • Complex Data Structures: The current work focuses on natural numbers and iteration. The authors suggest that "recursive neurons" could eventually allow for first-class differentiable recursion over more complex structures like lists and trees.

Summary updated

BibTeX
@article{velezginorio2026compiling,
  author = {Joey Velez-Ginorio and Nada Amin and Konrad P. Kording and Steve Zdancewic},
  title = {{Compiling to Recurrent Neurons}},
  journal = {Proc. ACM Program. Lang.},
  year = {2026},
  doi = {10.1145/3808345},
}
Figure