# 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?

-

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) –  The Toad Aug 25 '12 at 21:21
Or alternately, k = First@Maximize[...], since the function being maximized is just j. –  The Toad Aug 25 '12 at 21:27
More compactly: ArgMax[{j, 2^j/(j + 1) <= 10}, j, Integers]. –  Guess who it is. 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] –  The Toad 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. –  The Toad Aug 25 '12 at 21:52
@R.M Let's continue this in a proper duel –  belisarius Aug 26 '12 at 7:04