xvalues = {1, 2, 5, 10};
yvalues = {1/8, 1/4, 1/2, 1};
FindInstance[
x^2 + y^2 < 10 && Or @@ Thread[x == xvalues] &&
Or @@ Thread[y == yvalues], {x, y}, 8]
(* {{x -> 1, y -> 1/8}, {x -> 1, y -> 1/4}, {x -> 1, y -> 1/2},
{x -> 1, y -> 1}, {x -> 2, y -> 1/8}, {x -> 2, y -> 1/4},
{x -> 2, y -> 1/2}, {x -> 2, y -> 1}} *)
EDIT: Based on comparative timings, FindInstance
is not the preferred approach.
$HistoryLength = 0;
hanlon = FindInstance[
x^2 + y^2 < 10 && Or @@ Thread[x == xvalues] &&
Or @@ Thread[y == yvalues], {x, y}, 8] //
AbsoluteTiming;
woll = FindInstance[
{x^2 + y^2 < 10,
{x} ∈ Point[List /@ xvalues],
{y} ∈ Point[List /@ yvalues]},
{x, y}, 8] //
AbsoluteTiming;
outer = Outer[
If[#1^2 + #2^2 < 10, {x -> #1, y -> #2}, Nothing] &,
xvalues, yvalues] //
Flatten[#, 1] & //
AbsoluteTiming;
The results are identical
Equal @@ Last /@ {hanlon, woll, outer}
(* True *)
However, using Outer
is 300 times faster
(First /@ {hanlon, woll, outer})/outer[[1]]
(* {333.446, 308.769, 1.} *)
FindInstance[]
. For small lists like your example, useTable[]
andSelect[]
instead. $\endgroup$ – Somos May 21 at 2:30