Suppose we want to build a primality testing algorithm for the numbers limited to the set $A =\{1, ..., 2^n\}$ and $n$ is reasonably large. The prime-number theorem tells us that there are approximately $\frac{2^n}{n \ln 2 }$ prime numbers within the set. Now, if we had a permutation $\sigma : A \to A$ which has the property that $\sigma(a) > \sigma(b)$ whenever $a$ is composite a $b$ is prime, we could decide whether a number $k \le 2^n$ is prime, by looking at $\sigma(k) < \frac{2^n}{n \ln 2 }$. Obviously, there would be a small amount of numbers for which this would not work because the prime number theorem only works asymptotically, but overall it could be very reliable.
The question is, how do we obtain a $\sigma$ with the required property? Now since we defined $A$ to have $2^n$ elements, it's natural to represent any number from the set by $n$ binary digits. Since $\sigma$ is a permutation, it can be implemented as a reversible computation. That means, we can represent this computation as a circuit with $n$ wires and some number of Toffoli gates. Denote $t(n)$ the minimal number of Toffoli gates required to implement a $\sigma$ with the required property.
What is $t(n)$? Is it bounded by a polynomial? I don't know. But at least for small values of $n$, $t(n)$ could could be found on a computer by brute-force. Hopefully, we could see a pattern and make a conjecture about it's growth. Obviously, there could be other variants of this problem, for example if we instead have different $A$ or some other universal gates, we could get differet values for $t(n)$ but I would not anticipate it to be much different. I thought this approach could provide some insight into the famous problem of primality testing, but first I'd like to learn whether such an approach has been already studied or if there are some simple arguments why $t(n)$ cannot be polynomial. Any references please?