# 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 ∈ Integers && j <= -2)


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

I tried to using the function FindMaximum, as follows:

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


but it gives the following error:

FindMaximum::eqineq: "Constraints in {j∈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$? – M.S. 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. is in limbo Aug 26 '12 at 0:47
• @J.M.: That's really compact. Thanks! – M.S. 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 :) – Dr. 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 – Dr. belisarius Aug 26 '12 at 7:04

It is possible to define a function to return your maximum integer. First, note the output of Reduce for a couple examples:

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


j < -1 || (-Log[2] - ProductLog[-(Log[2]/20)])/Log[2] <= j <= (-Log[2] - ProductLog[-1, -(Log[2]/20)])/Log[2]

j < -1 || (-Log[2] - ProductLog[-(Log[2]/40)])/Log[2] <= j <= (-Log[2] - ProductLog[-1, -(Log[2]/40)])/Log[2]

This suggests that the following function returns your desired values:

maxj[c_] := Floor[(-Log[2]-ProductLog[-1,-(Log[2]/(2c))])/Log[2]]


(Alternatively, we can use the boundary of the inequality to arrive at the same result):

Reduce[2^j/(j+1) == c && j > 0 && c > 1, j]


c > 1 && j == (-Log[2] - ProductLog[-1, -(Log[2]/(2 c))])/Log[2]

Check:

maxj[10]


6