Can Transformers Reason Logically? A Study in SAT Solving
Leyan Pan, Vijay Ganesh, Jacob Abernethy, Chris Esposo, Wenke Lee
TL;DR
The paper analyzes whether decoder-only Transformers can perform formal logical reasoning for SAT by constructing a CoT-based solver that simulates DPLL backtracking. It provides both a theoretical construction showing feasibility for $3$-SAT and a practical compiler, PARAT, to instantiate the weights and validate correctness on DIMACS 3-SAT instances. Empirically, training on CoT traces yields strong out-of-distribution generalization for the same problem length but fails to generalize to longer instance sizes, highlighting fundamental length-generalization limits. The work advances theoretical foundations for Transformer reasoning in formal domains and offers a practical toolchain for compiling and evaluating such constructions.
Abstract
We formally study the logical reasoning capabilities of decoder-only Transformers in the context of the boolean satisfiability (SAT) problem. First, we prove by construction that decoder-only Transformers can decide 3-SAT, in a non-uniform model of computation, using backtracking and deduction via Chain-of-Thought (CoT). %We prove its correctness by showing trace equivalence to the well-known DPLL SAT-solving algorithm. Second, we implement our construction as a PyTorch model with a tool (PARAT) that we designed to empirically demonstrate its correctness and investigate its properties. Third, rather than \textit{programming} a transformer to reason, we evaluate empirically whether it can be \textit{trained} to do so by learning directly from algorithmic traces (``reasoning paths'') from our theoretical construction. The trained models demonstrate strong out-of-distribution generalization on problem sizes seen during training but has limited length generalization, which is consistent with the implications of our theoretical result
