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

Programming by Rewards

Nagarajan Natarajan, Ajaykrishna Karthikeyan, Prateek Jain, Ivan Radicek, Sriram K. Rajamani, Sumit Gulwani, Johannes GehrkearXiv 2020

Introduction

In modern software engineering, developers frequently encounter the challenge of optimizing "decision functions"—small but critical subroutines that determine system behavior through thresholds, heuristics, or ranking logic. Examples include setting timeout values for database queries or selecting the most relevant result in a search algorithm. Traditionally, these functions are either manually tuned through tedious trial and error or optimized using Reinforcement Learning (RL) and white-box synthesis. However, these methods often struggle with sample efficiency or require full access to the system's internal code.

This paper introduces Programming by Rewards (PBR), a novel framework that bridges the gap between program synthesis and reinforcement learning. By treating the program structure as a white-box Domain-Specific Language (DSL) while interacting with the broader system environment as a black box, PBR achieves high sample efficiency and flexibility in complex, real-world environments.

The Problem: The Gap Between Synthesis and Learning

Optimizing decision functions currently relies on three primary, yet flawed, approaches:

  1. Manual Tuning: Developers spend significant time "magic-number hunting." This process is brittle, time-consuming, and fails to adapt when the system environment changes.
  2. Sketch-based Synthesis: Tools like Sketch can automatically find optimal values but require the entire system to be a "white-box." For massive, proprietary, or highly complex systems, providing a complete, readable code representation is often impossible.
  3. Reinforcement Learning (RL): RL treats the entire system as a black box. While flexible, it typically requires a prohibitive number of samples to converge, particularly when the action space—the possible parameter values—is continuous or high-dimensional.

PBR addresses this "middle path," seeking to optimize code within large-scale systems without needing to model the system's internals or execute millions of training trials.

The PBR Framework

The core of PBR is the synthesis of programs within a DSL called IMP, which consists of loop-free if-then-else statements and linear operations. The framework relies on several key technical innovations:

The "Middle Path" Architecture

PBR treats the decision function $f$ as a white-box (where the structure is known) and the reward function $r$ (representing the system's performance) as a black-box. This allows the system to optimize the function based on the feedback it receives from the environment without needing to understand the environment's underlying logic.

Gradient Estimation via Perturbation

Because the reward function is a black box, direct gradient calculation is impossible. PBR overcomes this using a "perturbation trick": it queries the reward at random points around the current decision parameters to estimate a noisy but unbiased gradient, allowing for continuous optimization.

EntropyNet

To synthesize discrete decision trees using continuous optimization techniques like gradient descent, the authors developed EntropyNet. This architecture maps the discrete structure of a decision tree onto a differentiable, three-layer neural network. This enables the simultaneous learning of both the program's logic (the branches) and its constants (the leaves).

Sample Complexity

By exploiting the known structure of the DSL, the authors demonstrate that learning complexity depends on the number of decisions made rather than the total number of parameters. This structural awareness makes PBR significantly faster than standard RL methods.

Experimental Evaluation

The researchers evaluated PBR across a variety of demanding environments, ranging from industrial frameworks to synthetic benchmarks:

  • PROSE: An industrial program synthesis framework from Microsoft. PBR was used to optimize ~70 ranking heuristics for spreadsheet data transformation.
  • Synthetic Benchmarks: Problems like "XOR" and "Slates" were used to test the framework's ability to learn non-linear decision boundaries.
  • Fermat & Parrot Benchmarks: These included quantitative synthesis problems such as thermostat and aircraft control, as well as polynomial approximations of complex trigonometric functions.

Key Results and Insights

The evaluation yielded three primary insights:

  1. Superior Accuracy: In the PROSE codebase, PBR synthesized heuristics that achieved 668/740 accuracy. This outperformed previous state-of-the-art machine learning approaches (606/740) and neared the performance of domain experts (703/740) who had spent years hand-tuning the system.
  2. Extreme Efficiency: PBR reached high-quality solutions in approximately 250 reward function calls. In comparison, standard RL methods failed to converge even after thousands of queries due to the size of the search space.
  3. Scalability: PBR proved to be orders of magnitude faster than white-box tools like Sketch. While Sketch timed out after an hour on problems involving only eight parameters, PBR solved them in seconds.

Limitations and Future Work

While PBR represents a significant step forward, it has limitations. The theoretical guarantees currently rely on the reward function being relatively "well-behaved" (concave and Lipschitz continuous). Additionally, the DSL is limited to loop-free linear programs; expanding PBR to handle complex loops or data structures remains a challenge for future research. Finally, the authors suggest that incorporating user-provided "sketches" or partial programs could further accelerate the synthesis process.

Conclusion

Programming by Rewards offers a powerful new paradigm for software optimization. By combining the structural advantages of program synthesis with the environmental flexibility of reinforcement learning, PBR enables the automatic generation of high-performing code in complex, black-box systems where traditional methods fail.

Summary updated

BibTeX
@misc{natarajan2020programming,
  author = {Nagarajan Natarajan and Ajaykrishna Karthikeyan and Prateek Jain and Ivan Radicek and Sriram K. Rajamani and Sumit Gulwani and Johannes Gehrke},
  title = {{Programming by Rewards}},
  year = {2020},
  eprint = {2007.06835},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2007.06835},
}
Figure