Abstract 1 Introduction 2 Preliminaries 3 versus 𝒑 4 Algorithms 5 NP-hardness and reductions 6 Combining several primes, and the ordering 7 Conclusions and an open problem References

Polynomial-Time Tractable Problems over the p-Adic Numbers

Manuel Bodirsky ORCID Institut für Algebra, Technische Universität Dresden, Germany Arno Fehm ORCID Institut für Algebra, Technische Universität Dresden, Germany
Abstract

We study the computational complexity of fundamental problems over the p-adic numbers p and the p-adic integers p. Guépin, Haase, and Worrell [9] proved that checking satisfiability of systems of linear equations combined with valuation constraints of the form vp(x)=c for p5 is NP-complete (both over p and over p), and left the cases p=2 and p=3 open. We solve their problem by showing that the problem is NP-complete for 3 and for 3, but that it is in P for 2 and for 2. We also present different polynomial-time algorithms for solvability of systems of linear equations in p with either constraints of the form vp(x)c or of the form vp(x)c for c. Finally, we show how our algorithms can be used to decide in polynomial time the satisfiability of systems of (strict and non-strict) linear inequalities over together with valuation constraints vp(x)c for several different prime numbers p simultaneously.

Keywords and phrases:
p-adic numbers, existential theory, linear theory, constraint satisfaction, linear program feasibility, NP-hardness, polynomial-time algorithm
Funding:
Manuel Bodirsky: The author received funding from the ERC (Grant Agreement no. 101071674, POCOCOP). Views and opinions expressed are however those of the authors only and do not necessarily reflect those of the European Union or the European Research Council Executive Agency.
Arno Fehm: The author was funded by the Deutsche Forschungsgemeinschaft (DFG) - 404427454
Copyright and License:
[Uncaptioned image] © Manuel Bodirsky and Arno Fehm; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Logic and verification
; Theory of computation Complexity theory and logic
Related Version:
Full Version: https://arxiv.org/abs/2504.13536,arXiv:2504.13536 [6]
Acknowledgements:
The authors would like to thank Philip Dittmann and Pierre Touchard for helpful discussions regarding quantifier elimination for p.
Editors:
Paweł Gawrychowski, Filip Mazowiecki, and Michał Skrzypczak

1 Introduction

The satisfiability problem for systems of polynomial equations is an immensely useful computational problem; however, it has a quite bad worst-time complexity: it is NP-hard in arbitrary fields, undecidable over  [14], not known to be decidable over , and not known to be in NP for  [15]. In contrast, the satisfiability problem for systems of linear equations has a much better computational complexity: it can be solved in polynomial time over and, equivalently, over , and even over (see, e.g., [16]). It is therefore natural to search for meaningful extensions of the satisfiability problem for linear systems that retain some of the pleasant computational properties; in particular, extensions that remain in the complexity class P. It is also interesting to search for meaningful restrictions of the satisfiability problem for systems of polynomial equations that are no longer computationally hard.

One of the well-studied expansions of linear systems is the expansion by linear inequalities. Note that xy can be expressed over by z(x+z2=y) (and it can also be expressed over and , but we then need a different formula), so this expansion can also be viewed as a restriction of the mentioned problem for systems of polynomial equations. The satisfiability problem for linear inequalities is known to be NP-complete over , but remains in P over and (e.g., via the ellipsoid method; see, e.g., [16]).

Other interesting, but less well-known expansions of the linear existential theory of and come from p-adic valuations vp, for p a prime number: For x, one defines vp(x):=sup{j:pj|x}{}, and one extends this to by vp(ab):=vp(a)vp(b). The complexity of the satisfiability problem for systems of linear equalities combined with valuation constraints of the form vp(x)=c for c has been studied by Guépin, Haase, and Worrell [9]. Their results show that the problem over is in NP, even if the constants c are represented in binary and p is part of the input. This is remarkable, because for any x=ab that satisfies vp(x)=c>0, the number a has exponential size in c, i.e., doubly exponential size in the input size. So we cannot simply guess and verify a solution in binary representation.

The results of Guépin, Haase, and Worrell are actually stated in a different setting: they phrase their result over the p-adic numbers. The p-adic valuation gives rise to a (non-archimedean) absolute value, defined for x by |x|p:=pvp(x). The field of p-adic numbers p is the completion of with respect to ||p, similarly as is defined to be the completion of with respect to the standard absolute value. The ring of p-adic integers is the subring p of p with domain {xpvp(x)0}, where vp denotes the natural extension of the p-adic valuation to p. Guépin, Haase, and Worrell [9] phrase their mentioned results as satisfiability problems over p; however, the problems are equivalent to the respective problems over ; see Proposition 6. They then use their algorithm to prove that the entire existential theory of p in a suitable (linear) language is in NP.

Guépin, Haase, and Worrell moreover obtain some hardness results: they prove that the satisfiability problem for systems of linear equations over p and over p with valuation constraints of the form vp(x)=c is NP-hard for p5. They also state: “While we believe it to be the case, it remains an open problem whether an NP lower bound can also be established for the cases p=2,3.” [9, Remark 23].

We solve this problem and prove that satisfiability is NP-complete in the case p=3 for both p and p. For p=2, however, we prove containment in P. Interestingly, our algorithm can also cope with constraints of the form vp(x)c, even if p is larger than 2 (Theorem 18). We also find an algorithm that can test the satisfiability of linear systems for p in the presence of constraints of the form vp(x)c (Proposition 8); it is the combination of both upper and lower valuation bounds that makes the problem hard.

Our algorithm can also be used for the satisfiability problem for valuation constraints in combination with linear inequalities over . We prove that the satisfiability of systems of (weak and strict) linear inequalities together with various valuation constraints, for instance of the form vp(x)c, can be decided in polynomial time (Theorem 31). We do allow valuation constraints for different primes in the input; we allow binary representations of all coefficients in the input. The proof uses the fact that linear programming is in P [16, Section 13], and the approximation theorem for finitely many inequivalent absolute values for ([13, Ch. XII, Thm. 1.2]).

Related Work.

The computational complexity for satisfiability problems of semilinear expansions of linear inequalities over (equivalently: over ) has been studied in [3]. The results there state that every expansion of the satisfiability problem for linear inequalities by other semilinear relations is NP-hard, unless all relations Rn are essentially convex, i.e., have the property that for any two a,bR, all but finitely many rational points on the line segment between a and b are also contained in R; moreover, if all relations are essentially convex, then the satisfiability problem is in P [3, Theorem 5.2]. This result has later been generalised to expansions of linear equalities instead of inequalities [12]. Valuation constraints are clearly not essentially convex; however, they are also not semilinear, and not even semialgebraic, and hence are not covered by the results from [3] and from [12].

Different computational tasks for the p-adic numbers have been studied by Dolzmann and Sturm [5], and more recently by Haase and Mansutti [10]: they showed that whether a given system of linear equations with valuation constraints (where the valuation constraints in [10] are more expressive than the ones from [5], which are more expressive than ours) has a solution in p for all prime numbers p is in coNExpTime.

Another recent results is a polynomial-time algorithm for the dyadic feasibility problem [1], which is the problem of testing the satisfiability of systems of linear inequalities over [12]; it is unclear how to reduce this problem to the problems studied here and vice versa.

2 Preliminaries

We recall some well-known facts about p-adic numbers, see e.g. [8], and how we treat them from a logic and a computational point of view. We write for the set of all prime numbers and we let p.

2.1 𝒑 and 𝒑

As p is by definition the completion of with respect to the p-adic absolute value |.|p, it is a metric space whose topology is the p-adic topology. The p-adic absolute value on p gives rise to the p-adic valuation vp(x)=logp|x|p. It satisfies the following basic properties:

Lemma 1.

For all a,bp we have

  • vp(ab)=vp(a)+vp(b), and

  • vp(a+b)min(vp(a),vp(b)), with equality if vp(a)vp(b).

The set p={xp:vp(x)0} forms a subring of p called the ring of p-adic integers. Its unique maximal ideal is generated by p, and p/pnp/pn for every n. This implies the following fact, which we will use several times:

Lemma 2.

For every xp{0} with n=vp(x) there exists a unique i{1,,p1} such that vp(xipn)>n.

This further implies that every p-adic number has a unique p-adic expansion:

Lemma 3.

Every 0xp with n=vp(x) is the limit (in the p-adic topology) of a unique series of the form i=nxipi with xi{0,,p1} for every i.

As usual, we let (see Figure 1)

(p):=p={x:vp(x)0}={ab:a,b,pb}.
Figure 1: Inclusions between the number domains studied in this article.

2.2 The structure 𝕼𝒑

It will be convenient for some of our results and proofs to take a logic perspective on the p-adic numbers; for an introduction to first-order logic, see [11]. A signature is a set τ of relation and function symbols, each equipped with an arity, which is a natural number. A (first-order) structure 𝔖 of signature τ consists of a set (the domain, typically denoted by the corresponding capital roman letter S), a function f𝔖:SkS for each function symbol fτ of arity k (the case k=0 is allowed; in this case, we refer to f as a constant symbol), and a relation R𝔖Sk for each relation symbol Rτ of arity k; we then say that f denotes f𝔖, and R denotes R𝔖.

A reduct of 𝔖 is a structure obtained from 𝔖 by taking a subset of the signature. If is a reduct of 𝔖, then 𝔖 is called an expansion of . A substructure of 𝔖 is a structure 𝔖 with the same signature τ as 𝔖 and domain SS such that for every function symbol fτ of arity k, the function f𝔖 is the restriction of f𝔖 to (S)k, and for every relation symbol Rτ of arity k, the relation R𝔖 equals R𝔖(S)k.

A first-order τ-formula is a formula built from first-order quantifiers ,, Boolean connectives ,,¬, and atomic formulas that are built from variables, the equality symbol =, and the symbols from τ in the usual way; for a proper definition, we refer to any standard introduction to mathematical logic or model theory, such as [11].

 Remark 4.

Often when p-adic numbers are treated from a logic perspective, they are introduced as “two-sorted structures”, with one sort for the p-adic numbers and one sort for the values, i.e., {}, and a function symbol v for the valuation. For our purposes, however, usual first-order structures (as introduced above) are sufficient.

We work with the structure 𝔔p which has the domain p and the signature

{+,1}{cp,cp,=cp,cp,c},

where

  • + is a binary function symbol that denotes the addition operation of p-adic numbers as introduced above;

  • 1 is a constant symbol which denotes 1(p)=p as introduced above;

  • cp is a unary relation symbol that denotes the unary relation {xpvp(x)c}; cp, =cp, and cp are defined analogously.

Sometimes, we specify structures as tuples; e.g., we write

𝔔p=(p;+,1,(cp)c,(cp)c,(=cp)c,(cp)c)

and do not distinguish between function and relation symbols and the respective functions and relations. Atomic formulas that are built from the relations cp, cp, =cp, and cp will be called valuation constraints. For c, we also use the symbols <cp as a shortcut for c1p, and >cp as a shortcut for c+1p.

2.3 Primitive Positive Formulas and CSPs

A formula is called primitive positive if it is of the form

x1,,xn(ψ1ψm)

where ψ1,,ψm are atomic. In primitive existential formulas, ψ1,,ψm are allowed to be negated atomic formulas as well, and existential formulas are disjunctions of primitive existential formulas. We use the concepts of primitive positive (and primitive existential, and existential) sentences, theories, definitions, definability, etc., as in the case of first-order logic (see, e.g., [11]), but restricting to primitive positive (primitive existential, and existential) formulas.

The computational problem of deciding the truth of a given primitive positive sentence φ in a fixed structure 𝔖 is called the constraint satisfaction problem (CSP) of 𝔖. We refer to the quantifier-free part ψ1ψm of φ as the instance of CSP(𝔖) (i.e., the existential quantifiers will be left implicit), and a satisfying assignment to the variables will also be called a solution to φ.

If the signature of 𝔖 is infinite, then the computational problem is not yet well-defined, because we still have to specify how to represent the symbols from the signature in the input; the choice of the representation can have an impact on the complexity of the CSP. For the structure 𝔔p introduced above, a natural representation is to represent the relation symbols cp, cp, =cp, and cp by the binary encoding of p and c. Note that vp(x)c holds if and only if vp(x)vp(pc). It will turn out that our polynomial-time algorithms can handle the constants c stored in binary (which makes pc a doubly exponentially large number). The hardness results, however, always make use of only finitely many symbols in the signature, and hence hold independently from the choice of the representation. We will therefore allow binary representations for the values c in the valuation constraints, since this allows the strongest formulations of our results.

We will determine the computational complexity of CSP(𝔖) for all reducts of 𝔔p (Theorem 27 and 28).

2.4 Primitive positive interpretations

Primitive positive interpretations can be used to obtain complexity reductions between CSPs. For d1, a d-dimensional primitive positive interpretation of a structure 𝔄 in a structure 𝔅 is given by a partial function I from Bd to A such that the preimages under I of the following sets are primitively positively definable in 𝔅:

  • A and the equality relation =A on A,

  • each relation of 𝔄, and

  • each graph of a function of 𝔄.

Lemma 5 (see, e.g., [2, Theorem 3.1.4]).

Let 𝔄 be a structure with a finite signature and a primitive positive interpretation in a structure 𝔅. Then 𝔅 has a reduct 𝔅 with a finite signature such that there is a polynomial-time reduction from CSP(𝔄) to CSP(𝔅).

3 versus 𝒑

Note that the structure 𝔔p has a substructure with domain . All our algorithms in Section 4 and hardness proofs in Section 5 can be stated equivalently over the uncountable field p or over . This is possible due to the following fact, which is a consequence of a result of Weispfenning [17].

Proposition 6.

For every p, the structure 𝔔p and its substructure with domain have the same first-order theory.

Proof.

Let τ be the signature {+,,0,1,π,div} where π is a constant symbol and div is a binary relation symbol. Weispfenning [17] introduces a certain first-order τ-theory, which he calls TDVFp; both and p give rise to models of TDVFp if π is interpreted as p and adivb if and only if vp(a)<vp(b). He then proves that TDVFp admits quantifier elimination for linear formulas [17, Theorem 3.6]. That is, every σ-formula, for σ:={+,0,1,π,div} (where the symbol for multiplication is missing, which is why these formulas are called “linear”), is over TDVFp equivalent to a quantifier-free σ-formula. Clearly, every atomic formula in the signature of 𝔔p can be defined by a σ-formula over p. Let φ be a first-order sentence in the signature of 𝔔p, and let φ be the first-order σ-sentence obtained from φ by replacing all atomic formulas by their defining σ-formula. Then φ is either equivalent to 0=0 over TDVFp or it is equivalent to 0=1 over TDVFp. It follows that either both 𝔔p and its substructure with domain satisfy φ, or both 𝔔p and its substructure with domain satisfy ¬φ, which is what we wanted to show.

Corollary 7.

For each p, the existential theory of 𝔔p and the existential theory of the expansion of (;+,1) by all relations of the form cp, cp, =cp and cp, for c, are in NP.

Proof.

By Proposition 6, these two existential theories are equal, so the claim follows from [9, Proposition 21], where it is proven that the existential theory of p in a more expressive language is in NP.

4 Algorithms

We first discuss how to measure the size of input instances to the computational problems studied in this text. For a,b{0} coprime, define h(±ab):=1+log|a|+log|b|, and define h(0):=1. Occasionally we might allow special coefficients like or ; we set h()=h():=1. For matrices A1,,Ar with coefficients in we let

C(A1,,Ar):=s+k=1ri,jh(akij),

where s is the maximal number of rows or columns of one of the Ak=(akij)i,j. This is our measure of size of a computational problem that is given by a set of rational matrices. A rational number p in the input is interpreted as the matrix p1×1, and a finite set D={d1,,dr} is interpreted as the matrix D=(d1,,dr)1×r. For example, the input size of the algorithm in Proposition 8 below is C(A,b,p,c,D1,,Dn).

We now present two algorithms. The first one, essentially for constraints of the form vp(x)c, is straightforward. The second one, mainly for constraints of the form vp(x)c, is more involved. In both settings, among all such valuation constraints on the same variable, there is a most restrictive one, which can easily be identified (in polynomial time), and therefore our algorithms are only formulated for one valuation constraint of the form vp(x)c (or of the form vp(x)c) per variable.

Proposition 8.

There is a polynomial time algorithm that decides, given m,n, p, c({})n, Am×n, bm, and finite sets D1,,Dn, whether there exists xn with Ax=b such that vp(xj)cj and vp(xj)Dj for j=1,,n.

Proof.

Let L:={xn:Ax=b} be the solution space of the system of linear equations. If L=, the algorithm outputs NO. Otherwise write

L={y0+k=1dλkyk:λ1,,λd} (4.1)

with y1,,ydn linearly independent. One can check whether L= and otherwise compute such d and y0,,yd in polynomial time: It is possible to compute one solution y0n of Ax=b in polynomial time [16, Corollary 3.3a]. Moreover, we can transform A by elementary row operations into a matrix A in row echelon form in polynomial time [16, Theorem 3.3], and from A we can read off the rank d of A and a basis y1,,yd of

{xn:Ax=0}={xn:Ax=0}.

If cj= let Cj=({})Dj, otherwise let Cj=(,cj]Dj, so that the algorithm has to decide whether there exists xL with vp(xj)Cj for every j. If for some j we have that vp(y0,j)Cj and yk,j=0 for every k=1,,d, then every xL satisfies vp(xj)=vp(y0,j)Cj, and the algorithm outputs NO. Otherwise, the algorithm outputs YES. To see that this is the correct answer, assume now that for every j we have vp(y0,j)Cj or yk,j0 for some k. Let cj=sup(Cj){}, where we set cj:= if Cj={}, and let

e:=max{|vp(yk,j)|:k=0,,d;j=1,,n;yk,j0}+max{0,c1,,cn}+1.

We claim that

x:=y0+k=1dp2keyk

is a solution to all the constraints. For each j let

Kj={k{0,,d}:yk,j0}.

If Kj{0}=, then, by our assumption, vp(xj)=vp(y0,j)Cj. Otherwise,

e(2k+1)=2kee<vp(p2keyk,j)<2ke+e=e(2k1)

for every kKj, so that the vp(p2keyk,j) for kKj are pairwise distinct, and therefore, with kj:=maxKj,

vp(xj) =vp(k=0kjp2keyk,j)=2kje+vp(ykj,j)<cj

by the choice of e. This shows in particular that vp(xj)Cj, as required.

 Remark 9.

We might not be able to compute a solution in the usual binary representation, as already for the single constraint vp(x)c the smallest solution (with respect to the p-adic absolute value |x|p:=pvp(x)) is pc. The algorithm not only works for the p-adic valuation on but for arbitrary so-called discrete valuations on a computable field K in which a solution of a given linear equation, a basis for the solution space of a homogeneous linear equation, and the valuation of an element can be computed; the resulting algorithm has a polynomial running time if these computations can be performed in polynomial time.

For our second algorithm we need some preparations. As the algorithm achieves a stronger result, we just mention without proof that the usual Hermite normal form allows to check in polynomial time whether Ax=b has a solution x(p)n (see, e.g., [16, Chapter 5]). However, already checking for solutions x with xj(p) for 1jr and xj for r+1jn requires new ideas. Also, if we want to allow constraints of the form vp(xj)cj rather than just vp(xj)0, one could replace xj by xjpcj, but only as long as pcj is polynomial in the input size. This would be the case if the cj would be coded in unary, but if the cj are coded in binary, as is our convention (see above), replacing xj by xjpcj will blow up the coefficients of the linear equation exponentially. We therefore do not replace xj by xjpcj but instead do some extra bookkeeping, exploiting the fact that although we might not be able to compute finite sums of elements of the form xjpcj in polynomial time, we can at least compute their valuations.

Lemma 10.

There is a polynomial-time algorithm which, given p, n, and pairs (a1,c1),, (an,cn)×, computes vp(i=1naipci){}.

Proof.

First remove all (ai,ci) with ai=0 from the list. If n=0 then output . Replace each (ai,ci) by (aipvp(ai),ci+vp(ai)) to assume that vp(ai)=0. Let c=minici. If there exists a unique i0 with c=ci0, then output vp(iaipci)=c. Otherwise assume without loss of generality that c=c1=c2. Then a1pc1+a2pc2=(a1+a2)pc. Remove (a1,c1) and (a2,c2) from the list and append (a1+a2,c). Repeating this process will terminate after at most n steps.

We also need a certain row echelon form. Before we give the definition, we present two motivating examples.

Example 11.

Suppose we want check whether a linear equation

a1x1++anxn=b (4.2)

with a1,,an,b has a solution xn with vp(xj)0 for every j{1,,n}. Such an x exists if and only if vp(b)minjvp(aj): For any such x,

vp(b)=vp(a1x1++anxn) min{vp(a1)+vp(x1),,vp(an)+vp(xn)}
minjvp(aj),

and conversely, if vp(aj0)vp(b) for some j0, we can let xj0:=aj01b and set the other xj to 0 (unless aj0=0, in which case b=0 and we can let x=0).

Example 12.

Suppose we are given a nonempty set X(p)n1 and want to check whether for some (x2,,xn)X there exists x1(p) satisfying (4.2). As long as a10, we can solve for x1 and obtain

x1=a11(bj=2najxj).

However, computing vp(x1) can be difficult from just the values vp(xj) for j=2,,n, since we are only guaranteed

vp(a11(bj=2najxj))min{vp(b)vp(a1),minj=2,,n(vp(aj)vp(a1)+vp(xj))}

and it can happen that the inequality is strict. The right hand side is certainly nonnegative as long as vp(a1)vp(b) and vp(a1)vp(aj) for every j. And in fact, when vp(a1)vp(aj) for every j, the condition vp(a1)vp(b) is also necessary for the left hand side to be nonnegative: If vp(a1)>vp(b), then vp(b)vp(a1)<0 but vp(aj)vp(a1)+vp(xj)0 for every j, so the inequality is actually an equality. Therefore, as long as a1 has minimal valuation among the ai, for any (x2,,xn)X there exists x1(p) satisfying (4.2) if and only if vp(a1)vp(b). This criterion easily generalizes to systems of several equations Ax=b where A is in row echelon form and each pivot element has minimal valuation in its row. This is what Definition 13 below expresses in the special case of the function f(a,j)=vp(a).

Definition 13.

A pivot function is a function

f:×{,}

such that f(a,j)= if and only if a=0. For a pivot function f, we say that a matrix A=(aij)i,jm×n is in f-minimal row echelon form if the following two conditions are satisfied.

  1. (1)

    A is in row echelon form, i.e., setting ji:=inf{j:aij0} for i{1,,n}, there exists k{0,,m} such that j1<<jk<jk+1==jm=.

  2. (2)

    Each pivot element ai,ji of A minimizes f within its row in the sense that for each i{1,,k},

    f(aiji,ji)=min{f(aij,j):j=ji,,n}.
Example 14.

To explain why we need more general functions f than just f(a,j)=vp(a), suppose we replace the conditions vp(xj)0 in Example 12 by vp(xj)cj for some cj. Rewriting this as vp(xjpcj)0 we see that we could instead consider the matrix A=(aij)i,j given by aij=aijpcj and apply the criterion from Example 12. However, the numbers pcj have exponential representation size. This can be avoided by replacing the condition that each pivot element aijipcji of A minimizes the function vp within its row by the condition that each pivot element aiji of A minimizes the function f(aij,j):=vp(aij)+cj within its row, where the second argument indicates the column.

We write GLm() for the general linear group of degree m over the field , i.e., the group of all invertible matrices in m×m. If σSn is a permutation, then Pσ=(δi,σ(i))i,jGLn() denotes the corresponding permutation matrix. For a pivot function f and σSn, we write fσ for the pivot function given by

fσ(a,j):={f(a,σ1(j)) if j{1,,n}f(a,j) otherwise.

If S is a set, then S denotes the set of non-empty words over the alphabet S, i.e., the set of finite sequences of elements of S.

Lemma 15.

Let f:××({}){,} and assume that for each c({}), the map fc defined by (a,j)f(a,j,c) is a pivot function. For every m,n, Am×n, and c({}) there exist UGLm() and σSn such that UAPσ is in (fc)σ-minimal row echelon form. If f is computable in polynomial time, then such U and Pσ can be computed in polynomial time.

Proof.

We describe how to get U and Pσ in terms of elementary row and column operations, where the only elementary column operations allowed are swapping two columns. If A=0, then we are done. Otherwise, possibly swap two rows to assume that a1j0 for some j. Choose k{1,,n} such that fc(a1k,k)=min{fc(a1j,j):j=1,,n} (which implies in particular that a1k0, since fc(0,k)= by assumption). If k1, then swap the first column with the k-th column. Add multiples of the first row to the other rows to achieve that ai1=0 for every i>1. Reduce the fractions in the entries of the matrix. Now take the (m1)×(n1)-submatrix with rows i=2,,m and columns j=2,,n, and iterate (extending each of the following row and column operations to the whole matrix). It is well-known that the representation size of the involved numbers stays polynomial (see, e.g., [16, Theorem 3.3]). This process terminates after at most max{m,n} steps, and the resulting matrix is of the desired form.

In the following, if xn and c({})n, we will write vp(x)c if vp(xj)cj for every j{1,,n}.

 Remark 16.

Note that if B=UAPσ for some UGLm() and σSn, then Ax=b has a solution xn such that vp(x)c if and only if By=Ub has a solution yn such that vp(y)Pσ1c (the map xPσ1x is a bijection between the solutions to the first system and the solutions to the second system).

The following result allows constraints of the form vp(x)c.

Theorem 17.

There is a polynomial-time algorithm that decides, given m,n, p, c({})n, Am×n, and bm, whether there exists xn with Ax=b such that vp(x)c.

In the case p=2, we can additionally treat constraints of the form v2(x)=c. The tuple δ encodes which constraint applies to which variable. The following is a generalisation of Theorem 17.

Theorem 18.

There is a polynomial-time algorithm that decides, given m,n, p, c({})n, δ{0,1}n, Am×n, and bm, whether there exists xn with Ax=b such that vp(x)c and, in the case p=2, δj=1, and cj, also vp(xj)=cj.

Proof.

We can assume that if δj=1 for some j, then p=2 and cj. Define the pivot function

f(a,j):=vp(a)+cj+δj2,

where we use the convention +():=. Clearly, f is computable in polynomial time (as a function of a, j, p and c and δ). By Lemma 15 we can compute U and Pσ in polynomial time such that UAPσ is in fσ-minimal row echelon form. We may replace A by UAPσ, b by Ub, c by Pσ1c, and δ by Pσ1δ (adapting the idea from Remark 16 appropriately in the case p=2), and henceforth assume without loss of generality that σ=id and that A is already in f-minimal row echelon form.

Let k and j1,,jk be as in Definition 13. The algorithm then outputs YES if

  1. (1)

    bi=0 for every i{k+1,,m}, and

  2. (2)

    vp(aiji)+cji+δjivp(bijjiδjaijpcj) for every i{1,,k},

and otherwise it outputs NO. Note that Condition (2) can be checked in polynomial time by Lemma 10. Since A is in row echelon form, Condition (1) holds if and only if there exists xn with Ax=b. To see that the algorithm gives the correct answer, we have to show that (1) and (2) holds if and only if there exists xn with Ax=b, vp(x)c and vp(xj)=cj for every j with δj=1.

For the forward direction, we assume that (1) and (2) hold and construct x as follows. For each j{1,,n}{j1,,jk}, let xj:=pcj if cj, and otherwise let xj:=0. For i=k,,1 define xji iteratively by

xji:=aiji1(bij>jiaijxj). (4.3)

Since A is in row echelon form, the so constructed x satisfies Ax=b. Moreover, for each j{j1,,jk} one has by definition that vp(xj)cj and vp(xj)=cj if δj=1, and one needs to show that the latter conditions also hold for j{j1,,jk}, using that A is in f-minimal row echelon form.

The full proof can be found in the arXiv-version of the paper [6].

5 NP-hardness and reductions

For a set A and aA, we use a as a relation symbol for the unary relation A{a}, and later write xa instead of a(x).

Lemma 19.

Let G be a finite cyclic group of order n3. Then CSP(G;+,0) is NP-hard. In particular, the primitive existential theory of (G;+) is NP-hard.

Proof.

The primitive positive formula e,z(e+e=ey+z=ex+z0) defines the binary relation over G. A finite graph with vertices [n] and edges E[n]2 can be colored with n=|G| colors if and only if (i,j)Exixj is satisfiable in G. For n3, the graph coloring problem is NP-hard [7, Section 4], so the claim follows from Lemma 5.

Lemma 20.

For every prime number p and every e the structure (/pe;+,0) has a primitive positive interpretation in (p;+,<ep).

Proof.

The quotient map γ:pp/pep/pe does the job: As γ1(0)=pep is primitively positively definable in (p;+), also the pullback of the graph of + is primitively positively definable in (p;+). Finally, vp(x)<e is a primitive positive definition in (p;+,<ep) of the unary relation γ1(0)=ppep.

Proposition 21.

The primitive positive theory of CSP(p;+,=0p) is NP-hard for p3, and CSP(p;+,1p) is NP-hard for all prime numbers p.

Proof.

If p3, then (/p;+,0) is NP-hard by Lemma 19. Moreover, by Lemma 20 it has a primitive positive interpretation in (p;+,=0p)=(p;+,<1p) and so CSP(p;+,=0p) is NP-hard by Lemma 5.

If p is an arbitrary prime number, then (/p2;+) is cyclic of order p23 and we have that CSP(/p2;+,0) is NP-hard by Lemma 19. The structure (/p2;+,0) has a primitive positive interpretation in (p;+,<2p) by Lemma 20, and hence (p;+,<2p)=(p;+,1p) is NP-hard by Lemma 5.

Let c be a positive integer. In primitive positive formulas over structures whose signature contains + and 1, we use cy as a shortcut for y++yc times, and c as a shortcut for c1. We also freely use the term x+c for c; if c=0, then this can be replaced by x, and if c<0, then this can be rewritten into a proper primitive positive formula by introducing a new existentially quantified variable y, replacing x+c by y, and adding a new conjunct x=y+|c|.

Lemma 22.

For p3, the primitive positive formula

y,z(vp(y)=0vp(z)=0x=y+z)

defines the relation 0p in (p;+,=0p). The primitive positive formula

y,z(v2(y)=0v2(z)=02x=y+z)

defines the relation 02 in (2;+,=02).

Proof.

First let p3. Suppose that xp is such that vp(x)0. Let i0{0,,p1} be such that vp(xi0)>0 (Lemma 2). Since p3, there exists i{1,,p1}{i0}, and x=(xi)+i with vp(xi)=0 and vp(i)=0. Then setting y to xi and z to i, all the three conjuncts of the given formula are satisfied. Conversely, if vp(y)=vp(z)=0, then vp(y+z)0.

For p=2, if x2 is such that v2(x)0, then 2x=(2x1)+1 with v2(2x1)=0 and v2(1)=0. Conversely, if y,z2 are such that v2(y)=v2(z)=0, then v2(y+z)=v2((y1)+(z1)+2)min{v2(y1),v2(z1),v2(2)}>0 by Lemma 2, so if 2x=y+z, then 1+v2(x)=v2(2x)=v2(y+z)1, hence v2(x)0.

The following solves an open problem from [9, Remark 23] for p=3; the NP-hardness for p5 was already shown in [9, Prop. 22].

Corollary 23.

Let p3 be prime. Then CSP(p;+,=0p) is NP-hard.

Proof.

Note that (p;+,=0p) has a primitive positive interpretation in (p;+,=0p), because 0p is primitive positive definable in (p;+,=0p) by Lemma 22. Since CSP(p;+,=0p) is NP-hard by Proposition 21, the statement follows from Lemma 5.

Lemma 24.

Let c. The relation =c2 has the primitive positive definition

y(v2(y)0x=2c+2c+1y)

in (2;+,1,02), and in (2;+,1) the primitive positive definition

y(x=2c+2c+1y).

Proof.

If v2(x)=c, then x=2c+2c+1y with v2(y)0, i.e., y2 (Lemma 2). Conversely, if x=2c+2c+1y with v2(y)0, then v2(x)=min{v2(2c),v2(2c+1y)}=c.

Note that the primitive positive formula in Lemma 24 has exponential representation size, since 2c+1 is a doubly exponentially large number. However, in all hardness proofs where we use this formula, c will be a constant and hence the length of the formula will be a constant as well.

Lemma 25.

For all p, the relation 0p has the primitive positive definition

i=1p1vp(xi)0

in (p;+,1,0p), and in (p;+) the primitive positive definition y(py=x).

Proof.

If vp(x)>0, then vp(xi)=vp(i)=0 for every 1i<p, and if vp(x)<0, then vp(xi)=vp(x)<0 for every i. Conversely, if vp(x)=0 there exists i0{1,,p1} with vp(xi0)>0 (Lemma 2). In p, vp(x)0 just means vp(x)1, i.e., x=py with yp.

Lemma 26.

Let d. Then dp has the primitive positive definition

i=1p1vp(x+ipd+1)d+1

in (p;+,1,d+1p) for p3, and in (2;+,1,d2) the primitive positive definition

v2(x+2d)d.

Proof.

First let p3. If vp(x)d, then vp(x+ipd+1)=vp(x)<d+1 for every i=1,,p1. Conversely, if vp(x)>d, then either vp(x)>d+1, in which case vp(x+ipd+1)=d+1 for every i=1,,p1, or vp(x)=d+1. In this case, there exists (exactly) one i0{1,,p1} with vp(x+i0pd+1)>d+1 (Lemma 2), and vp(x+ipd+1)=vp(pd+1)=d+1 for all i{1,,p1}{i0}. Such an i exists by the assumption that p3.

Now let p=2. If v2(x)<d, then v2(x+2d)=v2(x)<d, and if v2(x)=d, then v2(x+2d)>d (Lemma 2). Conversely, if v2(x)>d, then v2(x+2d)=d.

Theorem 27.

Let p be such that p3. Let be a reduct of 𝔔p whose signature τ contains {+,1}. Then CSP() is in P if is a reduct of one of the structures

(p;+,1,(cp)c,(cp)c) (5.1)
(p;+,1,(cp)c), (5.2)

and is NP-complete otherwise.

Proof.

The containment of CSP() in NP follows from Corollary 7. If τ contains =cp for some c, then the relation =0p is primitively positively definable in and CSP() is NP-hard by Corollary 23 and Lemma 5. So suppose that τ does not contain =cp for any c. If does not contain cp for any c, then is a reduct of the structure in (5.1). In this case, the polynomial-time tractability of CSP() follows from Proposition 8 and Proposition 6. So suppose that contains cp for some c. If τ also contains dp for some d, then the relation =0p is primitively positively definable as well, and we are again done. If τ contains cp for some c, then c1p is primitively positively definable in by Lemma 26, and we are in a case that we have already treated. Otherwise, τ contains neither of cp, cp, and =cp for any c, and hence is a reduct of the structure (5.2). The polynomial-time tractability in this case follows from Theorem 18 and Proposition 6.

Theorem 28.

Let be a reduct of 𝔔2 whose signature τ contains {+,1}. Then CSP() is in P if is a reduct of one of the structures

(2;+,1,(c2)c,(c2)c) (5.3)
(2;+,1,(=c2)c,(c2)c), (5.4)

and is NP-complete otherwise.

Proof.

The containment of CSP() in NP follows again from Corollary 7. If τ contains neither c2 nor c2 for any c, then is a reduct of the structure in (5.4), and the polynomial-time tractability of CSP() follows from Theorem 18 and Proposition 6. Otherwise, the relation 12 is primitively positively definable in by Lemma 26. If additionally 02 is primitively positively definable in , then the structure (2;+,12) has a primitive positive interpretation in , and the NP-hardness of CSP() follows from Proposition 21 via Lemma 5. If not, then by Lemma 22 we may assume that τ contains neither cp nor =cp for any c. In this case, is a reduct of the structure in (5.3), and the polynomial-time tractability of CSP() follows from Proposition 8 and Proposition 6.

6 Combining several primes, and the ordering

The complexity classification results for reducts of 𝔔p from Theorems 27 and 28 translate to complexity classification results for expansions of (;+,1) by relations from

τp:={cp,cp,=cp,cpc},

for fixed p, via Proposition 6. Interestingly, we can even derive results about expansions of (;+,1) by relations from pτp. Moreover, we may also obtain results about expansions of (;+,1,<) and of (;+,1,). The key to this is the following consequence of the approximation theorem for absolute values. As in the introduction, define |x|p:=pvp(x) for x.

Lemma 29.

Let m,n,r, ϵ>0, Am×n, bm, and let p1,,pr be distinct prime numbers. For each i{0,,r} let x(i)n be such that Ax(i)=b. Then there exists xn with Ax=b such that for every j{1,,n} and i{1,,r} we have |xjxj(0)|<ϵ and |xjxj(i)|pi<ϵ.

Proof.

Write the solution space Ln of Ax=b as in (4.1). The map Ld, y0+k=1dλkyk(λ1,,λd) is a homeomorphism with respect to the real topology and with respect to each p-adic topology. We can therefore assume without loss of generality that L=n, i.e., that A=0 and b=0. The claim is then precisely the statement of the approximation theorem for finitely many inequivalent absolute values on a field K ([13, Ch. XII, Thm. 1.2]) in the case K=, applied for each j{1,,n}.

Let 𝔔 be the expansion of (;+,1) by new relations for τ:={<}pτp.

Proposition 30.

Let φ be a conjunction of atomic ({+,1}τ)-formulas. Let φ< be all conjuncts of φ formed with the symbol <, let φp be all conjuncts of φ formed with symbols from τp, and let φ= be all the conjuncts formed with =. Then φ is satisfiable in 𝔔 if and only if φ=φ< is satisfiable in 𝔔 and φ=φp is satisfiable in 𝔔 for each p.

Proof.

The forward implication is trivial. For the converse, let s<n be a satisfying assignment for φ=φ<, let P denote the (finite) set of prime numbers such that φ contains symbols from τp, and for each pP let s(p)n be a satisfying assignment for φ=φp. The set U<n of satisfying assignments for φ< is open in the real topology, and the set Up of satisfying assignments for φp is open in the p-adic topology, for each p. In particular, there exists ϵ>0 such that the whole box {yn:|yjsj<|<ϵ for every j} is contained in U<, and similarly {yn:|yjsj(p)|p<ϵ for every j}Up for every pP. Therefore, by Lemma 29, there exists sn such that s satisfies φ= and sU<pPUp, hence s is a satisfying assignment for φ.

Proposition 30 only works for strict inequalities, and the corresponding statement would be false for weak inequalities. Algorithmically, however, there is a way to reduce the problem to the satisfiability problem for strict inequalities, and we obtain the following result.

Theorem 31.

Let be a reduct of (𝔔,) whose signature τ contains {1,+}. If τ contains

  • =cp for some c and p with p3, or

  • c1p and a relation from {c2p,c2p} for some c1,c2 and p with p3,

  • a relation from {c12,=c12} and a relation from {c22,c2p} for some c1,c2,

then CSP() is NP-complete; otherwise, CSP() is in P.

Proof.

If τ contains a symbol of the form =cp for some p3, or contains cp and a symbol of the form cp or cp, then the NP-hardness of CSP() follows from Theorem 27 and Proposition 6. Moreover, if the signature contains a symbol of the form =c2 or c2 and a symbol of the form p2 or cp, then the NP-hardness of CSP() follows from Theorem 28 and Proposition 6. Otherwise, let φ be an instance of CSP(). Similarly to Proposition 30 let

  • φ< be the conjuncts of φ formed with the symbol <,

  • φ the conjuncts formed with ,

  • φp the conjuncts formed with symbols from τp, and

  • φ= the conjuncts formed with =.

Let P be the set of p such that a symbol from τp occurs in φ. For any instance ψ denote by ψ< the instance obtained by replacing all by <.

We first check with known methods whether there is a solution for φ0:=φ=φ<φ (see, e.g., [16, final remark in Section 13.4]). If there is no solution, then output NO. Otherwise, let Ψ be the set of conjuncts of φ. We then test for each ψΨ whether the formula φ0ψ< is still satisfiable (again, using known methods). If φ0ψ< is unsatisfiable, then every solution of φ0 must satisfy the formula ψ= obtained from ψ by replacing with =. We then recursively run the entire algorithm on the formula where we replace the conjunct ψ by ψ=. Otherwise, if for every ψΨ, the formula φ0ψ< has a solution sψ, then φ0< has a solution s< as well. This is clear if Ψ=; otherwise, we note that the function f:k given by (x1,,xk)1ki=1kxi applied componentwise preserves +, 1, , and strongly preserves < in the sense that f(x1,,xk)<f(y1,,yk) if x1y1, …, xkyk and xi<yi for at least one i{1,,k}. This shows that we may take s<:=1|Ψ|ψΨsψ.

We run the polynomial-time algorithm from Theorem 28 on φ=φ2 and for each pP{2} the polynomial-time algorithm from Theorem 27 on φ=φp. If one of these algorithms returns NO, then φ is unsatisfiable by Proposition 6. If all of the algorithms return YES, then φ< has a solution by Proposition 6 and Proposition 30, and therefore also φ has a solution.

Finally, CSP(𝔔) is in NP as can be shown by repeating the argument from the previous paragraphs for an instance φ of CSP(𝔔) and using Corollary 7 instead of the polynomial-time algorithms.

7 Conclusions and an open problem

We have presented polynomial-time algorithms for the satisfiability problem of systems of linear equalities combined with various valuation constraints. For such systems, the satisfiability in p is equivalent to satisfiability in (Proposition 6). We also prove the matching NP-hardness results, answering open questions from [9] (Theorem 27 and Theorem 28; also see Table 1). Our results can be combined with the polynomial-time tractability result for the satisfiability of (strict and weak) linear inequalities over , and we may even solve valuation constraints for different prime numbers simultaneously (Theorem 31). Our polynomial-time tractability result for linear inequalities with valuation constraints of the form v2(x)=c, for constants c given in binary, would also follow from a positive answer to the following question, which remains open.

Question 32.

Is there a polynomial-time algorithm for the satisfiability problem of systems of weak linear inequalities where the coefficients of the inequalities are of the form 2c where c is represented in binary?

Such an algorithm would also imply a polynomial-time algorithm for mean-payoff-games (see [4] for related reductions) which is a problem currently not known to be in P.

Table 1: An overview of polynomial-time tractability and NP-hardness for systems of linear equations with valuation constraints.
p, p3 p, p=2 p, p3 p, p=2
P: Gauss algorithm P: Hermite normal form
vp(x)c P: 18
vp(x)=0 NP-hard: def. p 22 P: reduce to vp(x)0 24 NP-hard: 21 P: reduce to 24
vp(x)=c NP-hard: solves vp(x)=0 P: 18 NP-hard: solves vp(x)=0 P: 18
vp(x)0 P: special case of vp(x)c NP-hard: same as vp(x)=0 P: same as vp(x)=0
vp(x)1 P: special case of vp(x)c NP-hard: 21
vp(x)c P: 8 NP-hard: solves vp(x)1
vp(x)0 P: 8 or reduce to vp(x)0 via 25 P: reduces to via 25
vp(x)c P: 8 NP-hard: def. vp(x)1 via 26

References

  • [1] Ahmad Abdi, Gérard Cornuéjols, Bertrand Guenin, and Levent Tunçel. Dyadic linear programming and extensions. Mathematical Programming, 2024. doi:10.1007/s10107-024-02146-4.
  • [2] Manuel Bodirsky. Complexity of Infinite-Domain Constraint Satisfaction. Lecture Notes in Logic (52). Cambridge University Press, Cambridge, United Kingdom; New York, NY, 2021. doi:10.1017/9781107337534.
  • [3] Manuel Bodirsky, Peter Jonsson, and Timo von Oertzen. Essential convexity and complexity of semi-algebraic constraints. Logical Methods in Computer Science, 8(4), 2012. An extended abstract about a subset of the results has been published under the title Semilinear Program Feasibility at ICALP’10. doi:10.2168/LMCS-8(4:5)2012.
  • [4] Manuel Bodirsky, Georg Loho, and Mateusz Skomra. Reducing stochastic games to semidefinite programming. In the proceedings of the International Colloquium on Automata, Languages, and Programming, ICALP, 2025. https://arxiv.org/abs/2411.09646. doi:10.48550/arXiv.2411.09646.
  • [5] Andreas Dolzmann and Thomas Sturm. P-adic constraint solving. In Proceedings of the 1999 International Symposium on Symbolic and Algebraic Computation, ISSAC ’99, pages 151–158, New York, NY, USA, 1999. Association for Computing Machinery. doi:10.1145/309831.309894.
  • [6] Arno Fehm and Manuel Bodirsky. Polynomial-time tractable problems over the p-adic numbers, 2025. doi:10.48550/arXiv.2504.13536.
  • [7] Michael Garey and David Johnson. A guide to NP-completeness. CSLI Press, Stanford, 1978.
  • [8] Fernando Gouvêa. p-adic Numbers. Springer, 1997.
  • [9] Florent Guépin, Christoph Haase, and James Worrell. On the existential theories of Büchi arithmetic and linear p-adic fields. In Logic in Computer Science, LICS. IEEE, 2019. doi:10.1109/LICS.2019.8785681.
  • [10] Christoph Haase and Alessio Mansutti. On Deciding Linear Arithmetic Constraints Over p-adic Integers for All Primes. In Filippo Bonchi and Simon J. Puglisi, editors, 46th International Symposium on Mathematical Foundations of Computer Science (MFCS 2021), volume 202 of Leibniz International Proceedings in Informatics (LIPIcs), pages 55:1–55:20, Dagstuhl, Germany, 2021. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. doi:10.4230/LIPIcs.MFCS.2021.55.
  • [11] Wilfrid Hodges. A shorter model theory. Cambridge University Press, Cambridge, 1997.
  • [12] Peter Jonsson and Johan Thapper. Constraint satisfaction and semilinear expansions of addition over the rationals and the reals. CoRR, abs/1506.00479, 2015. arXiv:1506.00479.
  • [13] Serge Lang. Algebra. Springer, 2002. Revised third edition.
  • [14] Yuri Matiyasevich. Enumerable sets are Diophantine. Doklady Akademii Nauk SSSR, 191:279–282, 1970.
  • [15] Marcus Schaefer and Daniel Štefankovič. Fixed points, Nash equilibria, and the existential theory of the reals. Theory of Computing Systems, pages 1–22, 2015.
  • [16] Alexander Schrijver. Theory of Linear and Integer Programming. Wiley - Interscience Series in Discrete Mathematics and Optimization, 1998.
  • [17] Volker Weispfenning. The complexity of linear problems in fields. Journal of Symbolic Computation, 5(1):3–27, 1988. doi:10.1016/S0747-7171(88)80003-8.