# What is the order of $\mathrm{Z}(x)-\pi(x)?$

Consider the offset logarithmic integral which approximates the number of primes up to a given $$x$$ quite well $$\mathrm{Li}(x)=\int_2^x\frac{1}{\log t}~dt$$

And consider the alternating series

$$\mathrm{Z}(x)= \sum_{n=2}^x (-1)^{n+1}e^{\sin\big(\frac{(-1)^{n+1}}{\log n}\big)}$$

$$\mathrm{Z}(x)$$ remarkably stays close to $$\mathrm{Li}(x)$$ and is at least asymptotic to $$\mathrm{Li}(x)$$ from what I can tell. For example I tested this at $$x=10^8$$ the difference between the two is only about $$4$$ with $$\mathrm{Z}(x)$$ slightly less than the offset logarithmic integral.

What is the order of $$\mathrm{Z}(x)-\pi(x)?$$

Notice that $$\sin z=z+O(z)$$ and $$e^z=1+z+\frac12z^2+O(z^3)$$ as $$z\to0$$, so we have

\begin{aligned} Z(x) &=\sum_{2\le n\le x}(-1)^{n+1}e^{(-1)^{n+1}/\log n+O(1/\log^3n)} \\ &=\sum_{2\le n\le x}(-1)^{n+1}\left[1+{(-1)^{n+1}\over\log n}+{1\over2\log^2n}+O\left(1\over\log^3n\right)\right] \\ &=\sum_{2\le n\le x}{1\over\log n}+\sum_{2\le n\le x}(-1)^{n+1}+\frac12\sum_{2\le n\le x}{(-1)^{n+1}\over\log^2n}+O\left(\sum_{2\le n\le x}{1\over\log^3n}\right). \end{aligned}

Notice that the second sum is bounded, the third sum converges, and

$$\sum_{2\le n\le x}{1\over\log^3n}\le\sum_{2\le n\le\sqrt x}{1\over\log^32}+\sum_{\sqrt x

so we have

$$Z(x)=\sum_{2\le n\le x}{1\over\log n}+O\left(x\over\log^3x\right).\tag1$$

It can be proven that the remaining summation has bounded difference from $$\operatorname{Li}(x)$$, so we conclude that

$$Z(x)-\operatorname{Li}(x)=O\left(x\over\log^3x\right).\tag2$$

Although (2) only provides an O-bound, if we expand more terms from $$\sin z$$ and $$e^z$$, it is pretty likely that one will conclude the true order of error is $$x/(\log x)^A$$ for some fixed $$A\ge3$$, which is much worse than the order of $$\pi(x)-\operatorname{Li}(x)$$:

$$\pi(x)-\operatorname{Li}(x)=O(xe^{-(\log x)^B})$$

for some $$0.