First time here? Check out the FAQ!

Ask Your Question
2

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

asked 3 years ago

Rune gravatar image

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?

Preview: (hide)

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

2 Answers

Sort by » oldest newest most voted
4

answered 3 years ago

rburing gravatar image

updated 3 years ago

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),)
Preview: (hide)
link

Comments

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

Rune gravatar imageRune ( 3 years ago )
3

answered 3 years ago

Max Alekseyev gravatar image

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)
Preview: (hide)
link

Comments

This works as well, but the other answer gave more info on how Sage works.

Rune gravatar imageRune ( 3 years ago )

Question Tools

Stats

Asked: 3 years ago

Seen: 835 times

Last updated: Jan 19 '22