# Solve an equation with specific domain?

How can I write a code in Mathematica to solve an equation with variable in specific domains? For instance, I want to write a code for

Solve[{2 x + 1 == y && x > 0 && y > 0}, {x, y}, Integers] // Column


with extra conditions that $x\in\{1,5,8,17,31,111\}$. How can I put this condition inside the command Solve[ ] among other conditions?

• When the list is a finite set, could just make an equation: In:= xlist = {1, 5, 8, 17, 31, 111}; Solve[{2 x + 1 == y && x > 0 && y > 0 && Apply[Times, x - xlist] == 0}, {x, y}, Integers] Out= {{x -> 1, y -> 3}, {x -> 5, y -> 11}, {x -> 8, y -> 17}, {x -> 17, y -> 35}, {x -> 31, y -> 63}, {x -> 111, y -> 223}} – Daniel Lichtblau Apr 19 '18 at 14:20

One way is to insert all the equalities directly:

set = {1, 5, 8, 17, 31, 111};
Solve[{2 x + 1 == y && x > 0 && y > 0 &&
Or @@ (Equal[x, #] & /@ set)}, {x, y}, Integers] // Column

• thanks, Do you think it is possible to use something such as "Element" or "Member" here instead of " Or @@ (Equal[x, #] & /@ set)"? – asad Apr 19 '18 at 13:25
• I don't know, It doesn't seem to work in Solve as well as in Reduce. Here is another variant of the same direct approach: Solve[{2 x + 1 == y && x > 0 && y > 0 && Times@@(x-set)==0, {x, y}, Integers] // Column – Andrew Apr 19 '18 at 13:43

Alternatively,

xlist = {1, 5, 8, 17, 31, 111};

Table[{x, y} /. Solve[2 x + 1 == y && y > 0, y, Integers][],{x, xlist}]

(* {{1, 3}, {5, 11}, {8, 17}, {17, 35}, {31, 63}, {111, 223}} *)


EDIT: Or more simply,

{#, 2 # + 1} & /@ xlist

(* {{1, 3}, {5, 11}, {8, 17}, {17, 35}, {31, 63}, {111, 223}} *)