Skip to main content
1 of 3

How to find the integer solution number of a linear system with inequalities?

I have the following system with mixed equality and inequalities defined as:

n = 100;
eqn = (n1 + n3 + n5 == n2 + n4 + n6) && (n1 >= 
    n2) && (n1 - n2 + n3 - n4 >= 0) && (n1 <= n) && (n1 - n2 + n3 <= 
    n) && (n1 - n2 + n3 - n4 + n5 <= n) && (2 n <= 
    n1 + n2 + n3 + n4 + n5 + n6 <= 6 n);

How can I find all the integer solutions and especially the number of all integer solutions?

It seems Reduce or Solve does not work:

sol = Reduce[eqn, {n1, n2, n3, n4, n5, n6}, Integers]

produces:

(n1 | n2 | n3 | n4 | n5 | n6) \[Element] Integers && -100 <= n1 <= 
  100 && ((n2 == -100 && n3 == -n1 && n4 == 100 && n5 == 100 && 
     n6 == 100) || (-100 < n2 <= 
      n1 && ((n3 == -n1 && n4 == -n2 && n5 == 100 && 
         n6 == 100) || (-n1 < n3 <= 
          100 - n1 + 
           n2 && ((n4 == -n2 && n5 == 100 - n1 - n3 && 
             n6 == 100) || (-n2 < n4 <= n1 - n2 + n3 && 
             100 - n1 - n3 <= n5 <= 100 - n1 + n2 - n3 + n4 && 
             n6 == n1 - n2 + n3 - n4 + n5))))))