Computing $J$-ideals of a matrix over a principal ideal domain

Given a square matrix $B$ over a principal ideal domain $D$ and an ideal $J$ of $D$, the $J$-ideal of $B$ consists of the polynomials $f\in D[X]$ such that all entries of $f(B)$ are in $J$. It has been shown that in order to determine all $J$-ideals of $B$ it suffices to compute a generating set of the $(p^t)$-ideal of $B$ for finitely many prime powers $p^t$. Moreover, it is known that $(p^t)$-ideals are generated by polynomials of the form $p^{t-s}\nu_s$ where $\nu_s$ is a monic polynomial of minimal degree in the $(p^s)$-ideal of $B$ for some $s\le t$. However, except for the case of diagonal matrices, it was not known how to determine these polynomials explicitly. We present an algorithm which allows to compute the polynomials $\nu_s$ for general square matrices. Exploiting one of McCoy's theorems we first compute some set of generators of the $(p^s)$-ideal of $B$ which then can be used to determine $\nu_s$. This algorithmic computation significantly extends our understanding of the $J$-ideals of $B$.


Introduction
If B ∈ M n (R) is a square matrix over a commutative ring R and J is an ideal of R, the J-ideal of B is defined as N J (B) = {f ∈ R[X] | f (B) ∈ M n (J)}. These ideals have been introduced in [9] and arise naturally in the study of integer-valued polynomials on a matrix B (see below in Section 2.2).
In case the underlying ring is a principal ideal domain, the structure of J-ideals has been studied thoroughly in [9]. It has been shown that it suffices to compute a finite number of polynomials in order to describe all J-ideals of a matrix B. As summarized in Section 2.1, it suffices to determine a monic polynomial of minimal degree in N (p t ) (B) for a finite number of prime powers p t of D. It is further known that these so-called (p t )-minimal polynomials are strongly related to the decomposition of the modules However, the characterization of these generating sets given in [9] is theoretic. Except for diagonal matrices, it was not known until now how to compute (p t )-minimal polynomials. This paper is the algorithmic counterpart of [9]. Algorithm 5 determines these polynomials explicitly for general square matrices B with entries in a principal ideal domain. The iterative computation consists of two main steps. Given a generating system of the (p t−1 )-ideal of B, we first determine a set F of polynomials such that N (p t ) (B) = (F) + pN (p t−1 ) (B). We then perform a couple of carefully chosen polynomial long divisions to compute a (p t )-minimal polynomial.
In order to determine the set F, we use a description of the null ideal of a matrix given by McCoy in [8,Theorem 54] (see Lemma 4.2). This result allows us to translate the question to that of solving a system of linear equations modulo p t . In order to solve this linear system, we present a special lifting technique in Section 3. The application of this technique to the original question is considered in Section 4. The topic of Section 5 is then the computation of a (p t )-minimal polynomial. Next, in Section 6 we explain why the minimal polynomial µ B of B is a (p t )-minimal polynomial for all but finitely many prime elements p. Finally, in Section 7 we prove that for the remaining prime elements p it suffices to determine a finite number of (p i )-minimal polynomials to describe the (p t )-ideals for all t ≥ 0.

Results
All rings considered in this paper are assumed to be commutative with unity. For a ring R and positive integers r, s, the set of (r × s)-matrices over R is denoted by M r,s (R) or by M r (R) if r = s. If a = 0, then it is easily seen that where µ B is the minimal polynomial of B over the quotient field K of D, cf. [4]. If 0 = a = bc for coprime elements b and c, then N a (B) = cN b (B) + bN c (B) according to [9,Lemma 2.9]. Since every element in D has a decomposition into primes, it suffices to consider the case a = p t where p is a prime element and t ∈ N.
For almost all prime elements p, we have for t ≥ 1. More precisely, this is the case for all primes p which do not divide det(T ) where T is a matrix in M n (D) ∩ GL n (K) such that T BT −1 is in rational canonical form, see Theorem 4. However, the transformation matrix T is not uniquely determined and the set of prime divisors det(T ) depends on the choice of T , see Example 6.1. Thus it is sufficient to determine N (p t ) (B) for finitely many primes p. The following result is a consequence of [9, Theorem 2.19, Corollary 2.23]. We give a proof below in Section 7.
Theorem 1 ([9, Theorem 2.19, Corollary 2.23]). Let p be a prime element of D. Then there is a finite set S p of positive integers and monic polynomials ν (p,s) for s ∈ S p such that for t ≥ 1, holds where b(t) = inf{r ∈ S p | r ≥ t}. The degree of ν (p,s) is strictly increasing in s ∈ S p and ν (p,s) is a monic polynomial of minimal degree in N (p s ) (B). If t ≤ max S p , then the summand µ B D[X] can be omitted.
Whereas [9] could only show the existence of these S p , and ν (p,s) , s ∈ S p , the present paper presents an algorithm (Algorithm 5) to explicitly compute these quantities. Thus the structure of N (a) (B) is completely understood.
For simplicity, we omit the indices p and write S and ν s instead of S p and ν (p,s) , respectively, when the prime p is clear from the context. An implementation of Algorithm 5 has been included [5] in the free open-source mathematics software system SageMath [10] as method p_minimal_polynomials of a matrix; the (a)-ideal of B can be computed by the method null_ideal of B.

2.2.
Integer-valued polynomials. Let D be a principal ideal domain with quotient field K and B ∈ M n (D). Then Int(B, M n (D)) : is called the ring of integer-valued polynomials on B. As before, the minimal polynomial of B over K is denoted by µ B .
If a polynomial f ∈ K[X] is written as f = g/d for some g ∈ D[X] and d ∈ D, then f ∈ Int(B, M n (D)) holds if and only if g ∈ N (d) (B). Thus Theorem 1 translates into the following corollary proved in [9]. Theorem 4.3]). With the above notations, there is a finite set P of prime elements such that where S p and ν (p,s) , s ∈ S p , are the set and polynomials from Theorem 1.
As a consequence, Algorithm 5 completely describes the structure of Int(B, M n (D)). An implementation has been submitted as method integer_valued_polynomials for inclusion in SageMath.
is a finitely generated module over a principal ideal ring. According to [3,Theorem 15.33] this module decomposes into a direct sum of cyclic submodules with uniquely determined annihilators (the invariant factors). As shown in [9], this decomposition is strongly related to the generating set described in Theorem 1 which is stated in the next theorem. This further implies that the set S p and the degrees of the polynomials ν (p,s) , s ∈ S p are uniquely determined.
Theorem 2 ([9, Theorem 3.5]). Let B ∈ M n (D) and for a prime p of D, let S p and ν (p,s) , s ∈ S p , the set and polynomials from Theorem 1. We order {ν (p,s) | s ∈ S p } ∪ {µ B } by ascending degree and define succ(ν (p,s) ) for s ∈ S p to be the successor of ν (p,s) with respect to this ordering. Finally, let d = min{deg(ν (p,s) ) | s ∈ S p } and d s = deg(succ(ν (p,s) )) − deg(ν (p,s) ). Then As a consequence, Algorithm 5 completely determines the structure of (D/p t D)[B + M n (p t D)].

Lifting
In this section, we provide the lifting procedure which allows the recursive computation of the (p t )-minimal polynomials in Section 5.
Let D be a principal ideal domain, p be a prime element of D and d ≥ c ≥ 1. The projection of some z ∈ D to the field D/pD is denoted by z. We extend this notation to polynomials in D[X] and vectors in D[X] d as well as matrices in M c,d (D[X]). The identity matrix is denoted by I.
) be a matrix such that A has rank c. For t ≥ 0, we consider the set  Ah h h + Rq q q ≡ 0 (mod p).
Left-multiply (2) by S to obtain

This is equivalent to
Thus we have as claimed.

Generators of (p t )-ideals
This section is dedicated to the computation of a generating set of the (p t )-ideal of a matrix over a principal ideal domain. Before we go into details, let us recall the basic definitions.
We omit the superscript in N R J (B) if the underlying ring is clear from the context.
. The minimal polynomial of B is the (in this case) uniquely determined (0)-minimal polynomial of B. Over general commutative rings, a (0)-minimal polynomial of a matrix is not necessarily uniquely determined although its degree is.
Remark. Note that every square matrix B ∈ M n (R) has a J-minimal polynomial for every ideal J of R. This is due to the Cayley-Hamilton theorem; every matrix over a commutative ring is a root of its own characteristic polynomial which is monic, cf. [ ) and hence f ∈ N J (B). In particular, there exists a monic preimage of χ in R[X].
From now on, let the underlying ring be the principal ideal domain D and B ∈ M n (D) a square matrix. For any ideal J of D there exists a ∈ D such that J = (a). Following the convention in Assume that a = 0 and let K denote the quotient field of D. The null ideal of B considered as a matrix over K is generated by its minimal polynomial However, D is integrally closed and therefore every monic factor in K[X] of a monic polynomial in D[X] is already an . In order to find a generating set of N p t (B), we reformulate the problem in a form to which the approach of the previous section is applicable. For this purpose we use one of McCoy's theorems. . Let R be a commutative ring and C ∈ M n (R) a square matrix.
denotes the characteristic polynomial of C.
Since this result is central to our work, we restate its proof here for the reader's convenience.
Being a monic polynomial, X − C is not a zero-divisor in M n (R)[X] and therefore if and only if ) under the projection modulo p t . Hence we can write the (p t )-ideal of our matrix B ∈ M n (D) in the following way.
Note that if t = 0, then (p 0 ) = D and D/D is the zero ring which has no unity and we cannot apply McCoy's theorem (Lemma 4.2). However, it is easily seen that the corollary still holds which is why we allow the case t = 0.
For 1 ≤ i, j ≤ n, the congruence in Corollary 4.3 translates to Proposition 4.4. Let D be a principal ideal domain, p ∈ D a prime element, B ∈ M n (D) be a square matrix with characteristic polynomial χ B and t ≥ 0. Further, let b b b ∈ D[X] n 2 be the column vector containing all entries of adj(X − B) in some fixed order, where I denotes the n 2 × n 2 -identity matrix and For g 11 , . . . , g 1s ∈ D[X] (with s ∈ N 0 ), the following assertions are equivalent: (1) There is a matrix G ∈ M n 2 +1,s (D[X]) with first row g 11 , . . . , g 1s such that the columns of p t I G form a generating set of O t (A). (2) p t , g 11 , . . ., g 1s form a generating set of N p t (B).
Since χ B is monic, its residue class modulo p t is no zero-divisor and we can cancel χ B in the equation above to conclude that .
Therefore f f f is a D[X]-linear combination of the columns of p t I G where G = (g ji ) 1≤j≤n 2 +1 1≤i≤s . It follows from Proposition 4.4 that we can use Algorithm 1 to compute a generating system of O t (A) (with c = n 2 and d = n 2 + 1). Note that the residue class A of A has full rank since χ B is monic. Assume that we are given G ∈ M n 2 +1,s (D[X]) whose columns together with those of p t−1 I generate O t−1 (A), then Algorithm 1 computes a matrix F ∈ M n 2 +1,s+1 (D[X]) such that the columns of p t I F pG generate O t (A). Then p t , f 11 , . . ., f 1,s+1 , pg 11 , . . ., pg 1s generate N p t (B), according to Proposition 4.4. In particular, the elements f 11 , . . ., f 1,s+1 satisfy a property which motivates the next definition. As output of Algorithm 1, F = {f 11 , . . . , f 1,s+1 } has s + 1 elements. Applying the algorithm recursively leads to a huge set of generators.
Indeed, according to [9, Proposition 2.13], if t ≥ 1 and ν t is a (p t )-minimal polynomial of B, then This is also a consequence of Algorithm 5 below. The next section is dedicated to the question how to compute (p t )-minimal polynomials given a set F with the (p t )-generating property and a (p t−1 )-minimal polynomial. For now, we assume that we already know (p i )-minimal polynomials ν i for 1 ≤ i ≤ t − 1. Then Equation (4) implies and according to Proposition 4.4, there exists a matrix G ∈ M n 2 +1,t−1 With this choice, s = t − 1 and hence Algorithm 1 produces a set F with t elements. Note that [9, Theorem 2.19] states that it suffices to sum over the (t − 1)-st index set in Equation (5) which may result in a smaller number of columns of G. However, even this reduction technique does not yield |F| = 1 except in trivial cases. Therefore, reduction of |F| in every step is essential.

Computing (p t )-minimal polynomials
This section considers the question how to compute a (p t )-minimal polynomial of a square matrix B ∈ M n (D) over a principal ideal domain D for t ≥ 1. For this purpose, we assume throughout this section that we already determined a (p i )-minimal polynomial ν i for 0 ≤ i ≤ t − 1 and a set F with the (p t )-generating property. We start with a special case, namely the case where the set F consists of a single monic polynomial f . If Proof. Since ν ∈ N p t (B) holds by hypothesis, it suffices to show that deg(f ) ≥ deg(ν) for all monic polynomials f ∈ N p t (B). By assumption, holds, so for a monic polynomial f ∈ N p t (B) there exist g ∈ D[X] and h ∈ N p t−1 (B) such that f = gν + ph. Let g 1 , g 2 ∈ D[X] be polynomials such that g = g 1 + pg 2 and no non-zero coefficient of g 1 is divisible by p. Then f = g 1 ν + p(g 2 ν + h) and since f is monic and p does not divide lc(g 1 ) = lc(g 1 ν) it follows that deg(f ) = deg(g 1 ) + deg(ν) ≥ deg(ν).
In order to apply Proposition 5.1, we have to reduce the output set F of Algorithm 1 such that it only contains one monic polynomial.
As a first step, observe that holds and therefore F \ pD[X] has the (p t )-generating property. From now on we can therefore assume that F ∩ pD[X] = ∅. Since N p t (B) always contains a monic polynomial it follows that N p t (B) = pN p t−1 (B) and hence F is never empty. In order to compute a (p t )-minimal polynomial from the polynomials in F we need the following special case of [9, Corollary 2.14].

Lemma 5.2 ([9]
). Let ν t be a (p t )-minimal polynomial of B and f ∈ N p t (B). If The idea is to start with F 0 = F and show (for i ≥ 1) that if |F i−1 | > 1 then we can compute a set F i of monic polynomials with the (p t )-generating property with F i ∩ pD[X] = ∅ such that (min f ∈Fi deg f, |F i |) decreases lexicographically in each step.
Since the degree of monic polynomials in N p t (B) is clearly bounded from below, we end up with a singleton satisfying the (p t )-generating property. Hence, by Proposition 5.1 the singleton at the end contains a (p t )-minimal polynomial.
It turns out that polynomial division is a useful tool to compute F i . However, we are working in D[X], so we cannot just divide some polynomial by another; we want to deal with monic polynomials to guarantee that polynomial division is applicable. Algorithms 2 and 3 provide the tools to replace a set with the (p t )-generating property by another one which consists only of monic polynomials.

Algorithm 2 Find monic polynomial
Write f = f 1 + pf 2 such that all non-zero coefficients of f 1 are not divisible by p Let r be the remainder of Since p does not divide lc(f 1 ), the leading terms of f 1 and pr cannot cancel each other out and deg(h) = max{deg(f 1 ), deg(r)}. On the other hand,h ∈ N p t (B) \ pD[X] and therefore deg(h) ≥ deg(ν t ) by Lemma 5.2. We conclude that and it follows that max{deg(f 1 ), deg(ν t−1 ) − 1} = deg(f 1 ) = deg(h) and therefore p lc(h).

Algorithm 3 Replacing by monic polynomials
Further, deg(f i ) < deg(f i−1 ) holds which implies that there exists s ∈ N such that f s ∈ pD[X]. Hence f s ∈ pN p t−1 (B) and We can now replace F by a set with the (p t )-generating property which consists only of monic polynomials using Algorithm 3. Note that we need to know a (p t−1 )-minimal polynomial to do the necessary computations. We are now ready to present Algorithm 4 to compute a (p t )-minimal polynomial.

Algorithm 4 Computation of a (p t )-minimal polynomial
Delete all elements in F ∩pD[X] from F and then replace non-monic polynomials in F by monic polynomials using Algorithm 3 Let g ∈ F be of minimal degree. Proof. We will show that in every step, F consists of monic polynomials and has the (p t )-generating property and (min f ∈F deg(f ), |F|) decreases lexicographically in each step.
This implies that the algorithm computes a singleton with the (p t )-generating property. According to Proposition 5.1, such a singleton contains a (p t )-minimal polynomial.
Removing all polynomials in F ∩ pD[X] ⊆ pN p t−1 (B) in the first step does not affect the (p t )-generating property. The same holds for replacing non-monic polynomials by Algorithm 3. Now, let F 0 be the result of this first step in the algorithm and F i be the resulting set after i iterations of the while loop. Further, let g i be a polynomial of minimal degree in F i . Now assume that |F i−1 | > 1 and let us have a closer look at the i-th iteration of the while loop. For a polynomial f ∈ F i−1 with f = g i−1 , the algorithm computes the remainder r of f modulo g i−1 with deg(r) < deg(g i−1 ). Then the following holds We split into two cases: r ∈ pD[X] and r / ∈ pD[X]. If r ∈ pD[X], then r ∈ pN p t−1 (B) and hence F i = F i−1 \ {f } has the (p t )-generating property. In this case, |F i | < |F i−1 | holds and g i = g i−1 is a polynomial of minimal degree in F i .
If, however, r / ∈ pD[X], then the algorithm computes monic polynomials h 1 , . . ., h s with We conclude this section with Algorithm 5 that computes the generators of N p t (B) of a matrix B ∈ M n (D) and a prime element p ∈ D as stated in Theorem 1, that are (p s )-minimal polynomials ν s for indices s of a finite set S such that for all t ≥ 1, holds where b(t) = inf{r ∈ S | r ≥ t}.
Theorem 3. Algorithm 5 terminates and is correct.
Proof. By definition, (deg(ν s )) s≥0 is a non-decreasing sequence which is bounded from above by deg(µ B ). Hence this sequence eventually stabilizes. Moreover, as shown in [9, Proposition 2.22], the sequence always stabilizes at the value deg(µ B ), that is, there exists s 0 ≥ 0 such that deg(ν s ) = deg(µ B ) for all s ≥ s 0 . This implies that the algorithm terminates. Determine F such that p t I F pG are generators of O t (A) by Algorithm 1 F := first row of F ν t := (p t )-minimal polynomial of B by Algorithm 4 (using For the correctness, observe first that Algorithm 4 computes a (p t )-minimal polynomial ν t with the (p t )-generating property. Next, we explain the choice of g g g. As ν t ∈ N p t (B), there is some q i ∈ D[X] such that ν t b i ≡ χ B q i (mod p t ) by Corollary 4.3. Thus we have r i ≡ χ B (q i − g i ) (mod p t ). As χ B is monic, the degree of the right hand side modulo p t exceeds the degree of r i unless q i ≡ g i (mod p t ).
If deg(ν t ) = deg(ν t−1 ), then ν t is a (p t−1 )-minimal polynomial and ν t − ν t−1 is a polynomial in N p t−1 (B) with degree less than deg(ν t−1 ). By Lemma 5.2, this implies that and thus ν t has the (p t−1 )-generating property. Observe that this is in particular the case if the Algorithm reaches its stopping point, that is, if deg(ν t ) = deg(µ B ). Then µ B is a (p s )-minimal polynomial for all s ≥ t.
The remaining proof consists of repeated application of Proposition 4.4 in both directions.
Remark. Gröbner bases provide an alternative to Algorithm 4. Adams and Loustaunau describe in [1,Ch. 4.5] how to extend the theory of Gröbner bases to polynomial rings over principal ideal domains. If G is a Gröbner basis of N p t (B), we set G = {g ∈ G | p lc(g)}. One can show that G = ∅ and if g is a polynomial of minimal degree in G, then ug + vp t X deg(g) is a (p t )-minimal polynomial where u, v ∈ D such that u lc(g) + vp t = 1.
We skip the computation of ν 1 and claim that ν 1 = X 2 + X is a (2)-minimal polynomial (one can check that its residue class is the minimal polynomial of B over the field Z/2Z).

5.1.
Run-time and memory usage in practice. Table 5.1 displays average run-time and memory usage for Algorithm 5 for a dense random integer matrix B of size n and a prime number p. Note that only instances with non-trivial (p t )-minimal polynomials were taken into account, see Section 6 below. To find such instances, Theorem 4 below provides a strategy to test only a finite number of primes p for a given matrix B. Table 5.1 also contains the total number of pairs (B, p) to which we applied Algorithm 5 and the number of pairs (B, p) among them with non-trivial (p t )-minimal polynomials. All computations were done in the free open-source mathematics software system SageMath (Version 7.6.beta6) on a machine with an Intel(R) Core(TM) i5-4690S CPU @ 3.20GHz processor.
However, the current implementation of the Smith normal form in SageMath is designed to deal with matrices in general principal ideal domains and does not exploit the Euclidean structure of univariate polynomial rings over fields. We experienced memory issues using this implementation in Algorithm 1. For this reason we implemented the algorithm presented in [6] which is also applicable to matrices with entries in a univariate polynomial ring over a field.
In addition, it is worth mentioning that large prime numbers can cause a significant increase in run-time and memory usage. For example, for p = 366388788500439413183777 Algorithm 5 takes 5006.08 seconds and 207.5 MB given the input matrix In this particular example however, it turns out that this value of p only occurs as a root of the determinant of the transformation matrix (see Theorem 4). In fact, B has no non-trivial (p t )-minimal polynomial for any p.  (5) for primes p and integer matrix instances of size n with non-trivial (p t )-minimal polynomials.

Primes with trivial (p t )-minimal polynomials
In this section, we show that for all but finitely many prime elements p and all t ≥ 1, µ B is a (p t )-minimal polynomial. This further implies that the (p t )-ideal N p t (B) of B is generated by µ B and the constant p t . This assertion has been shown before as auxiliary result in the proof of [9,Theorem 4.3]. In order to make it more accessible, we restate it here as proper theorem together with a proof. Theorem 4 ([9]). Let D be a principal ideal domain and B ∈ M n (D) a square matrix with minimal polynomial µ B . Then for all but finitely many prime elements p ∈ D and all t ≥ 1 Proof. It suffices to show that µ B is a (p)-minimal polynomial for all but finitely many prime elements p ∈ D. If this is the case (for a fixed p), then Algorithm 5 stops in the first iteration of the while loop returning S = ∅. Hence, Considered as a matrix over the quotient field K of D, B is similar to its rational canonical form C, that is, there exists a matrix T ∈ GL n (K) such that where µ 1 | · · · | µ r = µ B are the invariant factors of B (in K[X]) and C µi denotes the companion matrix of the polynomial µ i for 1 ≤ i ≤ r (cf. Hence the rational canonical form C of B is a matrix with entries in D. Moreover, we can choose T ∈ M n (D). However, in general, the similarity relation of B and C does not hold over the domain D, that is, we cannot assume T ∈ GL n (D).
Let p be a prime element that does not divide det(T ). Then det(T ) is invertible in the localization D (p) of D at p and T −1 = det(T ) −1 adj(T ) ∈ GL n (D (p) ). This allows to reduce Equation (7) modulo p T B T −1 = T BT −1 = C = C µ B ⊕ · · · ⊕ C µ1 (where we identify the residue fields of D and D (p) modulo p). Hence C is the rational canonical form of B which implies that µ B is the minimal polynomial of B. Equivalently, µ B is a (p)-minimal polynomial of B. The assertion follows since det(T ) has only finitely many prime divisors.
The choice of the transformation matrix in the proof of Theorem 4 is not unique. Moreover, the prime divisors of different transformation matrices may not coincide as the following example demonstrates. Since det(S) = 1, B is similar to C over Z. This implies that µ B is a (p)-minimal polynomial for all primes p of Z. However, det(T ) = 3.

7.
Finite description of (p t )-ideals for all t Finally, we give a proof of Theorem 1 which has been stated above in Section 2. For the reader's convenience we restate it at this point. holds where b(t) = inf{r ∈ S p | r ≥ t}. The degree of ν (p,s) is strictly increasing in s ∈ S p and ν (p,s) is a monic polynomial of minimal degree in N (p s ) (B). If t ≤ max S p , then the summand µ B D[X] can be omitted.
Proof. It has been shown in [9,Theorem 2.19] that where I t denotes the t-th index set of B with respect to p and ν (p,i) are monic polynomials of minimal degree in N (p i ) (B) whose degree is strictly increasing in i ∈ I t . Moreover, it follows from [9, Corollary 2.23] that for every p there exists an integer m such that . For t ≥ m, the assertion now follows from Equations (8) and (9). If t < m, it follows from [9, Definition 2.16, Remark 2.18] that I t \{0, t} = S p ∩{1, . . . , t−1} and ν (p,b(t)) is also a feasible choice for ν (p,t) . Therefore, the assertion follows from Equation (8).