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.

Consider the following;

all = {a, b, c, d, e};
mean = Mean[all];
a1=Accumulate@Prepend[all, 0];
a2=Accumulate@Append[Table[mean, {i, Length[all]}], 0];
a3=a2-a1;
a4=Map[Reduce[# >= 0, all] &, a3]

Now I would like Mathematica to solve this with the restriction that all elements of all are positive Integers.

share|improve this question
    
Thanks for the answers. I have to admit that I was hoping for a result that says that a4 is always true, for all positive Integers, but as it appears this is not the case. However, I think we can leave my question with the edited heading as it is, in any case, somebody has a similar problem. –  John Apr 12 '12 at 22:19

2 Answers 2

Reduce allows you to specify the domain of Reals, Complexes, or Integers as the third parameter. But, positivity is not directly specifiable at that point. Instead, it must be added to the expr being reduced as an added condition. A simple form of this condition would be

 And @@ Thread[all > 0]

which is equivalent to

a > 0 && b > 0 && c > 0 && d > 0 && e > 0

Combining this with the Integers domain gives this form for Reduce:

Reduce[# >= 0 && And @@ Thread[all > 0], all, Integers] &

As a word of caution, this will result in a very, very large output as Reduce uses GeneratedParameters for its unknown integer coefficients. For the second inequality, this results in 34 unknown coefficients.

share|improve this answer

This may give you some ideas.

In[230]:= all = {a, b, c, d, e};
mean = Mean[all];
a1 = Accumulate@Prepend[all, 0];
a2 = Accumulate@Append[Table[mean, {i, Length[all]}], 0];
a3 = a2 - a1;

Your solution sets will be unbounded, and require many parameters to describe them. For purposes of illustration I opted instead to combine your inequalities and add another to make the set not too large.

solnb = 
 Reduce[Join[Thread[a3 >= 0], Thread[a3 <= 2], 
   Thread[all >= 1], {Element[all, Integers]}], all, 
  Backsubstitution -> True]

Out[237]= (a == 1 && b == 1 && c == 1 && d == 1 && 
   e == 1) || (a == 1 && b == 1 && c == 1 && d == 1 && 
   e == 2) || (a == 1 && b == 1 && c == 1 && d == 2 && 
   e == 1) || (a == 1 && b == 1 && c == 2 && d == 1 && 
   e == 1) || (a == 1 && b == 2 && c == 1 && d == 1 && 
   e == 1) || (a == 1 && b == 2 && c == 1 && d == 1 && 
   e == 2) || (a == 1 && b == 2 && c == 1 && d == 2 && 
   e == 1) || (a == 1 && b == 2 && c == 2 && d == 1 && 
   e == 1) || (a == 1 && b == 3 && c == 1 && d == 1 && 
   e == 1) || (a == 2 && b == 1 && c == 1 && d == 1 && 
   e == 1) || (a == 2 && b == 1 && c == 1 && d == 1 && 
   e == 2) || (a == 2 && b == 1 && c == 1 && d == 2 && 
   e == 1) || (a == 2 && b == 1 && c == 2 && d == 1 && 
   e == 1) || (a == 2 && b == 1 && c == 2 && d == 1 && 
   e == 2) || (a == 2 && b == 1 && c == 2 && d == 2 && 
   e == 1) || (a == 2 && b == 1 && c == 3 && d == 1 && 
   e == 1) || (a == 2 && b == 2 && c == 1 && d == 1 && 
   e == 1) || (a == 2 && b == 2 && c == 1 && d == 1 && 
   e == 2) || (a == 2 && b == 2 && c == 1 && d == 2 && 
   e == 1) || (a == 2 && b == 2 && c == 2 && d == 1 && 
   e == 1) || (a == 2 && b == 2 && c == 2 && d == 1 && 
   e == 2) || (a == 2 && b == 2 && c == 2 && d == 2 && 
   e == 1) || (a == 2 && b == 2 && c == 2 && d == 2 && 
   e == 2) || (a == 2 && b == 2 && c == 2 && d == 3 && 
   e == 1) || (a == 2 && b == 2 && c == 3 && d == 1 && 
   e == 1) || (a == 2 && b == 2 && c == 3 && d == 1 && 
   e == 2) || (a == 2 && b == 2 && c == 3 && d == 2 && 
   e == 1) || (a == 2 && b == 2 && c == 4 && d == 1 && 
   e == 1) || (a == 2 && b == 3 && c == 1 && d == 1 && 
   e == 2) || (a == 2 && b == 3 && c == 1 && d == 2 && 
   e == 1) || (a == 2 && b == 3 && c == 1 && d == 2 && 
   e == 2) || (a == 2 && b == 3 && c == 1 && d == 3 && 
   e == 1) || (a == 2 && b == 3 && c == 2 && d == 1 && 
   e == 1) || (a == 2 && b == 3 && c == 2 && d == 1 && 
   e == 2) || (a == 2 && b == 3 && c == 2 && d == 2 && 
   e == 1) || (a == 2 && b == 3 && c == 3 && d == 1 && 
   e == 1) || (a == 2 && b == 4 && c == 1 && d == 1 && 
   e == 2) || (a == 2 && b == 4 && c == 1 && d == 2 && 
   e == 1) || (a == 2 && b == 4 && c == 2 && d == 1 && 
   e == 1) || (a == 3 && b == 1 && c == 1 && d == 1 && 
   e == 2) || (a == 3 && b == 1 && c == 1 && d == 2 && 
   e == 1) || (a == 3 && b == 1 && c == 2 && d == 1 && 
   e == 1) || (a == 3 && b == 1 && c == 2 && d == 1 && 
   e == 2) || (a == 3 && b == 1 && c == 2 && d == 2 && 
   e == 1) || (a == 3 && b == 1 && c == 2 && d == 2 && 
   e == 2) || (a == 3 && b == 1 && c == 2 && d == 3 && 
   e == 1) || (a == 3 && b == 1 && c == 3 && d == 1 && 
   e == 1) || (a == 3 && b == 1 && c == 3 && d == 1 && 
   e == 2) || (a == 3 && b == 1 && c == 3 && d == 2 && 
   e == 1) || (a == 3 && b == 1 && c == 4 && d == 1 && 
   e == 1) || (a == 3 && b == 2 && c == 1 && d == 1 && 
   e == 2) || (a == 3 && b == 2 && c == 1 && d == 2 && 
   e == 1) || (a == 3 && b == 2 && c == 1 && d == 2 && 
   e == 2) || (a == 3 && b == 2 && c == 1 && d == 3 && 
   e == 1) || (a == 3 && b == 2 && c == 2 && d == 1 && 
   e == 1) || (a == 3 && b == 2 && c == 2 && d == 1 && 
   e == 2) || (a == 3 && b == 2 && c == 2 && d == 2 && 
   e == 1) || (a == 3 && b == 2 && c == 3 && d == 1 && 
   e == 1) || (a == 3 && b == 3 && c == 1 && d == 1 && 
   e == 2) || (a == 3 && b == 3 && c == 1 && d == 2 && 
   e == 1) || (a == 3 && b == 3 && c == 2 && d == 1 && 
   e == 1) || (a == 4 && b == 1 && c == 1 && d == 2 && 
   e == 2) || (a == 4 && b == 1 && c == 1 && d == 3 && 
   e == 1) || (a == 4 && b == 1 && c == 2 && d == 1 && 
   e == 2) || (a == 4 && b == 1 && c == 2 && d == 2 && 
   e == 1) || (a == 4 && b == 1 && c == 3 && d == 1 && 
   e == 1) || (a == 4 && b == 2 && c == 1 && d == 1 && 
   e == 2) || (a == 4 && b == 2 && c == 1 && d == 2 && 
   e == 1) || (a == 4 && b == 2 && c == 2 && d == 1 && e == 1)

The way to specify your requirements can be taken from the Reduce invocation above.

share|improve this answer

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.