Loop Termination and Generalized Collatz Sequences
Abstract
Linear-constraint loops are programs whose transition relation is specified by a system of linear inequalities. The termination problem asks, given a loop, whether it admits an infinite computation. Decidability of termination remains open for linear-constraint loops over integers, rationals, and reals. We focus on loops over integers and show that they are tightly connected to generalized Collatz sequences – integer sequences generated by maps that are linear on each residue class modulo a fixed natural number. We prove that termination of one-variable linear-constraint loops is decidable in polynomial time, provided a long-standing conjecture about generalized Collatz sequences holds. Conversely, we show that any decision procedure for one-variable loops would prove or refute specific instances of this conjecture, which remain open. Moreover, we show that if a one-variable loop has a cyclic trace, then it also has a cyclic trace of length at most two.
Keywords and phrases:
Program Verification, Loop Termination, Generalized Collatz Sequences, Linear-Constraint LoopsCategory:
Track B: Automata, Logic, Semantics, and Theory of ProgrammingFunding:
Mishel Carelli: This work was supported by the European Research Council (ERC) Grant HYPER (No. 101055412).2012 ACM Subject Classification:
Theory of computation Logic and verificationAcknowledgements:
I want to thank Arkadiy Aliev, Bernd Finkbeiner, and Joël Ouaknine for the useful discussions.Editors:
Sayan Bhattacharya, Danupon Nanongkai, Michael Benedikt, and Gabriele PuppisSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
1 Introduction
Termination analysis is a long-standing topic in theoretical computer science. The Halting Problem – deciding whether a Turing machine halts on a given input – is undecidable, going back to Turing’s original work. Nevertheless, termination can become decidable when restricted to certain classes of programs.
In this paper, we analyze the open problem of termination for Single-Path Linear-Constraint Loops (SLC). This problem originates in program analysis and verification, where incomplete but efficient approaches such as ranking functions [22] and transition invariants [21] are used as building blocks in verification tools to prove termination and other liveness properties [8, 21, 10] and in Horn Clauses solvers [5, 27].
SLCs are loops of the form
| (1) |
Here, is the vector of values of the program variables in the current step, and denotes their values in the next step. Moreover, and are matrices with rational coefficients, and and are rational vectors. Later in the paper, we introduce an equivalent definition with the loop guard omitted. The decision problem is: given such a loop, does there exist an infinite computation with program variables taking values in from some initial state?
The question of whether this problem is decidable was posed two decades ago [7], and remains open to this day, not only for loops over , but also over and . Recently, decidability over has been established in the two-variable case [9].
Decidability of termination varies across loop classes. We now discuss two additional classes of linear loops to illustrate the current landscape.
On the positive side, a prominent decidable class of linear loops called affine SLCs, in which the transition is deterministic and has the form
Termination of affine SLCs has been proved decidable over [26] – via spectral analysis of – over [7], by symbolic reasoning about matrix powers through eigenvalues, and over [11], using different tools from geometry of numbers, such as the Khachiyan–Porkolab result on deciding whether a convex semi-algebraic set contains an integer point.
On the negative side, another relevant class of linear loops called Multi-Path Linear-Constraint Loops, which allows conditional choice among several linear updates:
Termination of such multi-path loops is undecidable over and [6] and over [1], even for , via encodings of counter machines.
In [7], Braverman asked: “How much nondeterminism can be introduced in a linear loop with no initial conditions before termination becomes undecidable?” Motivated by this question and in light of the subsequent results, SLCs occupy an intriguing middle ground between deterministic, decidable affine SLCs and highly expressive, undecidable multi-path loops. Because nondeterminism in SLCs is convex, it does not allow for modeling the unstructured nondeterminism of counter machines, at least not in a straightforward way.
In [2], the authors show that allowing a single irrational coefficient makes SLC termination undecidable over , and they describe the SLC termination problem as “the most intriguing” among loop-termination problems.
For a complete explanation of these results and further references, we refer the reader to the recent survey on linear loop termination [3].
In this work, we study the SLC termination problem for the case of one variable. While this restriction may seem severe, we show that this problem is deeply non-trivial even for one-variable loops, connecting it with a long-standing number theoretic conjecture about generalized Collatz sequences.
The study of Generalized Collatz sequences is a long-standing topic in number theory [18, 17, 15, 19, 13, 16]. These integer sequences are generated by generalized Collatz mappings of the form
The Uniform Distribution conjecture [18] asserts that every unbounded generalized Collatz sequence is uniformly distributed modulo for every . We formulate a weaker statement, the Reachability Conjecture, which posits that every sequence generated by generalized Collatz mappings of a certain type called weak Collatz mappings, reaches a certain residue class modulo at least once. We prove the Reachability Conjecture for .
Our main result shows that, if the Reachability Conjecture holds, then termination of one-variable SLCs is decidable in polynomial time.
For the other direction, we show that any algorithm deciding termination of one-variable SLCs would, given a weak Collatz mapping, determine whether the Reachability Conjecture holds for all sequences generated by that mapping. All cases with modulus remain open. This suggests that further progress on SLC decidability will require a deeper understanding of generalized Collatz sequences.
Let us give the high-level explanation of the results of this paper and its structure.
Section 2 introduces the basic definitions and notation. In particular, we define the SLC termination problem and split it into two subproblems: deciding the existence of cycles (finite traces from some state to itself), and deciding the existence of self-avoiding traces (infinite traces that never repeat a state).
Section 3 studies cycles. We show that deciding the existence of a cycle of a bounded length can be reduced to an instance of Integer Linear Programming problem. The main result of this section is that for a one-variable loop, the existence of any cycle implies the existence of a cycle of length at most two; hence cycle-detection problem is decidable for one-variable loops.
Section 4 introduces generalized Collatz sequences, and states the Uniform Distribution and Reachability Conjectures. We prove the Reachability conjecture for the case , and we prove that a one-variable SLC termination-checking algorithm, if it existed, could verify specific open instances of this conjecture.
Section 5 analyzes self-avoiding traces and shows that, assuming the Reachability Conjecture, termination of one-variable SLCs is decidable in polynomial time. The proof is geometric in nature. We view the transition relation as a polyhedron in and analyze its Minkowski-Weyl decomposition. Intuitively, we identify where the transition polyhedron “points to”. Simplifying, the self-avoiding trace exists if the polyhedron points in the direction where the absolute value of the variable grows. However, several corner cases arise, in one of which, the trace of SLC forms a weak Collatz sequence, which avoids a certain residue class modulo . If the Reachability conjecture holds, we can conclude that this kind of execution needs to terminate. Otherwise, the presented approach results in a semi-algorithm, which does not give an answer in these specific cases.
Section 7 summarizes the results.
2 Preliminaries
2.1 Notation
We denote the sets of natural numbers, integers, rationals, and reals by , and , respectively. The sets of positive, negative, and nonnegative real numbers are denoted by , , and .
Given , we write for its set of integer points.
Given and , define the slice .
Vectors are collinear if there exists such that ; we write . If and are not collinear, we write .
For , denotes the greatest natural number that divides both and .
For define
2.2 Convex sets and the Minkowski–Weyl theorem
Given , the Minkowski sum is
A set is convex if for all and all , we have .
The topological closure of is denoted (the set of limits of the sequences of elements of ). A set is closed if .
Intersections of families of closed sets are closed, and intersections of families of convex sets are convex.
Definition 1.
Let .
-
1.
A convex hull of is defined by
-
2.
A nonnegative (conic) hull is defined by
A convex cone is a set such that for every and every , we have and . Every convex cone is a convex set.
Definition 2.
Let be a nonempty convex set. The recession cone of is
For every nonempty convex , is a closed convex cone. A cone is pointed if .
The following classical result appears in §8.9 of [24].
Theorem 3 (Minkowski–Weyl Theorem).
Let . The following are equivalent:
-
1.
is a polyhedron, i.e., for some and .
-
2.
There exist and , such that
Moreover, if is given by linear inequalities with rational coefficients, then and can be chosen with rational entries.
Note that any polyhedron is closed and convex, because every linear inequality defines a closed half-space in and is an intersection of finitely many half-spaces.
The following result trivially follows from basic results in convex geometry, but we present the proof of this exact formulation for the sake of completeness.
Proposition 4.
The following statements hold for closed convex cones .
-
1.
can be represented as for some with .
-
2.
If and , then contains no line in .
-
3.
If cannot be generated by two vectors, then is either a half-plane or the whole plane.
Proof.
By §8.9 of [24], decomposes as , where is the lineality space and is a pointed cone.
If , then .
Assume is a line, say , and . Then , where and are the open half-planes with boundary . If for some , then . Hence is either the line or, if there exists , a half-plane .
Finally, if , then is pointed and therefore generated by two vectors (see, e.g., Example 2.39 in [25]); in this case, it cannot contain a line by definition of pointedness.
The next statement is Corollary 8.3.3 in [23].
Proposition 5 (Recession cone of an intersection).
If and are closed convex sets with , then .
2.3 Loops
We consider Single-Path Linear-Constraint Loops (SLC). Throughout, SLCs are over the integers.
The vector of variables is . A state is a valuation over integers, i.e., a vector in . The vector of variables at the next step is . An SLC is specified by a system of linear inequalities
| (2) |
where and .
Remark 6.
This definition differs from (1) in the Introduction because it omits an explicit loop guard. The two forms are expressively equivalent, since the guard can be encoded in the transition relation.
The transition polyhedron is the set of vectors satisfying (2).
Remark 7.
Since we study integer-valued loops, the actual transitions between states are elements of . We nevertheless work over the reals when convenient for proofs.
We identify an SLC with its transition polyhedron , and denote it by . We denote the size of the binary encoding of and as .
A trace is a sequence of states such that for all .
The SLC termination problem is to decide, for a given SLC, whether it has an infinite trace.
2.4 Cycles and Self-avoiding Traces
We divide the termination problem into two problems for two different types of infinite traces.
For an SLC, a cycle of length is a finite trace . The existence of a cycle implies the existence of an infinite trace. The converse need not hold:
Example 8.
The SLC has no cycle but admits an infinite trace.
An infinite trace is self-avoiding if for all .
Observation 9.
An SLC has an infinite trace if and only if it has a cycle or a self-avoiding trace.
In the remainder of the paper, we analyze the problems of deciding the existence of a cycle and the existence of a self-avoiding trace separately for a given SLC.
3 Cycles
3.1 Bound on a cycle length
Although cycles are finite objects (unlike self-avoiding traces), deciding their existence for an SLC remains nontrivial, since a cycle can have arbitrary length. By contrast, deciding the existence of a cycle whose length is bounded is decidable.
Proposition 10.
Given an SLC and , deciding whether has a cycle of length at most is in with respect to .
Proof.
It is known that the feasibility problem for Integer Linear Programming (ILP) – deciding whether a rational polyhedron contains an integer point – is -complete [20]. We give a polynomial-time reduction from our problem to ILP.
Given and , for each we construct an ILP instance encoding the existence of a cycle of length exactly :
Then has a cycle of length at most iff one of the polyhedra contains an integer point. Each ILP instance has size .
Proposition 26 of [9] shows that for Linear-Constraint Loops over or , the existence of a bounded infinite sequence is equivalent to the existence of a cycle of length one. The next proposition shows that this equivalence fails over .
Proposition 11.
For every , there exists an SLC over variables that has a cycle of length and no cycles of smaller length.
Proof.
Fix and consider the set of states . Take any cycle on , so that each appears exactly once; . Let be the set of transitions of , so . Let , which as a convex hull of a finite set of integer points, can be defined as an SLC. We claim that , i.e., has no integer points other than its vertices in . This implies that the minimal cycle length of is .
Suppose, to the contrary, that there exists . Enumerate and write with and . Without loss of generality, assume and choose a coordinate such that (such a exists since ). Because is an integer and each , the only way the convex combination can be an integer is if all with are equal. This contradicts . Hence, no such exists.
Since there is no universal bound on the minimal cycle length, it is natural to ask whether a bound depending on the number of variables exists.
Question 12.
For every , does there exist a constant such that every loop over variables that has a cycle also has a cycle of length at most ?
If the answer to Question 12 is positive, then cycle detection reduces to checking for cycles of length at most . If is computable, this yields decidability of cycle detection.
There exist convex sets that are not polyhedra (e.g., convex sets defined by quadratic inequalities). We now show that a positive answer to Question 12 extends from polyhedral relations to arbitrary convex relations.
Proposition 13.
Suppose that every SLC with a cycle also has a cycle of length at most . Then any convex relation with a cycle also has a cycle of length at most .
Proof.
If has a cycle represented by the set of transitions , then by convexity. The polyhedron has a cycle and therefore, by hypothesis, has one of length at most . This cycle is contained in .
3.2 One variable case
The following Theorem shows that the answer to Question 12 is positive for with .
Theorem 14.
If an SLC has a cycle, then it has a cycle of length at most .
Sketch of proof.
Let us informally explain the idea of the proof with an illustration from Figure 1(a). Consider the set of transitions of a cycle (the black points). The center of this set lies on the diagonal (the green point). If it has integer coordinates, then we obtain a length-one cycle. Otherwise, it lies on a unit square in the integer lattice. Two vertices of this unit square lie on the diagonal representing length-one cycles (the blue points). The other two vertices lie on the anti-diagonal, representing a length-two cycle (the red points). We then consider several cases, branching on the signs of different values, such as the largest value among the states of the cycle. In some cases, we show that contains points on the diagonal below or above the blue points, yielding the existence of the length-one cycles. In the remaining cases, we show contains points on the anti-diagonal on both sides of the green point, implying the existence of a length-two cycle. The formal argument is presented in Section 6.
4 Generalized Collatz sequences
The classical Collatz problem remains open. A key difficulty is its residue-class–dependent dynamics modulo . Several generalizations have been studied, replacing the modulus by other moduli and considering related piecewise-linear maps [12]. In particular, the framework proposed by Möller [19] has been investigated both theoretically and empirically [16]. In this paper, we focus on the Uniform Distribution Conjecture of Matthews and Watts [18], formulated for Möller’s generalization.
Let be a positive integer with . Let be nonzero integers such that for every . Let be a set of integers with the property that for each . Then the generalized Collatz mapping is given by
For we define the sequence recursively by
A sequence is called unbounded if for every there exists such that .
We recall a longstanding number-theoretic conjecture, first stated by Matthews and Watts [18] and further discussed, with empirical support, in [16].
Conjecture 15 (Uniform Distribution Conjecture).
If the sequence is unbounded, it is uniformly distributed modulo for each , i.e.
for .
In this paper, we state a weaker version of this conjecture. First, let us define a more restricted class of generalized Collatz mappings.
Let be a positive integer , let be a nonzero integer with , and let be an integer. Then a weak Collatz mapping is given by
Conjecture 16 (Reachability Conjecture).
Let be a weak Collatz mapping. Suppose for some the sequence is unbounded. Then there exists such that .
The proofs of the next two propositions are presented in Section 6.
The following proposition implies that Conjecture 16 holds for mappings with .
Proposition 17.
Let be a generalized Collatz mapping with . Suppose for some the sequence is unbounded. Then it visits at least two residue classes modulo .
The next proposition links weak Collatz sequences to self-avoiding traces.
Proposition 18.
There exists a linear-time algorithm that takes as input a weak Collatz mapping with , and outputs two one-variable SLCs, and , such that:
-
1.
has an infinite trace if and only if there exists such that, for every ,
-
2.
has an infinite trace if and only if there exists such that, for every ,
Proposition 18 implies that any decidability procedure for one-variable SLC termination, if it existed, could, given a weak Collatz mapping, determine whether the Reachability Conjecture holds for this particular mapping. This suggests that progress on decidability requires progress in understanding the behavior of weak Collatz sequences. We conclude with an example of a mapping for which the Reachability Conjecture remains, to our knowledge, open, and we are unaware of any results that imply it.
Example 19.
Consider the weak Collatz mapping
which can be rewritten as
For this particular , it remains open whether it is true that for every there exists such that .
Proposition 18 implies that this question is equivalent to the termination question for the SLC defined by
On the Figure 1(b), is depicted as a red area, bounded by the two lines and , starting from , since for , .
5 Self-avoiding Traces
The following theorem is the main result of the paper.
Theorem 20.
If the Reachability Conjecture holds, then the termination of SLCs over one variable is decidable in polynomial time.
This section is devoted to proving Theorem 20. The treatment of cycles is given in Section 3. Now we turn our attention to self-avoiding traces. To determine the existence of self-avoiding traces, we make a case analysis, based on the geometric placement of in , split into four Lemmas 21, 23, 24, and 25. Before stating these lemmas, we introduce an auxiliary SLC that splits into different parts.
Define the following sets.
Note that the topological closure of , and are
Recall that any SLC can, by Theorem 3, be represented as
with . Moreover, since is defined by the set of integer linear inequalities, we may assume that all and have rational coefficients.
The following case distinction, presented in four lemmas, is aimed at characterizing when a given SLC admits a self-avoiding trace, and is based on the number of generators of and on the intersection of with and . Each lemma treats SLCs whose recession cone has a specific number of generators.
Lemma 21.
Let be an SLC. Suppose and . Then:
-
1.
If , then the loop has a self-avoiding trace.
-
2.
If , then the loop does not have a self-avoiding trace.
-
3.
If and , then the loop has a self-avoiding trace.
-
4.
If and , then the loop does not have a self-avoiding trace.
-
5.
If and , then the loop has a self-avoiding trace.
-
6.
If and , then the loop does not have a self-avoiding trace.
Sketch of proof.
This lemma handles the case where is pointed and generated by two noncollinear vectors. In this regime, is “large” in the sense that the number of integer points in its vertical slices, , is unbounded as varies. Consequently, we can decide whether the loop admits a self-avoiding trace by inspecting the direction of this cone.
The case where the recession cone intersects , as in Figure 2(a), corresponds to Statement 1. In this case, it points in a direction in which the absolute value of the state increases; thus, admits a self-avoiding trace.
The case where the recession cone does not intersect , as in Figure 2(b), corresponds to Statement 2. In this case, it points only in directions in which the absolute value of the state decreases; thus, does not admit a self-avoiding trace.
The case in which the cone intersects is slightly more delicate and requires analyzing the intersection , which is done in the remaining statements.
The complete proof is given in Section 6.
The next lemma, Lemma 23, treats the case in which is generated by a single vector. In this situation is infinite but “thin”: each vertical slice is bounded. We quantify this thinness via the .
Definition 22.
For and , define the -height of by
Lemma 23.
Let be an SLC. Suppose and for , and GCD. Then:
-
1.
If , and , then the loop has a self-avoiding trace.
-
2.
If , then the loop does not have a self-avoiding trace.
-
3.
If and , then the loop does not have a self-avoiding trace if Conjecture 16 holds.
-
4.
If and , then the loop does not have a self-avoiding trace.
-
5.
If , then the loop does not have a self-avoiding trace.
-
6.
If , then the loop does not have a self-avoiding trace.
-
7.
If and , then the loop has a self-avoiding trace.
-
8.
If and , then the loop does not have a self-avoiding trace.
-
9.
If and , then the loop has a self-avoiding trace.
-
10.
If and , then the loop does not have a self-avoiding trace.
Sketch of proof.
In this case, the cone is again pointed, but it is generated by a single vector. Since the cone is not “large” as in Lemma 21, it requires a more delicate analysis.
The cases where the recession cone does not intersect (Statements 2 and 6) are similar to Statement 2 of Lemma 21 and are handled in the same way.
The cases where the recession cone intersects are the essential ones and correspond to Statements 1, 3, and 4, which are the most important in this Lemma.
The case where the height of is too small, as in Figure 3(a), corresponds to Statement 4. In this regime, traces correspond to a weak Collatz sequence that visits only one residue class. Thus, the non-existence of a self-avoiding trace follows from Proposition 17.
The case where the height of is large enough, as in Figure 3(b), corresponds to Statement 1. This case is analogous to Statement 1 of Lemma 21. Here we show the existence of a self-avoiding trace.
The case where the height of is at least but less than , as in Figure 1(b), corresponds to Statement 3. In this case, every trace is a weak Collatz sequence that visits fewer than residue classes. If the Reachability Conjecture 16 holds, then the loop does not admit a self-avoiding trace.
The complete proof is presented in Section 6.
Lemma 24.
Let be an SLC. Suppose and for , and GCD. Then:
-
1.
If and , then the loop has a self-avoiding trace.
-
2.
If and , then the loop does not have a self-avoiding trace if Conjecture 16 holds.
-
3.
If and , then the loop does not have a self-avoiding trace.
-
4.
If , then the loop does not have a self-avoiding trace.
-
5.
If , then the loop does not have a self-avoiding trace.
-
6.
If and , then the loop has a self-avoiding trace.
-
7.
If and , then the loop does not have a self-avoiding trace.
-
8.
If and , then the loop has a self-avoiding trace.
-
9.
If and , then the loop does not have a self-avoiding trace.
-
10.
If , then the loop does not have a self-avoiding trace.
Sketch of proof.
This lemma treats the case where is a line (i.e., generated by vectors and ). In this setting, is unbounded but “thin”: each vertical slice is bounded. Accordingly, we analyze the height to determine whether a self-avoiding trace exists.
The intuition is the same as in Lemma 23, but the argument requires some additional technicalities. The complete proof is presented in Section 6.
Lemma 25.
Let be an SLC. The following statements hold.
-
1.
If and it cannot be generated by two vectors, then the loop has a self-avoiding trace.
-
2.
If , then the loop does not have a self-avoiding trace.
Sketch of proof.
This Lemma analyzes the remaining two cases. The complete proof is presented in Section 6.
Finally, we are ready to prove the main theorem.
Proof of Theorem 20.
In fixed dimension, integer feasibility for rational polyhedra can be decided in polynomial time [14].
By Theorem 14, cycle detection for a one-variable SLC reduces to checking for cycles of length at most two. Each such check can be expressed as an ILP instance of dimension four, as in Proposition 10, and can therefore be performed in polynomial time.
Moreover, a Minkowski–Weyl decomposition of can be computed in polynomial time [4]. By Lemmas 21, 23, 24, and 25, the remaining analysis consists of a constant number of two-dimensional ILP feasibility checks, obtained by intersecting with the cones , and , and, in certain cases, by computing the height.
It remains to argue that the height checks can also be carried out in polynomial time. If , then all vertical slices are translates of one another; hence, the height is independent of and can be computed from any single slice.
If with , , and , then the height of the slice varies monotonically with : it increases with when and decreases with when .
Since is bounded, there exists such that the absolute values of the coordinates of all points in are bounded by .
Assume . Then for any we have Moreover, if , then Hence, it suffices to check the height at .
If , a symmetric argument shows that it suffices to check the height at .
6 Proofs
6.1 Cycles
First, we state an auxiliary lemma.
Lemma 27.
Let be integers. If , then
Proof.
Define . Note that because .
Hence we obtain
Let us rewrite the expression.
Proof of Theorem 14.
Suppose has a cycle , where all are different states (otherwise we can take a smaller cycle) and . Then for every : and , so
Denote . Consider the translated relation and translated states . Then has a cycle , and the corresponding average satisfies . Thus, without loss of generality, we may assume . If , then there is a cycle of length . Suppose this is not the case.
Let denote the state of with the largest absolute value, and let and be the neighboring states of in . Hence, and are in . Since and all are different, we have . Now we can apply Lemma 27 and obtain
Denote and consider the following cases.
Case 1: or .
In this case, since , either or can be expressed as a convex combination of and , yielding a cycle of length one.
Case 2: .
Note that and and are distinct. Thus, , and , which implies . Hence, the statement follows from Case 1.
Case 3: and .
Since , rewriting , we obtain
If, for some , , then we can take instead of and the statement follows from Case 2. Thus, we can assume that for every we have . Therefore,
Hence inequality can be satisfied only if and or and . Without loss of generality, assume the first case.
Then is the smallest value in . Let denote the predecessor of in .
All states in are different, and the length of is at least , hence . Since , then we can apply Lemma 27 to get
If , then , hence .
It remains to prove the statement for . Since and are in we get that
It is easy to see that points and lie on the interval
because and . Hence, has a cycle of length 2.
6.2 Generalized Collatz Sequences
Proof of Proposition 17.
Assume the contrary, there exist , and such that for every . Hence,
We prove by induction on , that for every
For we get . Assuming the formula for let us prove it for ,
Hence, for every ,
Multiplying it by yields
Since and , we obtain for every that
As this holds for all and , it follows that . Thus . Therefore for all , contradicting unboundedness.
Proof of Proposition 18.
Recall that has the form
Define
Note that,
Therefore every infinite trace of is self-avoiding and corresponds to the unbounded sequence with , and , for every .
For the other direction, if there exists an infinite unbounded sequence of positive values, then, since , from some step it takes values large enough to have . It implies the existence of a self-avoiding trace of .
The proof for
is symmetric.
6.3 Self-avoiding Traces
Let us formulate an auxiliary notation and an auxiliary lemma.
Lemma 28.
Let be nonzero vectors with , , and . Then and .
Proof.
If , then is a line contained in the closed cone , contradicting Proposition 4, since . Thus .
Let us prove that there exists , such that . Denote and . Define . Since and , we obtain , and since they cannot be both equal to . Hence denominator of is nonzero and . A direct computation gives
Since we have , thus . Recall that , hence .
Since , and , we get that is in the interior of , thus, some open neighborhood of is contained in , but any such neighborhood intersects , since . Hence, the statement follows.
Proof of Lemma 21.
-
1.
Without loss of generality assume . The case when follows from the considered one applied to .
The set is a (possibly nonclosed) convex cone as the intersection of two convex cones. Let us prove that it contains at least two noncollinear vectors. Indeed, for the contradiction, suppose there exists a vector , such that every vector in is collinear to . Thus, .
Informally, contains “half of a neighborhood of ”. Formally, for angles , let be the set of vectors such that there exists an angle with and is the image of under rotation by around the origin. Equivalently, , where is the rotation matrix.
Since and , there exists such that either or .
Moreover, since is open and , we can choose small enough such that . Consequently, one of the sets or is contained in , contradicting the assumption that .
Hence, there are two non-collinear vectors . Then
Hence, for sufficiently large , there always exists a transition from to a larger value, thus the loop has a self-avoiding trace.
-
2.
Suppose there is a self-avoiding trace . If there are infinitely many negative and infinitely many positive states, then infinitely many indices satisfy and infinitely many satisfy . Thus, sets and are unbounded. In that case, their recession cones are non-empty, thus, by Proposition 5, there are non-zero vectors and . Hence, by Lemma 28, . Contradiction.
Suppose instead there are only finitely many negative . The case when there are only finitely many positive follows from the considered one for .
Then there are infinitely many such that . By Theorem 3, . Hence, for every , there are and , such that . Consider the normalized vectors along the infinite subsequence with . Since it is an infinite sequence on a compact sphere, it must have a converging subsequence . Since for every holds this sequence must converge to and . Let us prove that .
Assume that . Since converges to , for every there exists , such that for every , . Let us take . Thus, , hence by Proposition 5 , which implies that is bounded by Theorem 3. For every , , but , hence . Since the sequence is unbounded and the set is bounded, the sequence is also unbounded, but it is contained in a bounded set. Thus by contradiction.
Since and we obtain , hence . There exists , such that for every holds , hence , because otherwise , which is impossible, since . Since the set is bounded, the supremum is finite, denote it as . Since from the proven above, for every , . That contradicts the distinctness of and the assumption that there are only finitely many negative .
-
3.
If , then . If , then , hence for any it is always possible to make a transition to . Thus, the loop has a self-avoiding trace.
-
4.
Suppose there is a self-avoiding trace . If there are infinitely many negative and infinitely many positive states, then infinitely many indices satisfy and infinitely many satisfy . Thus, sets and are unbounded. In that case, their recession cones are non-empty, thus, by Proposition 5, there are non-zero vectors and . Hence, by Lemma 28, . Contradiction.
There cannot be only finitely many negative , due to the argument identical to the argument in statement 2 of this lemma.
If it contains only finitely many positive terms, then there is some index with , contradicting .
-
5.
This statement follows from the statement 3 applied to .
-
6.
This statement follows from the statement 4 applied to .
Proof of Lemma 23.
-
1.
Assume . The case when follows from the considered one applied to .
If , then there exists , such that
For any , using we can shift by along , which maps to and adds to the second coordinate. Hence
Since is convex implies that contains at least consecutive points from , hence at least one of them is an integer. Thus .
Since there exists , such that for every , . Hence, . Thus, for every , it is possible to make a transition to a larger value. Hence, the loop has a self-avoiding trace.
-
2.
Assume . The case when follows from the considered one applied to . In that case,
By Proposition 5 the set is bounded. Therefore, any self-avoiding trace would eventually have to make transitions only from to , which is impossible. Hence, no self-avoiding trace exists.
-
3.
Assume . The case when follows from the considered one applied to . The case when follows from the statement 2 of this Lemma.
Denote . There exists , such that Since is convex the points of are of the form for some .
Let us prove that for all ,
(3) Suppose that , then for any , since and , we obtain . Thus, we get (3).
Hence
Non-existence of a self-avoiding trace follows from Conjecture 16, since .
- 4.
-
5.
In that case , so the claim is immediate.
-
6.
If , then
Hence, the set is bounded. Assume there is a self-avoiding trace . Then there are infinitely many , such that . Contradiction.
Proof of Lemma 24.
The proofs of 1, 2, 3, 4, 5, 6, and 7 are analogous to the proofs of Lemma 23, items 1, 3, 4, 5, 6, 7, and 8, respectively.
Assume . Since we have , .
Denote . Take , such that . For every ,
and since , equality holds
Denote , then . Thus . If , then for every trace we have , hence , the loop does not have a self-avoiding trace, thus statement 9 is proved.
If , then let us define a trace by
For every odd we get and , hence this trace is self-avoiding. Thus, statement 8 is proved.
The statement 10 follows from the fact, that if , then the set is bounded, thus an infinite trace can visit only the finite number of different states.
Proof of Lemma 25.
-
1.
If and this cone cannot be generated by two vectors, then by Proposition 4 it is either a whole plane or a (closed) affine half-plane. In the former case, . For the latter case, note that any closed affine half-plane must intersect , hence the argument of Lemma 21.1 applies and yields a self-avoiding trace.
-
2.
If , then is bounded, hence any infinite trace can visit only a finite number of states and thus cannot be self-avoiding.
7 Conclusion
In this paper, we have studied the termination problem for SLCs over . We have observed that a loop has an infinite computation iff it admits either a cycle or a self-avoiding trace.
We first analyzed cyclic traces. For one-variable SLCs, we have proved that the existence of a cycle implies the existence of a cycle of length at most two. An open question is whether, for , there exists a bound such that any -variable loop that has a cycle also has one of length at most .
Next, we have formulated the Reachability Conjecture for weak Collatz sequences – a special case of a long-standing conjecture – and proved it for modulus . We have shown that a decision procedure for one-variable SLC termination would verify the Reachability Conjecture for specific mappings; for most mappings (in particular, all cases with ), the conjecture remains open.
Finally, assuming the Reachability Conjecture, we have established that termination of one-variable SLCs is decidable in polynomial time.
References
- [1] Amir M. Ben-Amram. Mortality of Iterated Piecewise Affine Functions over the Integers: Decidability and Complexity. In Natacha Portier and Thomas Wilke, editors, 30th International Symposium on Theoretical Aspects of Computer Science (STACS 2013), volume 20 of Leibniz International Proceedings in Informatics (LIPIcs), pages 514–525, Dagstuhl, Germany, 2013. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. doi:10.4230/LIPIcs.STACS.2013.514.
- [2] Amir M. Ben-Amram, Samir Genaim, and Abu Naser Masud. On the termination of integer loops. ACM Trans. Program. Lang. Syst., 34(4), 2012. doi:10.1145/2400676.2400679.
- [3] Amir M. Ben-Amram, Samir Genaim, Joël Ouaknine, and James Worrell. Termination analysis of linear-constraint programs, 2025. doi:10.48550/arXiv.2509.06752.
- [4] Mark de Berg, Otfried Cheong, Marc van Kreveld, and Mark Overmars. Computational Geometry: Algorithms and Applications. Springer-Verlag TELOS, Santa Clara, CA, USA, 3rd ed. edition, 2008.
- [5] Tewodros A. Beyene, Corneliu Popeea, and Andrey Rybalchenko. Solving existentially quantified horn clauses. In Natasha Sharygina and Helmut Veith, editors, Computer Aided Verification, pages 869–882, Berlin, Heidelberg, 2013. Springer Berlin Heidelberg. doi:10.1007/978-3-642-39799-8_61.
- [6] Vincent D. Blondel, Olivier Bournez, Pascal Koiran, Christos H. Papadimitriou, and John N. Tsitsiklis. Deciding stability and mortality of piecewise affine dynamical systems. Theor. Comput. Sci., 255(1–2):687–696, March 2001. doi:10.1016/S0304-3975(00)00399-6.
- [7] Mark Braverman. Termination of integer linear programs. In Thomas Ball and Robert B. Jones, editors, Computer Aided Verification, pages 372–385, Berlin, Heidelberg, 2006. Springer Berlin Heidelberg. doi:10.1007/11817963_34.
- [8] Byron Cook, Andreas Podelski, and Andrey Rybalchenko. Terminator: beyond safety. In Proceedings of the 18th International Conference on Computer Aided Verification, CAV’06, pages 415–418, Berlin, Heidelberg, 2006. Springer-Verlag. doi:10.1007/11817963_37.
- [9] Quentin Guilmant, Engel Lefaucheux, Joël Ouaknine, and James Worrell. The 2-Dimensional Constraint Loop Problem Is Decidable. In Karl Bringmann, Martin Grohe, Gabriele Puppis, and Ola Svensson, editors, 51st International Colloquium on Automata, Languages, and Programming (ICALP 2024), volume 297 of Leibniz International Proceedings in Informatics (LIPIcs), pages 140:1–140:21, Dagstuhl, Germany, 2024. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. doi:10.4230/LIPIcs.ICALP.2024.140.
- [10] Matthias Heizmann, Jochen Hoenicke, Jan Leike, and Andreas Podelski. Linear ranking for linear lasso programs. In Dang Van Hung and Mizuhito Ogawa, editors, Automated Technology for Verification and Analysis, pages 365–380, Cham, 2013. Springer International Publishing. doi:10.1007/978-3-319-02444-8_26.
- [11] Mehran Hosseini, Joël Ouaknine, and James Worrell. Termination of Linear Loops over the Integers. In Christel Baier, Ioannis Chatzigiannakis, Paola Flocchini, and Stefano Leonardi, editors, 46th International Colloquium on Automata, Languages, and Programming (ICALP 2019), volume 132 of Leibniz International Proceedings in Informatics (LIPIcs), pages 118:1–118:13, Dagstuhl, Germany, 2019. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. doi:10.4230/LIPIcs.ICALP.2019.118.
- [12] Jeffrey C. Lagarias. The 3x+1 problem: An overview, 2021. arXiv:2111.02635.
- [13] George M. Leigh. A markov process underlying the generalized syracuse algorithm. Acta Arithmetica, 46:125–143, 1986. URL: https://api.semanticscholar.org/CorpusID:117635633.
- [14] Hendrik W. Lenstra. Integer programming with a fixed number of variables. Math. Oper. Res., 8:538–548, 1983. doi:10.1287/MOOR.8.4.538.
- [15] Keith R. Matthews. Some borel measures associated with the generalized collatz mapping. Colloquium Mathematicum, 63:191–202, 1992. URL: https://api.semanticscholar.org/CorpusID:54607478.
- [16] Keith R Matthews. Generalized 3x+ 1 mappings: markov chains and ergodic theory. The ultimate challenge: The 3x, 1:79–103, 2010.
- [17] Keith R. Matthews and A. M. Watts. A markov approach to the generalized syracuse algorithm. Acta Arithmetica, 45:29–42, 1985. URL: https://api.semanticscholar.org/CorpusID:118600406.
- [18] Watts A. Matthews K. A generalization of hasse’s generalization of the syracuse algorithm. Acta Arithmetica, 43(2):167–175, 1984. URL: http://eudml.org/doc/205897.
- [19] H. Möller. Über hasses verallgemeinerung des syracuse-algorithmus (kakutanis problem). Acta Arithmetica, 34:219–226, 1978. URL: https://api.semanticscholar.org/CorpusID:117690327.
- [20] Christos H. Papadimitriou. On the complexity of integer programming. J. ACM, 28(4):765–768, October 1981. doi:10.1145/322276.322287.
- [21] A. Podelski and A. Rybalchenko. Transition invariants. In Proceedings of the 19th Annual IEEE Symposium on Logic in Computer Science, 2004., pages 32–41, 2004. doi:10.1109/LICS.2004.1319598.
- [22] Andreas Podelski and Andrey Rybalchenko. A complete method for the synthesis of linear ranking functions. In Verification, Model Checking, and Abstract Interpretation, 5th International Conference, VMCAI 2004, Venice, Italy, January 11-13, 2004, Proceedings, volume 2937, pages 239–251, January 2004. doi:10.1007/978-3-540-24622-0_20.
- [23] R. Tyrrell Rockafellar. Convex Analysis. Princeton Landmarks in Mathematics and Physics. Princeton University Press, 1970.
- [24] Alexander Schrijver. Theory of linear and integer programming. John Wiley & Sons, Inc., USA, 1986.
- [25] Simon Telen. Introduction to toric geometry, 2022. arXiv:2203.01690.
- [26] A. Tiwari. Termination of linear programs. In R. Alur and D. Peled, editors, Computer-Aided Verification, CAV, volume 3114 of LNCS, pages 70–82. Springer, July 2004. doi:10.1007/978-3-540-27813-9_6.
- [27] Hiroshi Unno, Tachio Terauchi, and Eric Koskinen. Constraint-based relational verification. In Alexandra Silva and K. Rustan M. Leino, editors, Computer Aided Verification, pages 742–766, Cham, 2021. Springer International Publishing. doi:10.1007/978-3-030-81685-8_35.
