A Robust Class of Linear Recurrence Sequences

We introduce a subclass of linear recurrence sequences which we call poly-rational sequences because they are denoted by rational expressions closed under sum and product. We show that this class is robust by giving several characterisations: polynomially ambiguous weighted automata, copyless cost-register automata, rational formal series, and linear recurrence sequences whose eigenvalues are roots of rational numbers.


Introduction
The study of sequences of numbers originated in mathematics and has deep connections with many fields. A prominent class of sequences is linear recurrence sequences, such as the Fibonacci sequence 0, 1, 1, 2, 3, 5, 8, 13, . . .
Despite the simplicity of linear recurrence sequences many problems related to them remain open, and are the object of active research. In theoretical computer science the two main questions are: How to finitely represent sequences? How to algorithmically analyse properties of sequences?
In this paper we focus on problems related to the first question. The question of representation has led to important insights in the structure of linear recurrence sequences by giving several equivalent characterisations, some of which we briefly review here. We refer to Section 2 and the next sections for technical definitions.
Linear recurrence sequences A sequence of real numbers u = u n n∈N = u 0 , u 1 , u 2 , . . . is a linear recurrence system (LRS) if there exist real numbers a 1 , . . . , a k such that for all n ≥ 0 u n+k = a 1 u n+k−1 + . . . + a k u n . (1)

Algorithmic analysis of linear recurrence sequences
The questions regarding algorithmic analysis are far from being answered. A very simple and natural problem, the Skolem problem, is still unsolved [20,17]: given a linear recurrence sequence, does it contain a zero? Recent breakthrough results sharpened our understanding of the Skolem problem [15,16], but one of the outcomes is that the general problem for the whole class of linear recurrence sequences is beyond our reach at the moment, since it would impact notoriously difficult problems from number theory. We refer the reader to the recent survey about what is known to be decidable for linear recurrence sequences [17].

Our contributions
Since the full class of linear recurrence sequences is too hard to be algorithmically analysed (we only mentioned the Skolem problem but many related problems are also difficult), let us revise our ambitions, go back to the drawing board, and study tractable subclasses.
In this paper we introduce poly-rational sequences which is a strict fragment of linear recurrence sequences. We give several equivalent characterisations of this class following

Related works
The intractability of the Skolem problem for linear recurrence sequences also impacts the other equivalent models, leading to the study of several restrictions. A classical approach to tame weighted automata is to bound the ambiguity of weighted automata, i.e. bounding the number of accepting runs with a function depending on the length of the word. Many positive results have been obtained in the past years following this approach [10,9,7].
Another restriction studied in the model of cost-register automata is the copyless restriction: registers are not allowed to be copied more than once. It was conjectured that the copyless restriction would result in good decidability properties [3], but this has been recently falsified [2].

23:4
A Robust Class of Linear Recurrence Sequences value of the n-th element in the sequence. Note that a polynomial represents a sequence with a finite support.

Example 3.
A standard example of an LRS is the Fibonacci sequence F n n∈N defined by the recurrence F n+2 = F n+1 + F n and initial values F 0 = 0, F 1 = 1. Its characteristic polynomial is p(x) = x 2 − x − 1, whose roots are 1+

Rational expressions
We start by defining three classes of sequences.
Fin: a sequence u is in Fin, or equivalently u has finite support, if the set {n ∈ N : u n = 0} is finite; Arith: a sequence u is in Arith, or equivalently u is arithmetic, if u 0 = a, u n+1 = u n + b for some rational numbers a, b; Geo: a sequence u is in Geo, or equivalent u is geometric, if u 0 = a, u n+1 = λ · u n , for some rational numbers a, λ. We let Geo λ denote the class of geometric sequences with a fixed parameter λ.
We write Rat[C, op 1 , . . . , op k ] for the smallest class of sequences containing C and closed under the operators op 1 , . . . , op k . Rational expressions in Theorem 1 are classically defined as follows [19]: The class Rat contains all classes defined above, and is closed under all mentioned operators, i.e.
We now introduce a class of sequences denoted by a fragment of rational expressions, whose study is the purpose of this article. The class is called poly-rational sequences, because they are denoted by rational expressions using sum and product. In other words PolyRat is the smallest class of sequences containing arithmetic and geometric sequences that is closed under sum, Hadarmard product, shift, and shuffle. A trivial observation is that Fin ⊆ PolyRat since using shift one can generate any sequence with finite support. One could try to simplify the definition of PolyRat replacing Arith ∪ Geo with Fin. Unfortunately, the operators +, ×, shift, shuffle are too restricted, and geometric and arithmetic sequences could not be generated. In fact, the class would collapse to Fin.
Since Rat contains Arith and Geo and is closed under Hadamard product, shift, and shuffle, we have PolyRat ⊆ Rat. We will show that the inclusion is indeed strict. As we will see in this paper, the class PolyRat has many equivalent and surprising characterisations.

Characterisation with polynomially ambiguous weighted automata
We refer to e.g. [6] for an excellent introduction to weighted automata. We consider weighted automata over the rational semiring (Q, +, ·), where + and · are the standard sum and product. For an alphabet Σ, weighted automata recognise functions assigning rational numbers to finite words, i.e. f : Σ * → Q. In this paper we will consider only one-letter alphabets so the set of words is {a} * = ε, a, a 2 , . . . , which is identified with N. Therefore, weighted automata recognise functions f : N → Q, i.e. weighted automata recognise sequences of rational numbers. Formally, a weighted automaton is a tuple A = (Q, M, I, F ), where Q is a finite set of states, M is a Q × Q matrix over Q and I, F are the initial and final vectors, respectively, of dimension Q (for convenience we label the coordinates by elements of Q). The sequence recognised by the automaton A is A defined by A (n) = I t M n F , where I t is the transpose of I.
We give an equivalent definition of A in terms of accepting runs. We say that a state q ∈ Q is an initial state if I(q) = 0 and that it is a final state if F (q) = 0. If q is initial we say that its initial weight is I(q), and if q is final then its final weight is F (q). For two states p, q ∈ Q we say that there is a transition from p to q if M (p, q) = 0. Such a transition is denoted p → q and its weights is M (p, q). A run ρ is a sequence of consecutive transitions, and it is accepting if the first state is initial and the last state is final. The value of an accepting run ρ = q 0 → q 1 → · · · → q n is Let Runs A (n) denote the set of all accepting runs of length n. An alternative and equivalent definition of A is  The ambiguity of an automaton A is the function a A : N → N which associates to n the number of accepting runs |Runs A (n)|. We consider the following classes:

23:6 A Robust Class of Linear Recurrence Sequences
DetWA -the class of deterministic weighted automata; kWA for fixed k ∈ N -the class of k-ambiguous weighted automata, i.e. when a A (n) ≤ k for all n; FinWA = k∈N kWA -the class of finitely ambiguous weighted automata, i.e. when there exists k such that a A (n) ≤ k for all n; PolyWA -class of polynomially ambiguous automata, i.e. when there exists a polynomial P : N → N such that a A (n) ≤ P (n) for all n; WA -the full class of weighted automata.
For example, the automaton in Example 5 is not polynomially ambiguous because the number of accepting runs is exponential. We will see that this is no accident by proving in Section 5 that the Fibonacci sequence is not in PolyWA.
We present our first characterisation of PolyRat.

Proof of Theorem 6
This subsection is divided into two parts for both inclusions.
PolyRat ⊆ PolyWA Figure 2 shows how to recognise the arithmetic and the geometric sequences. For each finitely Figure 2 The weighted automaton on the left recognises the arithmetic sequence with parameters (a, b) and it is linearly ambiguous. The weighted automaton on the right recognises the geometric sequence with parameters a, λ and it is deterministic.
supported sequence a simple weighted automaton can be constructed. It remains to prove that the class PolyWA is closed under the operators. The sum and products correspond to union and product of automata, it is readily verified that these standard constructions preserve the polynomial ambiguity. Below we deal with shift and shuffle operators.
Suppose we have a polynomially ambiguous automaton A for u and we want to construct a new polynomially ambiguous automaton A for a, u . We start with the case when a = 0. Then A has the same state as A plus one new state q 0 , which is the only initial state in A . All transitions from A are inherited. There are additionally only outgoing transitions from q 0 to all states that are initial in A; the weight of the transition is the initial weight of the corresponding state in A. It is readily verified that A recognises 0, u and that A is polynomially ambiguous. For a = 0 it suffices to add one more state that is both initial and final with initial weight 1 and final weight a.
To deal with shuffle we start with the following preliminary construction. Fix some k > 0 and a polynomially ambiguous automaton A recognising u. We construct A[k] recognising . . , i.e. elements u i are separated by k − 1 elements with 0.
The idea to construct A is that the set of states have an additional component {0, . . . , k − 1}, and they behave like A every k-th step; in the remaining steps they only wait. Formally, the set of states of with the same weight. The remaining transitions are (q, i) → (q, (i + 1) mod k) with weight 1, defined for every i > 0 and every q ∈ Q. It is readily verified that A[k] recognises u .

PolyWA ⊆ PolyRat
The first step is to decompose polynomially ambiguous automata into a union of automata that we will call chained loops. We say that the states p 0 , each q i is contained in at most one loop (the states in P are used only as intermediate states in the loops); q k−1 is the unique final state with F (q k−1 ) = 1. We define the concatenation of two chained loops A 1 , A 2 : this is the chained loop obtained by constructing the union of the two automata with the initial state being the initial state of A 1 , the final state being the final state of A 2 , and rewiring the output of A 1 to the initial state of A 2 , see e.g. Figure 3.

Lemma 7. Any polynomially ambiguous weighted automaton is equivalent to a union of chained loops.
Proof. Let A be a polynomially ambiguous weighted automaton. Without loss of generality A is trimmed, i.e. every state occurs in at least one accepting run.

A Robust Class of Linear Recurrence Sequences
We first note that any state in A is contained in at most one loop. Indeed, a state contained in two loops induces a sequence of words with exponential ambiguity. This implies that a sequence (q 0 , q 1 , . . . , q k ) with q i = q j for i = j induces at most one chained loop of which it is the path. There are finitely many such sequences because k < |A|.
We claim that A is equivalent to the union of all chained loops induced by such sequences. Indeed, there is a bijection between the runs of A and the runs of all the chained loops, respecting the values of runs. Consider a run ρ of A, where a state q appears multiple times. Then between each occurence of q this is the same run, because they are loops over q and there can be only one loop containing q. So ρ = uv k w, where v is the (only) loop containing q. Repeating this for u and w, we obtain a unique decomposition of ρ into where i is a loop over q i (we can have m i = 0) and q i = q j for i = j.
Our aim is to use the decomposition result stated in Lemma 7 to prove the inclusion PolyWA ⊆ PolyRat. It will be convenient for reasoning to use formal series. Let S 1 , S 2 be the formal series induced by the chained loops A 1 and A 2 , then the formal series induced by the concatenation of A 1 and A 2 is x · S 1 · S 2 . Let S 1 , S 2 be the formal series induced by two automata A 1 and A 2 , then the formal series induced by the union of A 1 and A 2 is S 1 + S 2 .
Proof. The first and the third item are immediate, we focus on the second. For convenience let us assume that A 2 (−1) = 0. By definition the concatenation of two chained loops recognises the sequence defined by since an accepting run in the concatenation is the concatenation of an accepting run in A 1 and an accepting run in A 2 . The only issue is that the output state of A 1 was changed into a transition, and to include this step we write A 1 (i − 1) instead of A 1 (i). Hence the formal series is indeed the Cauchy product of S 1 and S 2 , shifted by one.
We are now half-way through the proof of the inclusion PolyWA ⊆ PolyRat: thanks to Lemma 7, we can restrict our attention to unions of chained loops, and thanks to Lemma 8, we know what are the formal series induced by the sequences computed by such automata. More specifically, they are obtained from formal series of the form α 1−λx by taking sums and Cauchy products (with an additional shift).
To prove that PolyRat contains such sequences it is tempting to attempt showing that the sequences above are in PolyRat and the closure of PolyRat under sums and Cauchy products. Unfortunately, the closure under Cauchy product is not clear (although it will follow from the final result that it indeed holds).
We sidestep this issue by observing that we only need to be able to do Cauchy products of formal series of a special form. Indeed, the formal series described above are of the form P Q where P, Q are rational polynomials and the roots of Q are roots of rational numbers: this is true of α 1−λx and is clearly closed under sums and Cauchy products (with the additional shift).
Notice that every chained loop can be obtained as concatenations of chained loops of size 1. Thus Lemma 8 gives a characterisation of formal series corresponding to unions of chained loops: these are sums of products of α 1−λx and polynomials. We further simplify this characterisation applying the following lemma. Proof. This is a direct consequence of the fact that Q[x] is a Euclidean ring. The exact statement following from this is that any product n i=1 Ri Pi where the polynomials P i are mutually prime (meaning, for each i, the polynomials P i and j =i P j are coprime) can be written as a sum of Qi Pi for some rational polynomials Q i . To conclude, we observe that any polynomial whose roots are roots of rational numbers can be written as a product of mutually prime polynomials of the form (1 − λx ) k .
By Lemma 8 and Lemma 9 it follows that for every finite union of chained loops its formal series is a sum of R (1−λx ) k for rational polynomials R, rational numbers λ, and , k natural numbers. Combining this with Lemma 7 we get that the formal series computed by PolyWA are of the same form. Thus we have reduced proving the inclusion PolyWA ⊆ PolyRat to proving that sequences whose formal series are sums of formal series of the form Since PolyRat is closed under sum, it suffices to consider one such formal series. Moreover, due to the closure under shifts we can assume that the polynomial R is equal to 1; as stated in the lemma below. Lemma 10. The sequence whose formal series is Proof. We know that Note that n+k−1 k is a polynomial in n of degree at most k, i.e. n+k−1 k = k p=0 a p n p . It follows that It is enough to prove that for each p the sequence whose formal series is n∈N a p n p λ n x ·n is in PolyRat. Using an arithmetic sequence and Hadamard products we construct a p n p n∈N . Multiplying it using Hadamard product with the geometric sequence λ n n∈N yields a p n p λ n n∈N . Shuffling the obtained sequence with − 1 null sequences yields the desired sequence.

Application: the ambiguity hierarchy of weighted automata
We show that the natural classes of weighted automata defined by ambiguity can be described using subclasses of rational expressions. (⊆) Since the automaton is deterministic it has a shape of a lasso, i.e. the states can be partitioned into a path such that the last state on the path is in a loop. Let λ be the value obtained by multiplying all values on the loop, let l be the length of the loop and let m be the length of the path. Then it is easy to see that the sequence is obtained by first taking a shuffle of l sequences in Geo λ and then shifting it m times.
(⊇) We already know that Geo λ are definable by deterministic weighted automata from (⊆) By Lemma 7 we know that each automaton in FinWA is a union of chained loops. It is easy to see that every such chained loop has to be a lasso otherwise it will contradict the assumption that the automaton is finitely ambiguous. Then the construction follows by doing the construction for every lasso as in the proof of DetWA = λ∈Q Rat[Geo λ , shift, shuffle] and using + to deal with the union.
(⊇) This follows the same steps as the proof of DetWA = λ∈Q Rat[Geo λ , shift, shuffle]. It is even simpler because we can take a union of two automata and remain in the class of FinWA.
We give examples witnessing the strict inclusions DetWA FinWA PolyWA WA and kWA (k + 1)WA. n∈N , 1 n∈N ) is in 1WA but not in DetWA, u k defined by u n = 1 n + 2 n + · · · + (k + 1) n is in (k + 1)WA but not in kWA, v defined by v n = n is in PolyWA but not in FinWA; Fibonacci is in WA but not in PolyWA.
We omit the simple but technical proofs of the first three items. Only the last item will be proved in Section 5, it follows from the fact that PolyWA = PolyRat is equal to the class of LRS whose eigenvalues are roots of rational numbers. As mentioned in Example 3 the characteristic polynomial of the Fibonacci sequence is x 2 − x − 1, so its eigenvalues are not roots of rationals.

Characterisation with copyless cost-register automata
Cost-register automata (CRA) [3] are deterministic automata with write-only registers, where each transition updates the registers using addition and multiplication. Like in Section 3 we will consider only the variant of the model over a one-letter alphabet recognising functions f : N → Q. Let X be a set of variables (registers). The set of expressions Expr(X ) is generated by the following grammar e ::= x | r | e + e | e · e, where x ∈ X and r ∈ Q. A substitution is a mapping σ : X → Expr(X ). We let Subs(X ) denote the set of all substitutions. A valuation is a function σ : X → Q, it is a special case of substitutions, where expressions are limited to constants. We freely compose these objects: for instance let X = {x}, define the valuation ν 0 (x) = 0, the substitution σ(x) = x + 1 and the expression e = 2x. Then ν 0 • σ n • e = 2n. We see this computation as the output of a 1-register machine which initialises x with 0, increments its value at each step and outputs its double value. Formally, a CRA is a tuple A = (Q, X , δ, q 0 , ν 0 , µ), where Q is the set of states, X is the set of registers, δ : Q → Q × Subs(X ) is the transition function, q 0 is the initial state, ν 0 : X → Q is the initial valuation and µ : Q → Q is the final output function. The output of A on n is defined by the unique run of length n: let q 0 → q 1 → · · · → q n such that δ(q i ) = (q i+1 , σ i+1 ) A CRA is said to be linear if its transitions and output function use only linear expressions, i.e. such that in the grammar e · e is restricted to e · r. We denote LCRA the class of sequences recognised by linear CRA, which is known to be equivalent to the class WA [3]. For instance, the following linear CRA recognises the Fibonacci sequence.
A substitution σ is called copyless if each register is used at most once in all σ(x). It is easy to observe that a composition of copyless substitutions is a copyless substitution. A CRA is said to be copyless if in each transition, each substitution is copyless. For example in Figure 5 A linear CRA recognising the Fibonacci sequence. There is only one state and two variables X = {x0, x1}. Since there is only one state the transitions are presented using only the expression that is applied every time. Figure 5 the register x 1 is used twice in the substitution so it is not a copyless automaton. We let CCRA denote the class of sequences recognised by copyless cost register automata (CCRA). In [12] it is shown that CCRA is a subclass of linear CRA. We show that this is another class characterising PolyRat.

PolyRat ⊆ CCRA
This inclusion is easy to prove, it requires to perform the classical constructions as in Section 3 and to note that they respect the copyless restriction.

CCRA ⊆ PolyRat
We make use of a simple property in [14]. A substitution is in normal form if there exists an order on the registers x 1 < · · · < x k such that the substitutions updating registers respect the order: σ(x i ) can use only registers x j such that x j ≥ x i . A CCRA is in normal form if all substitutions used by it are in normal form, with the same order on the registers. It is known that every CCRA has an equivalent CCRA in normal form [14,Proposition 1]. We will use this fact only to prove Lemma 14, but in the construction we will assume that the CCRA is in normal form.
Consider a CCRA A, we prove that the sequence u it recognises is in PolyRat. We assume without loss of generality that A is in normal form. Since A is deterministic it has the shape of a lasso: a tail of length k and a loop of length . Let us fix n ∈ N and ∈ {0, . . . , − 1}, the run is Let δ(q i ) = (q i+1 mod , β i ) for i ∈ {0, . . . , k}, with the convention that q k+1 = p 0 , and Notice that σ is a copyless substitution since it is a composition of copyless substitutions. We define the sequence u[ ] by We will prove in Lemma 14 that the sequence u[ ] is in PolyRat. The decomposition of the runs into a lasso implies the following equality: which implies that u is in PolyRat, provided the lemma below is true.

Lemma 14.
For every copyless substitution σ in normal form, for all initial valuation ν and for all expression e, the sequence Proof. We prove that the sequence u x = ν • σ n (x) is in PolyRat for every register x, i.e. the lemma holds for e = x. The general case follows since PolyRat is closed under addition and product.
We consider two cases. Suppose x is not used in σ(x). We prove that for n big enough the sequence stabilises, i.e. σ n (x) = σ n+1 (x) = c for some constant c. We show this by the induction on the order < from the assumed normal form. If x is the biggest element in the order < then σ(x) is a constant and thus σ n (x) = σ n+1 (x). For the induction step suppose x is not the biggest element. If σ(x) is a constant then the claim is trivial. Otherwise let x 1 , . . . , x m be registers used in σ(x). Since σ is copyless then x i is not used in σ(x i ) for every i. Hence by the induction assumption for every i there exists n i such that σ n (x i ) = σ n+1 (x i ) for all n ≥ n i . It suffices to take n = max i {n i | 1 ≤ i ≤ m} + 1. Since constant sequences are geometric sequences with λ = 1 then u x can be defined in PolyRat using shift. Now suppose that x is used in σ(x). The expression σ(x) is equivalent to m i=0 a i · x i for some constants a i , where x 0 = x and x i are pairwise different. Since σ is copyless then for all i > 0 we know that σ(x i ) does not use x i . By the previous paragraph there exists N such Let a = a 0 and b = m i=1 a i · c i . We proved that for n ≥ N the sequence u x satisfies u x (n + 1) = a · u x (n) + b. It remains to prove that this sequence is in PolyRat. It is enough to show that u x (n) = u x (n + N ) is in PolyRat since to obtain u x it suffices to use shift N times. There are two cases. If a = 1 then u x (n) is an arithmetic sequence, which concludes the proof. If a = 1 then u x (n) = a n · u x (0) + n−1 i=0 a i · b = a n · u x (0) + b · a n − 1 a − 1 .
This is a sum of a geometric sequence a n · (u x (0) + b a−1 ); and a constant sequence − b a−1 ; which proves u x is in PolyRat.
Remark. One can extract from this proof the equivalence between linear CCRA and Rat[Arith ∪ Geo, +, shift, shuffle].
It was recently shown that CCRA are strictly less expressive than weighted automata [14]. The proof goes by analysing the Fibonacci sequence. We will get as a corollary of our results a self-contained proof that LCRA and CCRA are different.

Characterisation with linear recurrence sequences and formal series
Our last two characterisations are as follows.
C V I T 2 0 1 6

23:14
A Robust Class of Linear Recurrence Sequences Theorem 15. PolyRat is the class of LRS whose eigenvalues are roots of rational numbers, and equivalently whose formal series are P Q with P, Q rational polynomials and the roots of Q are roots of rational numbers.
Before proving the theorem, we note that we can now substantiate the claim that the Fibonacci sequence is not in PolyRat (hence not in CCRA and PolyWA), since its eigenvalues are not roots of rational numbers.
We rely on the following classical result about LRS, see e.g. [8].
Lemma 16. Let u be an LRS and Q its characteristic polynomial. The formal series induced by u is P Q for some rational polynomial P .
For both inclusions we rely on Theorem 6 stating that PolyRat = PolyWA and the decompositions obtained in the subsequent lemmas.
PolyRat ⊆ LRS whose eigenvalues are roots of rational numbers By Lemma 7 and Lemma 8 the formal series of sequences in PolyWA are sums and Cauchy products of formal series of the form R 1−λx , where R is a rational polynomial, ∈ N and λ ∈ Q. The roots of 1 − λx are roots of 1 λ , so the roots of the characteristic polynomial are roots of rational numbers.

LRS whose eigenvalues are roots of rational numbers ⊆ PolyRat
Consider an LRS whose eigenvalues are roots of rational numbers. Thanks to Lemma 16 the formal series it induces is P Q with P, Q rational polynomials and the roots of Q are roots of rational numbers. By Lemma 9 the formal series can be written as a sum of formal series of the form R (1−λx ) k for rational polynomials R, rational number λ, and , k natural numbers. It follows from Lemma 10 and the closure of PolyRat under sum and shift that such sequences belong to PolyRat.

Conclusion
We introduced a class of linear recurrence sequences and obtained several characterisations.