# Is there a way to implement Smolin's variant of Shor's algorithm?

I'm currently investigating Shor's algorithm and especially Smolin's variant, that he described in his article: https://arxiv.org/abs/1301.7007

My applied changes according to Smolin's variant are here: https://github.com/Sage-Cat/quantum_shors_algorithm

The paper I read you can find in repository docs/Smolin_pretending_large_numbers.pdf.

To be concise, he suggests to make this changes:

1. Find a, such as a^2 = 1 mod N, using Extended Euclidean Algorithm
2. Set period r = 2
3. And somehow use 2 qubits to simulate finding a and r or smth. (I don't understand the actual use of 2 qubits). From his paper I got only that he uses 2 qubits to get specific CNOT entanglement like this:
    operation ValidateAUsingQuantumSubroutine(a : Int, N : Int, r : Int) : Result {
use qubits = Qubit[2];
// Prepare qubits
H(qubits[0]);
CNOT(qubits[0], qubits[1]);

// Measurement could be used to validate assumptions or effects
let measurement = M(qubits[0]);

ResetAll(qubits);
return measurement;
}


But how it helps to validate a, I don't understand.

The thing to understand is that the quadratic residue $$a$$, that Smolin is getting you to compute, is exactly the same $$a$$ that Shor's algorithm is finding by using period-finding against a random base $$g$$. When you set $$g=a$$, you get a vacuous execution of Shor's algorithm where it computes that this $$g$$'s period is 2, and returns $$g^{2/2} = \text{...drumroll...} = a$$ as the quadratic residue to use for factoring.
So the first cheat is knowing the value you're trying to find. The second cheat is using the fact that you know the period of $$f(x) = g^x$$ is 2, and therefore Shor's algorithm will still work if you substitute this complicated $$f$$ with some trivial period-2 function like bit-flipping. So you do that. And also you reduce your phase estimation register size from $$2n$$ to 1, since that's sufficient for period 2. Thus the whole quantum part degenerates into a CNOT gate conjugated by Hadamard gates on its control.