# Limit solution domain in Solve

How should you write the Solve command or another to give me solutions to this equation for example

1. integers
2. rationals

Here are the equations:

Solve[
x + y + z == 100 &&
x == 7*p &&
y == 17*q &&
z == 27*r,
{x, y, z}
]

New contributor
BeTDa is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
• @MarcoB ,thaks, I wrote it right, I'm sure I will take it – BeTDa May 23 at 3:19
• Good, just checking. I’ve taken the liberty to fix it in your question then. – MarcoB May 23 at 3:21
• Shouldn't for this kind of condition, the domain should be more restrictive since for Integers, given any p you can find q and r which would satisfy the condition and for Rationals, given any p and q you can find an r that will satisfy the condition. But only for more restrictive domains which are not closed under subtraction like PositiveIntegers, NonNegativeIntegers, PositiveRationals, NonNegativeRationals you can find interesting solutions. – user13892 May 23 at 3:58
• @user13892 I think you are right about the restricted domain part. I was trying to find out why solve gave wrong result when telling it r,p,q are integers only. – Nasser May 23 at 4:16

For $$p,q,r$$ integers using Solve it actually did not work. I got result from Solve which is not valid, I do not know if this is a bug or it is by design

ClearAll[x, y, z, p, q, r];
eq1 = x + y + z == 100;
eq2 = x == 7*p;
eq3 = y == 17*q;
eq4 = z == 27*r;
const = Element[{p, q, r}, Integers];
sol = {x, y, z} /.
First@Solve[{eq1, eq2, eq3, eq4, const}, {x, y, z}] // Normal

(* {7 p, 17 q, 100 - 7 p - 17 q} *)


So r is implicit in the above. Can be found from the relation z == 27*r which means r = z/27. But when I run the above over few integer values of p,q, it shows r is not integer:

sol0 = Flatten[
Table[Evaluate[
Flatten@{sol, sol[[1]] + sol[[2]] + sol[[3]], p, q, sol[[3]]/27,
7*p, 17*q}], {p, 1, 3}, {q, 1, 3}], 1]

Grid[PrependTo[sol0, {"x", "y", "z", "x+y+z", "p", "q", "r", "x=7*p", "y=17*q"}],
Frame -> All]


However, it "works" if constraint is as mentioned in comments above, more restrictive than Integers. For example

const = Element[{p, q, r}, PositiveIntegers];
sol = {x, y, z} /.
First@Solve[{eq1, eq2, eq3, eq4, const}, {x, y, z}] // Normal


and for PositiveRationals

const = Element[{p, q, r}, PositiveRationals];
sol = {x, y, z} /.
First@Solve[{eq1, eq2, eq3, eq4, const}, {x, y, z}] // Normal

(* {7 p, 17 q, 100 - 7 p - 17 q} *)
sol0 = Flatten[
Table[Evaluate[
Flatten@{sol, sol[[1]] + sol[[2]] + sol[[3]], p, q, sol[[3]]/27,
7*p, 17*q, sol[[3]]}], {p, 1, 4}, {q, 1, 4}], 1]
Grid[PrependTo[
sol0, {"x", "y", "z", "x+y+z", "p", "q", "r", "x=7*p", "y=17*q",
"27*r"}], Frame -> All]


And now it is correct, r is rational, but that is OK.

So I think Solve did not work in first case above, because r,p,q domain was set as Integers. May be this is by design. I do not know now.

• @Nasser_Thank you for your answer and the time invested in it. I have enough points. – BeTDa May 23 at 7:33

If you are looking for integer p,q,r, you should just use FrobeniusSolve[] instead:

FrobeniusSolve[{7, 17, 27}, 100]
{{7, 3, 0}, {8, 1, 1}}


Check:

%.{7, 17, 27}
{100, 100}