0
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ What have you already tried? $\endgroup$ Commented Jun 3, 2013 at 15:55
  • $\begingroup$ 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$? $\endgroup$
    – rcollyer
    Commented Jun 3, 2013 at 15:57
  • $\begingroup$ I edited my trial and modified notation. $\endgroup$
    – user7540
    Commented Jun 3, 2013 at 16:52

1 Answer 1

2
$\begingroup$

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]].

$\endgroup$
2
  • $\begingroup$ I want list value data output. (e.g. $\{1,2\}$ not $x\to1, y\to 2$.) $\endgroup$
    – user7540
    Commented Jun 3, 2013 at 17:22
  • 2
    $\begingroup$ @user7540 a -> b is shorthand for Rule[a, b]. you can just do /. Rule -> List on the output $\endgroup$
    – amr
    Commented Jun 3, 2013 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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