Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to make a list (efficiently) which is the set of lattice solutions of the following equations (depends on $k$):

$x_0\geq 0$ and $x_i\in [0,4k]$ for $i=1,\ldots,4$ satisfies

$x_0+x_3\leq k+3$, $x_0+x_2+x_3\leq 2k+7$, $x_0+x_1+x_2+x_3\leq 3k+11$, $x_0\leq 15$, $x_1+x_2+x_3+x_4=4k$.

How can I do that?

EDIT: For example, by doing the following I can make a list of (easy) lattice equations:

$x,y\in[1,5]$, $x+y\leq 5$.

Flatten[Table[{i, j}, {i, 1, 5}, {j, 1, 5 - i}], 1]

But I want to make this using if sentence.

share|improve this question
    
What have you already tried? –  belisarius Jun 3 '13 at 15:55
    
What does $0\leq x_1, \ldots, x_4 \leq 4k$ mean? Does it imply that $0 \leq x_i\mbox{ , }i \in [1\mbox{,}4]$? or that all $x_i \leq 4k$? –  rcollyer Jun 3 '13 at 15:57
    
I edited my trial and modified notation. –  user7540 Jun 3 '13 at 16:52
add comment

1 Answer

up vote 2 down vote accepted

Maybe something like :

eqs = {x0 + x3 <= k + 3, x0 + x2 + x3 <= 2 k + 7, x0 + x1 + x2 + x3 <= 3 k + 11, 
       x0 <= 15, x1 + x2 + x3 + x4 == 4 k};
vars = {x0, x1, x2, x3, x4, x5};
const = 1 <= # <= 5 & /@ vars;

sol=Solve[Join[eqs /. k -> 1, const], vars, Integers];

As suggested by @amr, the values can be obtained with sol[[All,All,2]].

share|improve this answer
    
I want list value data output. (e.g. $\{1,2\}$ not $x\to1, y\to 2$.) –  user7540 Jun 3 '13 at 17:22
2  
@user7540 a -> b is shorthand for Rule[a, b]. you can just do /. Rule -> List on the output –  amr Jun 3 '13 at 17:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.