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

Compiling to recurrent neurons

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

Abstract

This paper presents a novel framework for compiling discrete programming structures, specifically iteration, into differentiable recurrent neurons. By leveraging a specialized linear programming language called Cajal, the authors demonstrate that embedding functional priors into neural architectures significantly enhances learning speed and data efficiency for algorithmic tasks.

Introduction

In differentiable programming, discrete structures like conditionals and loops are often problematic because they lack explicit derivatives, making them "invisible" to standard gradient-based optimization. While previous research has addressed compiling conditionals into linear neurons, iteration has remained a significant hurdle. Without first-class iteration, neural networks struggle to naturally handle tasks requiring a variable number of steps determined by input data. This paper addresses this gap by providing a formal bridge between symbolic programming and connectionist learning.

Methodology: The Cajal Compiler

The core contribution is a compiler that translates programs written in Cajal($\multimap, 2, \mathbb{N}$)—a minimal, linearly typed language—into linear recurrent neurons.

Cajal code and its compiled recurrent architecture for iterative blurring.

The choice of a linear type system is fundamental; it restricts variable usage to prevent arbitrary discarding or duplication, creating a direct mapping to linear algebra. Natural numbers are compiled into an infinite-dimensional sequence space, while iteration is represented as a summation over time steps. The dynamics of the recurrent neuron effectively implement the loop logic. Crucially, the authors provide a proof of compiler correctness, ensuring the compiled neurons' behavior matches the original discrete program's evaluation.

Experimental Evaluation

The approach was evaluated on image-processing tasks using the MNIST dataset, most notably an Iterative Image Transformation task. In this task, the network must recognize a digit $n$ and apply a vertical blur transformation exactly $n$ times.

The iterative blur task: applying a vertical blur $n$ times based on the input digit.

The researchers compared three models: Model D (Directly programmed via Cajal), Model T (Type-preserving but with random initialization), and Model I (An indirect baseline CNN). Model D demonstrated superior learning speed and data efficiency, reaching high Peak Signal-to-Noise Ratio (PSNR) values almost immediately. In contrast, the standard CNN (Model I) struggled to capture the multi-step nature of the transformation, often producing a blurry "average" output rather than the precise number of iterations.

Discussion and Key Insights

By compiling a program into the network's architecture, researchers set a "functional prior." The network does not need to discover the iterative nature of a task from scratch; the structure is pre-defined, allowing the model to focus on learning specific parameters, such as the blur kernel. Furthermore, linear recurrent neurons are inherently differentiable and compatible with standard deep learning frameworks like PyTorch, as they function as linear maps between finite-dimensional vector spaces over finite timeframes.

Limitations and Future Work

While the current framework is mathematically elegant, it is limited to linear recurrent neurons. Most state-of-the-art RNNs utilize non-linearities (e.g., Sigmoid or Tanh), and extending this theory to non-linear recurrence is a priority for future research. Additionally, numerical stability remains a concern, as large vector norms can destabilize gradient descent. Future iterations of the compiler may include automatic norm bounding and support for more complex recursive 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