ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 12 Feb 2017 17:05:59 -0600Find all non-negative integer solutions of $a+b+c+d+e = 8$ in Sagemathhttps://ask.sagemath.org/question/36564/find-all-non-negative-integer-solutions-of-abcde-8-in-sagemath/Find all non-negative integer a, b, c,d, e such that
$$a+b+c+d+e = 8$$
Is there any method for this? I have no idea. I can just fix the limit.Sat, 11 Feb 2017 03:30:54 -0600https://ask.sagemath.org/question/36564/find-all-non-negative-integer-solutions-of-abcde-8-in-sagemath/Comment by kcrisman for <p>Find all non-negative integer a, b, c,d, e such that</p>
<p>$$a+b+c+d+e = 8$$</p>
<p>Is there any method for this? I have no idea. I can just fix the limit.</p>
https://ask.sagemath.org/question/36564/find-all-non-negative-integer-solutions-of-abcde-8-in-sagemath/?comment=36568#post-id-36568See also http://math.stackexchange.com/questions/2139283/find-all-non-negative-integers-satisfying-the-conditions where this has several answers.Sat, 11 Feb 2017 07:28:41 -0600https://ask.sagemath.org/question/36564/find-all-non-negative-integer-solutions-of-abcde-8-in-sagemath/?comment=36568#post-id-36568Answer by tmonteil for <p>Find all non-negative integer a, b, c,d, e such that</p>
<p>$$a+b+c+d+e = 8$$</p>
<p>Is there any method for this? I have no idea. I can just fix the limit.</p>
https://ask.sagemath.org/question/36564/find-all-non-negative-integer-solutions-of-abcde-8-in-sagemath/?answer=36565#post-id-36565While this particular example could be easily done without Sage, you can have a look at Mixed Integer Linear Programming as a general method, see http://doc.sagemath.org/html/en/reference/numerical/sage/numerical/mip.html and http://doc.sagemath.org/html/en/thematic_tutorials/linear_programming.htmlSat, 11 Feb 2017 07:06:05 -0600https://ask.sagemath.org/question/36564/find-all-non-negative-integer-solutions-of-abcde-8-in-sagemath/?answer=36565#post-id-36565Answer by John Palmieri for <p>Find all non-negative integer a, b, c,d, e such that</p>
<p>$$a+b+c+d+e = 8$$</p>
<p>Is there any method for this? I have no idea. I can just fix the limit.</p>
https://ask.sagemath.org/question/36564/find-all-non-negative-integer-solutions-of-abcde-8-in-sagemath/?answer=36591#post-id-36591If the order of `a`, `b`, etc. matters:
sage: IntegerVectors(8, 5)
Integer vectors of length 5 that sum to 8
sage: list(IntegerVectors(8, 5))
[[8, 0, 0, 0, 0],
[7, 1, 0, 0, 0],
[7, 0, 1, 0, 0],
[7, 0, 0, 1, 0],
[7, 0, 0, 0, 1],
[6, 2, 0, 0, 0],
[6, 1, 1, 0, 0],
[6, 1, 0, 1, 0],
[6, 1, 0, 0, 1],
...
If you don't care about the order:
sage: Partitions(8, max_length=5)
Partitions of the integer 8 satisfying constraints max_length=5
sage: list(Partitions(8, max_length=5))
[[8],
[7, 1],
[6, 2],
[6, 1, 1],
[5, 3],
[5, 2, 1],
[5, 1, 1, 1],
[4, 4],
[4, 3, 1],
[4, 2, 2],
[4, 2, 1, 1],
[4, 1, 1, 1, 1],
[3, 3, 2],
[3, 3, 1, 1],
[3, 2, 2, 1],
[3, 2, 1, 1, 1],
[2, 2, 2, 2],
[2, 2, 2, 1, 1]]
Sun, 12 Feb 2017 17:05:59 -0600https://ask.sagemath.org/question/36564/find-all-non-negative-integer-solutions-of-abcde-8-in-sagemath/?answer=36591#post-id-36591