Benchmarking GPT-4 on Algorithmic Problems: A Systematic Evaluation of Prompting Strategies

Flavio Petruzzellis, Alberto Testolin, Alessandro Sperduti

Introduction: The Challenge of Systematic Generalization

Large Language Models (LLMs) have demonstrated remarkable proficiency in natural language tasks, yet their capacity for true algorithmic reasoning remains a subject of intense debate. A fundamental hallmark of intelligence is systematic generalization: the ability to apply learned rules to problems of increasing complexity. For instance, a model that understands addition for two numbers should theoretically be able to extend that logic to ten numbers. This paper investigates whether current state-of-the-art models like GPT-4 possess this capability or if they rely on pattern matching that fails as problem depth increases.

Experimental Methodology

The researchers conducted a comparative evaluation of GPT-4, GPT-3.5, and the Neural Data Router (NDR)—a specialized Transformer variant designed for iterative task simplification. To push the boundaries of these models, seven distinct prompting strategies were tested:

  • Zero-shot and Few-shot (3 examples) learning.
  • Role Assignment (e.g., "You are a mathematician").
  • Chain-of-Thought (CoT): Both Symbolic (intermediate equalities) and Verbal (natural language explanations).
  • Zero-shot CoT: Utilizing the prompt "Let's think step-by-step."
  • Self-consistency: A majority-vote approach using five independent model outputs.

Benchmarking Datasets

The study utilized three synthetic benchmarks where difficulty is controlled by Nesting depth ($N$) and Number of operands ($O$):

  1. ListOps: Logical operations (Min, Max, Sum Modulo 10) on nested integer lists.
  2. Arithmetic: Expressions involving $+$, $-$, and $*$ with results taken modulo 100.
  3. Algebra: Symbolic simplification of complex expressions (e.g., reducing $(((30xy + 33xy) + (-80xy + 62xy)) - 62xy)$).

The "Nesting Wall" and Generalization Gaps

A primary finding is the existence of a "Nesting Wall." Models handle increases in the number of operands ($O$) much better than increases in nesting depth ($N$). As formulas become more deeply nested, performance degrades sharply, suggesting that the recursive logic required for deep nesting is a significant hurdle for current architectures.

Accuracy and loss curves showing the significant gap between IID and OOD generalization across the three algorithmic domains.

As shown in the training dynamics above, while models can achieve high accuracy on in-distribution (IID) data, their performance on out-of-distribution (OOD) tasks—representing true systematic generalization—remains significantly lower, particularly in the Arithmetic and Algebra domains.

Comparative Performance Analysis

GPT-4, particularly when paired with Self-consistency and Zero-shot CoT, emerged as the top performer across all tasks. Advanced prompting served as a "math tutor," significantly raising the performance floor for medium-difficulty problems. In the Arithmetic task, CoT provided a boost of up to 40%, likely by helping the model manage the working memory required for multi-step calculations.

Performance heatmaps for NDR, GPT-3.5, and GPT-4 across different levels of nesting and operand counts.

Despite these gains, the comparative heatmaps illustrate that even GPT-4 hits a ceiling. On the most complex data splits (Nesting=4, Operands=4), accuracy for all models dropped precipitously. While GPT-4 dominates overall, reaching 79% on ListOps and 58% on Arithmetic, the specialized NDR architecture remained competitive on certain hard ListOps splits, highlighting the potential value of task-specific inductive biases.

Conclusion

The study concludes that while GPT-4 represents a major advancement, it does not yet possess robust algorithmic generalization. Prompting strategies optimize the use of existing knowledge but do not fundamentally solve the "complexity wall" encountered in deeply nested problems. Future research may need to move beyond prompting toward architectural innovations, such as ad-hoc Transformer variants that inherently support recursive, iterative logic.

Summary updated

BibTeX
@inproceedings{petruzzellis2024benchmarking,
  author = {Flavio Petruzzellis and Alberto Testolin and Alessandro Sperduti},
  title = {{Benchmarking GPT-4 on Algorithmic Problems: A Systematic Evaluation of Prompting Strategies}},
  booktitle = {International Conference on Computational Linguistics},
  year = {2024},
}
Figure