I was reading a piece of code that was an optimized version of Eratosthenis sieve for primes but I don't understand the logic and can't find online the formalized definition of it.
Basically for input n to generate all primes up to and including n, it considers as the max number of iterations to the process:
int size = Math.floor(0.5 * (n - 3)) + 1
and iteratively goes for i = 0; i < size; ++i considering that if i is prime then (i * 2) + 3 is also prime and then marking as not prime all j for j = ((i * i)* 2) + 6 * i + 3; j < size; j +=(i * 2 + 3)
Can someone explain what is the logic behind this?
This is just a standard sieve, optimized slightly for space but not for speed. Instead of an array with an entry for each positive integer, it uses an array with only entries for the odd numbers from 3 onwards. So entry $i$ in the array (with $0$-based indexing) represents the integer $2i+3$.
Note that contrary to what you said, it does not matter whether or not the index $i$ is prime, it only matters whether the number it represents, $2i+3$, is prime.
Anyway, the algorithm removes multiples of all numbers up to $n$. That is to say, the corresponding index $i$ is such that $2i+3\le n$. This leads to the expression you ask about.
That is actually not an optimized bound. Every composite number $\le n$ will actually have a factor that is $\le\sqrt{n}$, so really they could have lowered that bound significantly.