# How to find the maximum value of an integer that satisfies some inequality

Consider the following Mathematica expression:

Reduce[2^j/(j + 1) <= 10, j, Integers]


which outputs:

j == 0 || j == 1 || j == 2 || j == 3 || j == 4 ||
j == 5 || j == 6 || (j \[Element] Integers && j <= -2)


Therefore, the maximum integer $j$ satisfying $\frac{2^j}{j + 1}$ is 6.

I tried to using the FindMaximum, as follows:

FindMaximum[{j, 2^j/(j + 1) <= 10 && j \[Element] Integers}, j]


but it gives the following error:

FindMaximum::eqineq: "Constraints in {j\[Element]Integers,2^j/(1+j)<=10} are
not all equality or inequality constraints.
With the exception of integer domain constraints for linear programming,
domain constraints or constraints with Unequal (!=) are not supported."


My general question is:

How to solve inequalities like $\frac{2^j}{j + 1} \le c$ (for some constant $c$) in Mathematica, over Integers?

-
 Isn't your question actually, "How to find the maximum value of j (an integer) that satisfies the inequality?" – David Carraher Aug 25 '12 at 21:13 @DavidCarraher: Yes, that's much better! I changed the title accordingly. – Sadeq Dousti Aug 25 '12 at 21:26

## 2 Answers

Your approach to solve for general j using Reduce is correct. However, you can also use Maximize or NMaximize as:

Maximize[{j, 2^j/(j + 1) <= 10}, j, Integers]
(* {6, {j -> 6}} *)


Or even more compactly, as JM notes:

ArgMax[{j, 2^j/(j + 1) <= 10}, j, Integers]
(* 6 *)

-
Thanks for the answer. Is there a way to put this maximum value into another variable, say $k$? – Sadeq Dousti Aug 25 '12 at 21:20
@SadeqDousti You can do k = j /. Last@Maximize[...] (fill in the rest from above) – rm -rf Aug 25 '12 at 21:21
Or alternately, k = First@Maximize[...], since the function being maximized is just j. – rm -rf Aug 25 '12 at 21:27
More compactly: ArgMax[{j, 2^j/(j + 1) <= 10}, j, Integers]. – J. M. Aug 26 '12 at 0:47
@J.M.: That's really compact. Thanks! – Sadeq Dousti Aug 26 '12 at 12:01

If you want to use the results from Reduce, you could do:

Max[j /. Solve@ Reduce[2^j/(j + 1) <= 10, j, Integers]]

-
except that it doesn't generalize to situations where the actual answer is in the j ∈ Integers && j ... case :) For example, find the minimum $j$ such that $2^j/(j+1)\geq 4$. Reduce[2^j/(j + 1) >= 4, j, Integers] will give j ∈ Integers && j >= 5 which will lead to errors with Solve. But something in the spirit of what you're doing would be: Maximize[{j, Reduce[2^j/(j + 1) <= 10, j, Integers]}, j] – rm -rf Aug 25 '12 at 21:31
@R.M Well, your answer does not return Infinity for Maximize[j, 2^j/(j + 1) >= 4, j, Integers] either :) – belisarius Aug 25 '12 at 21:38
Yes, but that seems more like a bug in Maximize when given a constraint. Compare: Maximize[{x, x > 2}, x, Integers] with Maximize[{x}, x, Integers]. This is a bug worth being aware though... I can think of a few instances where this would've misled me. – rm -rf Aug 25 '12 at 21:52
@R.M Let's continue this in a proper duel – belisarius Aug 26 '12 at 7:04