# Finding a unique integer solution to a set of inequalities [closed]

I am trying to find the unique integer solution to a set of equalities and inequalities. The equations I have are 0<=k0<p-1 and k=k0+j(p-1). I know that for p a prime >=5 and k an integer, there is is a unique set of integers k0 and j such that these equations are satisfied. However, I can't seem to implement this.

What I have is

k0,j = var('k0 j')
solve([0<=k0<p-1,k==k0+j(p-1),k0 in ZZ,j in ZZ],k0,j)


Where I added the "in ZZ" parts later to try and force it to give me an answer, but no matter what I plug in for p and k, the output is always just

(k0, j)


What exactly am I doing wrong?

edit retag reopen merge delete

### Closed for the following reason the question is answered, right answer was accepted by Rune close date 2022-01-22 20:20:15.013423

Sort by ยป oldest newest most voted

Sage doesn't work that way, e.g. k0 in ZZ and j in ZZ evaluate to False because they are symbolic variables. You meant assume(k0, 'integer') and assume(j, 'integer'). Still, solve doesn't seem very good at your problem. Instead, you can define your solution set as a Polyhedron and ask for its integral points:

sage: p = 5
sage: k = 1
sage: Polyhedron(ieqs=[[0,1,0], [p-2,-1,0]], eqns=[[-k, 1,p-1]]).integral_points()
((1, 0),)

more

Thanks, this works. I'm still new to Sage, so I'm still learning how it works.

( 2022-01-20 21:29:12 +0200 )edit

The given conditions imply that k0 and j are simply the remainder and quotient of division of k by p-1. Correspondingly, they can be computed as:

j, k0 = k.quo_rem(p-1)

more