Prime counting function; when is it true that $\pi(n) > \pi(2n) -\pi(n)$?

According to Wikipedia,

$${x\over\ln x-1}\lt\pi(x)\lt{x\over\ln x-1.1}$$

for large $x$, with the lower bound holding for $x\ge5393$ and the upper bound for $x\ge60184$. Thus the inequality $\pi(2n)\lt2\pi(n)$ holds for $n\ge30092$, since the inequality

$${2n\over\ln(2n)-1.1}\lt{2n\over\ln n-1}$$

holds for all $n$ (i.e., since $\ln2\gt0.1$). Whether the inequality $\pi(2n)\lt2\pi(n)$ fails for any small $n$ can be "easily" checked.


I've written the program Akiva Weinberger suggested above. This is just a straightforward interpretation of the sieve of Eratosthenes, in R.

n = 30092
top = 2*n
isPrime = rep(TRUE, top)
isPrime[1] = FALSE

nextprime = 2
while (nextprime < sqrt(top)){
  isPrime[seq(2*nextprime, floor(top/nextprime)*nextprime, nextprime)] = FALSE
  nextprime = min(which(isPrime[(nextprime+1):top])) + nextprime
}

#isPrime[n] is now TRUE if n is prime and FALSE otherwise

primePi = cumsum(isPrime) #prime counting function, denoted as pi above

f = primePi[seq(2, 2*n, 2)] - 2*primePi[1:n] 

which(f>0)

The output is the list [1]. That is, $\pi(2k) > 2\pi(k)$ for $k = 1$ and no other $k <= 30092$. As Barry Cipra showed above, we can prove the desired inequality for larger values from of $k$ from known bounds.

If we want to consider the possibility that $\pi(2k) = 2\pi(k)$, we can replace the last line with which(f>=0). The output here is [1, 2, 4, 10]. And in fact we have $2 = \pi(4) = 2 \pi(2), 4 = \pi(8) = 2 \pi(4), 8 = \pi(20) = 2\pi(10)$.