# Solve diophantine equation with constraints by counting and listing results [duplicate]

This question already has an answer here:

I need this code to list me and say the total solutions found

Reduce[3 x + 2 y == 8800 && 1800 <= x <= 3200 &&
1000 <= y <= 1500 , {x, y}, Integers] /. Or -> List /. And -> List


this is an example, there are many more Thank you

## marked as duplicate by Carl Woll, Nasser, Michael E2, m_goldberg, Alexey PopkovOct 8 '17 at 0:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

• Why not use Solve instead of Reduce? – Carl Woll Oct 7 '17 at 1:30
• I find Reduce more versatile – juan muñoz Oct 7 '17 at 1:32
• You can use the Solve option Method->Reduce – Bob Hanlon Oct 7 '17 at 2:16

## 1 Answer

Using Solve produces the desired results directly:

Solve[
3 x + 2 y == 8800 && 1800<=x<=3200 && 1000<=y<=1500,
{x,y},
Integers
] //Length


167

However, the OP would prefer to use Reduce. To have Reduce produce similar output, one needs to change SystemOptions. Here is some code to do so:

InternalWithLocalSettings[
old = OptionValue[SystemOptions[], "ReduceOptions"->"DiscreteSolutionBound"];
SetSystemOptions["ReduceOptions" -> "DiscreteSolutionBound" -> 1000],
Reduce[
3 x + 2 y == 8800 && 1800<=x<=3200 && 1000<=y<=1500,
{x,y},
Integers
] //Length,
SetSystemOptions["ReduceOptions" -> "DiscreteSolutionBound" -> old]
]


167

• ok thank you, that simple, I did not see it before, but I just need solutions how do I do this 1) x = 516, and = 2226 2) x == 518, y = 2223 3) x = 520, y = 2220 – juan muñoz Oct 7 '17 at 2:10
• @juanmuñoz There are no solutions for x = 516, 518, 520. Define sol = Solve[...] (from answer), then the solution with the lowest x-value is MinimalBy[sol, #[[1, 2]] &], which is {x -> 1934, y -> 1499}`. – aardvark2012 Oct 7 '17 at 10:18
• an error in writing, I do not understand how to do what you say, then you put the code please, my knowledge is limited and I need it for something punctual – juan muñoz Oct 7 '17 at 12:38