Suppose I have function f:
f[x_, y_] := 50000 + x 30000 + y 35000;
Now I want to find the x and y when f[]<=200000. I use Reduce:
Reduce[f[x, y] <= 200000 && 1 <= x <= 8 && 1 <= y <= 8 , {x,y}, Integers]
The result is:
(x == 1 && y == 1) || (x == 1 && y == 2) || (x == 1 && y == 3) ||
(x == 2 && y == 1) || (x == 2 && y == 2) || (x == 3 && y == 1)
Now I would like to use these results back into f[] but it requires formatting. I use:
results = Reduce[f[x, y] <= 200000 && 1 <= x <= 8 && 1 <= y <= 8,
{x, y},Integers] /.
Or[a__, b__] -> {a, b} /.
And[a_ == c_, b_ == d_] -> {c, d}
And I use:
f[#[[1]], #[[2]]] & /@ results
to get:
{115000, 150000, 185000, 145000, 180000, 175000}
I wonder if this is the right way to do this or if it can be done easier. It seems reduce can generate different (depending on the equations of course) formats of the results and this would mean that for every type of result new rules will be needed. Is this a fact of life?
