HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Can you take classical code and compile it to quantum code?

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
canclassicalyoucompiletakeandcodequantum

Problem

Is there anyway for example, to take a trivial program from C such as:

int main() {
int i = 1 + 1;
return 0;
}


And compile this down to some form of Quantum Abstract High-level language, i.e. Quantum C?

From what I understand, quantum arithmetic is quite tricky business that uses QFTs. My first thought was to do the following for the example above:

Initialise two qubits and set the amplitudes like following:
$$ 0|1|0|0$$

Where 0100 = 2 in decimal.

Somehow return this quantum register.

Using the amplitudes, you could perform 32-bit arithmetic with 32 qubits?

I haven't answered the notion of creating a function or returning either.

Essentially what I'm asking is the following, can we take known quantum methods (using Unitary functions to perform calculation) and apply this to classical code and if so, how?

EDIT: I've looked further and seen a few papers on Quantum Full Adders, I assume this is the way to go for addition? Is this too much? In quantum computation books that describe quantum assembly, there is not much mention of addition.

Solution

Doubly-controlled NOT gates are universal with respect to classical functions. Quantum computers can perform doubly-controlled NOTs. So even a quantum computer not allowed to perform fancy operations involving superposition, and not allowed to perform irreversible operations such as measuring or clearing a bit, can perform any classical computation.

For example, a quantum computer can basically directly run the gates making up a VanRentergem addition circuit:

Quantum computers are actually slightly better at reversible computation than classical computers. Classically you sometimes need an extra scratch bit to compute a function, because of permutation parity issues, but quantum shenanigans get that down to zero. Though of course emulating irreversible functions still requires introducing new scratch bits each time.

Context

StackExchange Computer Science Q#50496, answer score: 6

Revisions (0)

No revisions yet.