8
$\begingroup$

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?

$\endgroup$
8
$\begingroup$

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

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

Max[j /. Solve@ Reduce[2^j/(j + 1) <= 10, j, Integers]]
$\endgroup$
  • $\begingroup$ 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] $\endgroup$ – rm -rf Aug 25 '12 at 21:31
  • $\begingroup$ @R.M Well, your answer does not return Infinity for Maximize[j, 2^j/(j + 1) >= 4, j, Integers] either :) $\endgroup$ – Dr. belisarius Aug 25 '12 at 21:38
  • $\begingroup$ 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. $\endgroup$ – rm -rf Aug 25 '12 at 21:52
  • 1
    $\begingroup$ @R.M Let's continue this in a proper duel $\endgroup$ – Dr. belisarius Aug 26 '12 at 7:04
0
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.