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

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.

• Probably the best way to think of a quantum programming language is a classical programming language (e.g. C) with a new data type which represents quantum memory, and a bunch of new operations that work on quantum memory (e.g. Hadamard transform, controlled not, phase rotate). In that sense, every classical program is a quantum program which just doesn't use the quantum stuff. Dec 9 '15 at 0:10
• Hi Pseudonym, I seem to understand everything barring arithmetic. I'm not sure how quantum gates can accomplish arithmetic? Or perhaps because I can just straight do addition using my qubits already? Dec 9 '15 at 0:13
• You first have to decide on what "quantum arithmetic" actually means. Once you've defined the precise operation that you want, then just like with classical logic, you can either implement the operator, or build it out of lower-level logic operators. In a sense, you don't really "need" integer addition in a classical programming language, either; you can build it out of logic operators if you feel so inclined. Dec 9 '15 at 0:59
• So essentially one could just suppose that hardware will take care of it and write it how I see fit? For instance, if we take addition, I could just suppose that hardware quantum full adders will exist and my quantum programming language could have for instance: int j = 1 + 2 ? I think the problem is I never really understood how classical assembly understands such things. Dec 9 '15 at 1:15
{"ft_lang_label":"__label__en","ft_lang_prob":0.92389846,"math_prob":0.7517116,"size":1175,"snap":"2021-31-2021-39","text_gpt3_token_len":276,"char_repetition_ratio":0.10503843,"word_repetition_ratio":0.0,"special_character_ratio":0.23489362,"punctuation_ratio":0.12173913,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9839507,"pos_list":[0,1,2],"im_url_duplicate_count":[null,7,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-09-18T14:16:20Z\",\"WARC-Record-ID\":\"<urn:uuid:e2d10b7a-14e2-4f10-b814-2fe7eb380a92>\",\"Content-Length\":\"172847\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:449e4694-5ed0-4aa4-80b6-e6ffbedcf457>\",\"WARC-Concurrent-To\":\"<urn:uuid:d9bcfe9f-a53c-4772-ada1-f8e84890a8ba>\",\"WARC-IP-Address\":\"151.101.65.69\",\"WARC-Target-URI\":\"https://cs.stackexchange.com/questions/50496/can-you-take-classical-code-and-compile-it-to-quantum-code?noredirect=1\",\"WARC-Payload-Digest\":\"sha1:6U4TRIMMVGD3RMFZXA3Z4VRG6QJZFUES\",\"WARC-Block-Digest\":\"sha1:BVATQEY67MX4GOW3IY7J423WMF7WXI7U\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-39/CC-MAIN-2021-39_segments_1631780056476.66_warc_CC-MAIN-20210918123546-20210918153546-00562.warc.gz\"}"}