Correct and Optimal: The Regular Expression Inference Challenge

Mojtaba Valizadeh, Philip John Gorinski, Ignacio Iacobacci, Martin Berger

Abstract

The Regular Expression Inference Challenge (REIC) is a novel benchmark designed to evaluate whether machine learning models can achieve structural optimality in addition to logical correctness. By requiring models to find the minimal regular expression that separates positive and negative string sets, the challenge highlights significant gaps in the combinatorial reasoning capabilities of current Large Language Models (LLMs). Results show that while specialized models can achieve high precision, finding truly minimal solutions remains a formidable task.

Introduction

In software engineering and program synthesis, "correctness" is often treated as the sole metric of success. However, high-quality code must also be efficient, concise, and maintainable. This paper introduces Regular Expression Inference (REI) as a rigorous "yardstick" for this correctness-vs-optimality trade-off.

Given a set of positive strings $P$ and negative strings $N$, the task is to find a regular expression $r$ that accepts all $s \in P$ and rejects all $s \in N$. While generating a correct expression is trivial (e.g., a simple union of all strings in $P$), finding the minimal expression according to a specific cost function is an NP-hard problem. This challenge forces models to balance logical precision with structural optimization, representing a key hurdle on the path toward Artificial General Intelligence (AGI).

Methodology

The researchers established a formal framework for REI that includes:

  • Formal Grammar: Support for standard operators (concatenation, union, Kleene star) and extended ones (intersection, complement, restriction).
  • Configurable Cost Functions: Difficulty is tuned using an 8-tuple of integers that assigns weights to different operators, allowing for various definitions of "optimality."
  • Ground Truth Generation: The authors utilized a state-of-the-art GPU-accelerated algorithmic solver to identify provably minimal expressions, providing a gold standard for evaluation.
  • Baseline Models: The benchmark compares a "Trivial" baseline (union of all positives), retrieval-based methods, a 15.5B parameter code LLM (StarChat$\beta$), and a specialized 300M parameter model (ReGPT) trained specifically on REI data.

Datasets

The authors released four large-scale datasets (DS1-DS4) containing over 250,000 instances. These datasets vary by operator sets and cost functions to test model flexibility and adaptability to different optimization constraints.

Table 1: Characteristics of the four datasets (DS1-DS4), detailing the alphabet, operator sets, cost functions, and instance counts.

DS1 and DS2 utilize basic operators, while DS3 and DS4 introduce extended operators like intersection and complement. Sampling methods were designed to ensure models could not rely on simple length-based heuristics to find solutions.

Results and Analysis

The experimental results reveal a stark contrast between precision and optimality. While the "Trivial" baseline achieves 100% precision, its cost ratio is nearly four times that of the optimal solution, highlighting the inadequacy of correctness-only metrics.

Table 2: Performance metrics across datasets, comparing precision (Prec), minimality (Min), and cost ratios for various models.

Key Insights

  • Small and Specialized Wins: The 300M parameter ReGPT significantly outperformed the 15.5B parameter StarChat$\beta$. This suggests that for formal logic tasks, task-specific training data is currently more impactful than raw model scale.
  • The Optimality Gap: Even the best-performing model, ReGPT, only found the truly minimal solution in approximately 12-13% of cases globally. However, its solutions were generally close to optimal, averaging a cost ratio of 1.09x compared to the Trivial baseline's 3.86x.
  • LLMs are Not Yet Optimizers: StarChat$\beta$ performed poorly, often failing to achieve even basic precision. This indicates that reasoning through combinatorial optimization remains a major weakness for general-purpose LLMs.

Conclusion

The REIC benchmark demonstrates that achieving structural minimality is significantly harder than achieving logical correctness. While specialized models like ReGPT show promise, finding truly optimal solutions remains an open challenge. Future work may involve Reinforcement Learning (RL), using the cost function as a direct reward signal to guide models toward more efficient code generation. Currently limited to a binary alphabet, scaling the challenge to the full ASCII set remains a primary goal for future research.

Summary updated

BibTeX
@inproceedings{valizadeh2024correct,
  author = {Mojtaba Valizadeh and Philip John Gorinski and Ignacio Iacobacci and Martin Berger},
  title = {{Correct and Optimal: The Regular Expression Inference Challenge}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {2024},
}
Figure