2
$\begingroup$

I have been trying to figure out how to solve a system of inequalities relatively. I don't care about values, I just want all possible ordering. An example system might be:$${b > r,\; p > r,\; c - 1 = p,\; c < x,\; h > x,\; h < e, }$$ $${r < k,\; q > k,\; l - 1 = q,\; l < h,\; k > p}$$

I want to get all possible ways they could be arranged in order, satisfying the inequalities. If I am not explaining this well, please let me know, I'm not sure how to describe what I'm looking in a more mathematical way.

Is there a straightforward way to do it? I tried using Reduce over the domain of Integers, but it choked. FindInstance was able to find a single instance, but not more than that.

Edit: I tried:

FindInstance[{ b > r, p > r, c - 1 == p, c < x, h > x, h < e, 
               r < k, q > k, l - 1 == q, l < h, k > p}, 
             { b, r, p, c, x, h, e, k, q, l}]
{{b -> 0, r -> -1, p -> 0, c -> 1, x -> 2, h -> 3, e -> 4, k -> 1/2, q -> 1, l -> 2}}

This is basically what I'm looking for, but when I tried increasing n, I let it run for 5+ minutes and never got a solution.

I also tried:

Reduce[{ b > r, p > r, c - 1 == p, c < x, h > x, h < e, 
         r < k, q > k, l - 1 == q, l < h, k > p}, 
       {b, r, p, c, x, h, e, k, q, l}]
 b ∈ Reals && r < b && p > r && c == 1 + p && x > 1 + p && h > x && 
 e > h && p < k < -1 + h && k < q < -1 + h && l == 1 + q

when I tried Reduce over the domain Integers, the output was several hundred lines long.

Edit : Sorting by the second element, the revised version is:

 DeleteDuplicates[
   Map[ First, Map[ SortBy[ #, Last] &, 
                    FindInstance[{ b > r, p > r, c - 1 == p, c < x, h > x, h < e, r < k, 
                                   q > k, l - 1 == q, l < h, k > p}, 
                                   { b, r, p, c, x, h, e, k, q, l}, 10]
                  ], {2}]]
$\endgroup$
  • $\begingroup$ Please share your Reduce[] and FindInstance[] codes with us $\endgroup$ – Dr. belisarius Nov 21 '13 at 1:56
  • $\begingroup$ @belisarius just added $\endgroup$ – kyryx Nov 21 '13 at 2:00
  • 1
    $\begingroup$ Re:your Edit. Your Map[First, ...] is getting the name of the variables only ... and they (the names) are always the same (of course). I don't get your point $\endgroup$ – Dr. belisarius Nov 21 '13 at 2:29
  • $\begingroup$ @belisarius You're correct, I meant to sort by the second element. I posted a corrected version. I appreciate the help. $\endgroup$ – kyryx Nov 21 '13 at 2:42
3
$\begingroup$

Try for example:

FindInstance[{b > r, p > r, c - 1 == p, c < x, h > x, h < e, r < k, 
             q > k, l - 1 == q, l < h, k > p}, {b, r, p, c, x, h, e, k, q, l}, 15]

which gives you 15 different solutions

| improve this answer | |
$\endgroup$
  • $\begingroup$ Very odd, I just realized when I was trying it, I specified the domain Integers, which never gave a solution. But without integers, it does it instantly.. $\endgroup$ – kyryx Nov 21 '13 at 2:13
  • $\begingroup$ I actually am not sure that works. I don't think those solutions are unique. See my edit above. $\endgroup$ – kyryx Nov 21 '13 at 2:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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