# Shor's 9 qubit code

The well-known Shor's 9 qubit code can correct any single Pauli error, but it can also correct some other kinds of errors. Its circuit is shown as below which can be constructed by the following code

using Yao
using SymEngine

shor(E) = chain(9,
# encode circuit
cnot(1, 4), cnot(1, 7),
put(1=>H), put(4=>H), put(7=>H),
cnot(1,2), cnot(1,3), cnot(4,5), cnot(4,6), cnot(7,8), cnot(7,9),
E, # the error
# decode circuit
cnot(1,2), cnot(1,3), cnot((2, 3), 1),
cnot(4,5), cnot(4,6), cnot((5, 6), 4),
cnot(7,8), cnot(7,9), cnot((8, 9), 7),
put(1=>H), put(4=>H), put(7=>H), cnot(1, 4), cnot(1, 7), cnot((4, 7), 1)
)
shor (generic function with 1 method)

Now we can check whether it can correct a given error by doing symbolic computation on an arbitrary 1-qubit pure quantum state $α|0⟩ + β|1⟩$ and a specific weight-9 error.

@vars α β
s = α * ket"0" + β * ket"1" |> append_qudits!(8)
E = kron(1=>X, 2=>Z, 3=>Z, 4=>X, 5=>Z, 6=>Z, 7=>X, 8=>Z, 9=>Z);
s |> shor(E) |> expand
(1.0 + 0.0*im)*α|110110110⟩ + (1.0 + 0.0*im)*β|110110111⟩
{"ft_lang_label":"__label__en","ft_lang_prob":0.6355022,"math_prob":0.99950695,"size":1085,"snap":"2022-27-2022-33","text_gpt3_token_len":468,"char_repetition_ratio":0.16096207,"word_repetition_ratio":0.0,"special_character_ratio":0.44792625,"punctuation_ratio":0.23026316,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99759614,"pos_list":[0,1,2],"im_url_duplicate_count":[null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-08-09T02:00:11Z\",\"WARC-Record-ID\":\"<urn:uuid:862d5634-bb60-491d-a2e3-07aa7bc751c6>\",\"Content-Length\":\"9680\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:e1002d37-5328-4488-b8bf-c70e79af2db8>\",\"WARC-Concurrent-To\":\"<urn:uuid:dc545f63-fa7c-459d-ab9c-95cc5a94a978>\",\"WARC-IP-Address\":\"185.199.108.153\",\"WARC-Target-URI\":\"https://docs.yaoquantum.org/dev/generated/examples/5.shor-9-code/index.html\",\"WARC-Payload-Digest\":\"sha1:LCCRKL6LXXK5JCYPQOUATPEIQ7S4F7LZ\",\"WARC-Block-Digest\":\"sha1:FECPQY4STG625PJA46VG7QBJEP27GXA5\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-33/CC-MAIN-2022-33_segments_1659882570879.37_warc_CC-MAIN-20220809003642-20220809033642-00451.warc.gz\"}"}