arXiv:2610.40378cs.LOOct 2026

Manuscript Offprint

arXiv:2610.40378

On Deciding the Constraint Loop Problem in Dimension Two

Daria Goliasova, Toghrul Karimov

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Recently, Guilmant, Lefaucheux, Ouaknine, and Worrell [2] proved decidability of the termination problem for linear constraint loops over two real-valued variables, thus settling a well-known open problem. Their algorithm is based on a theoretical result that such a loop does not terminate if and only if it has a witness of an infinite run of a specific shape. By analysing the structure of the witness carefully, we show that termination such loops can be decided in polynomial time, improving on the polynomial space bound argued by Guilmant et al. We also present an efficient implementation of the polynomial-time algorithm based on the satisfiability modulo theories (SMT) solver Z3.

1 Introduction

The problem of program verification is essential in modern software engineering. Ensuring that a program executes safely without getting stuck in infinite execution requires proving loop termination. In this work, we focus on termination for non-deterministic linear constraint loops, which has been extensively studied: see [1] for a recent survey. In this setting, both the loop guard and the loop update are specified as conjunctions of linear inequalities over program variables:

whileB⋅x≥bdoA⋅(x,x′)≥awhile B\cdot x\geq b do A\cdot(x,x^{\prime})\geq a

where x,x′x, x' are respectively the column vectors of program variables before and after the loop iteration. A, B are matrices with rational entries, a, b are vectors of rational numbers. By folding the guard condition into the update we can write every such loop as

whileTruedoA⋅(x,x′)≥b.while True do A\cdot(x,x^{\prime})\geq b.

The termination question (over R\mathbb{R}) is then equivalent to existence of an infinite sequence (xn)n∈N(x_n)_{n\in\mathbb{N}} of vectors of real numbers such that A⋅(xn,xn+1)≥bA\cdot(x_n,x_{n+1})\geq b for all n∈Nn\in\mathbb{N}.

Given (A,b)(A,b) as above, we define

K={(x,x′):x to x′ is a valid transition of the loop. i.e. A⋅(x,x′)≥b}K = \{(x, x') : x \text{ to } x' \text{ is a valid transition of the loop. i.e. } A \cdot (x, x') \geq b\}.

∗^{*}This is a report of the results produced by the first author while she was a research intern at the MPI-SWS, supervised by the second author.

The set KK contains all information about the loop. When x,x′∈R2x, x' \in \mathbb{R}^2, i.e. the program has two variables and K⊆R4K \subseteq \mathbb{R}^4, recently [2] gave an algorithm for deciding termination. Their argument is that the loop does not terminate if and only if there exists a witness as below; from the witness it is then easy to extract an explicit infinite trajectory. A witness consists of a linear map M:R2→R2M: \mathbb{R}^2 \to \mathbb{R}^2, a closed convex cone C⊆R2C \subseteq \mathbb{R}^2, and vectors v,w∈R2v, w \in \mathbb{R}^2 satisfying four conditions:

• M⋅C⊆C,M \cdot C \subseteq C,

• ∀z∈C:(z,Mz)∈rec(K),\forall z \in C: (z, Mz) \in \mathrm{rec}(K),

• (v,w)∈K,(v, w) \in K,

• w−v∈C.w - v \in C.

Here

rec⁡(K)={z ⁣:w+cz∈Kforallc≥0andw∈K}\operatorname{rec}(K)=\{z\colon w+cz\in K for all c\geq0 and w\in K\}

is the recession cone of K. The witnessing infinite trajectory is then [2, Prop. 27]

v,w,v+M(w−v),v+M(w−v)+M2(w−v),⋯v,\quad w,\quad v+M(w-v),\quad v+M(w-v)+M^{2}(w-v),\quad\cdots

So we have the partial sums of the geometric sequence (Mn(w−v))n∈N(M^n(w - v))_{n \in \mathbb{N}} translated by vv; this form of a witnessing infinite trajectory was already known in [3].

The original goal of this project was to implement an automated verification tool in Python using the Z3 SMT solver to search for such non-termination witnesses. However, we quickly realised that the naive translation of the requirements into first-order logic requires quantifier alternations (albit with a fixed number of variables) that Z3 cannot handle. In fact, Guilmant et al. note the complexity of checking existence of a witness as PSPACE, which comes from the aforementioned naive translation. We therefore first show how to decide existence of a witness in polynomial time, and then implement that in Z3. The implemented tool is available at loop-termination.mpi-sws.org.