Ask Your Question
2

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

asked 2022-01-16 20:22:29 +0200

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?

edit retag flag offensive 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

2 Answers

Sort by ยป oldest newest most voted
4

answered 2022-01-19 13:42:50 +0200

rburing gravatar image

updated 2022-01-19 13:45:00 +0200

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),)
edit flag offensive delete link more

Comments

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

Rune gravatar imageRune ( 2022-01-20 21:29:12 +0200 )edit
3

answered 2022-01-19 20:29:34 +0200

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)
edit flag offensive delete link more

Comments

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

Rune gravatar imageRune ( 2022-01-20 21:29:53 +0200 )edit

Question Tools

Stats

Asked: 2022-01-16 20:14:40 +0200

Seen: 441 times

Last updated: Jan 19 '22