概要
量子コンパイラを作る。
練習問題、2bit乗算器、やってみた。
コードを書く。
make 12
in 0 3
and 0 2 4
and 1 2 5
and 1 3 11
and 0 3 6
xor 5 6 10
and 5 6 7
xor 4 7 9
and 4 7 8
out 8 11
コンパイル結果
from blueqat import Circuit
print (Circuit(12).h[ : 4].ccx[0, 2, 4].ccx[1, 2, 5].ccx[1, 3, 11].ccx[0, 3, 6].cx[5, 10].cx[6, 10].ccx[5, 6, 7].cx[4, 9].cx[7, 9].ccx[4, 7, 8].m[ : ].run(shots = 1000))
成果物
真理値表で確認。
成果物
回路図で確認。
成果物
実行結果
Counter({
'110100100011': 84,
'110000000000': 73,
'010100000001': 71,
'101110100110': 71,
'111011000110': 66,
'010000000000': 66,
'100000000000': 65,
'011001000010': 62,
'000000000000': 61,
'001000000000': 60,
'001100000000': 58,
'111111111001': 58,
'011101000011': 56,
'101010000100': 55,
'100100100010': 51,
'000100000000': 43
})
以上。