Creating an Adder Circuit

Quantum Addtion

Adder Circuit satisfies tradtional binary addition operation.

ABresult
0000
0101
1001
1110

这里需要根据Quantum Computing的特点设计一个Circuit满足如上的加法运算。

在该Circuit中,A和B量子位作为输入,result通过两个measurement输出。

Entanglement

这里我们需要借助entanglement来实现这个结果。首先我们来看一下CNOT Gate,其实是XOR Gate。
在这里插入图片描述
在这里插入图片描述
XOR Gate满足加法运算中第一个bit位的要求。

接下来对于第二个bit位,不难发现是一个AND Gate。

For this, we need a new gate: like a CNOT but controlled on two qubits instead of just one. This will perform a NOT on the target qubit only when both controls are in state 1. This new gate is called the Toffoli. For those of you who are familiar with Boolean logic gates, it is basically an AND gate.

Coding

qc_ha = QuantumCircuit(4,2)
# encode inputs in qubits 0 and 1
qc_ha.x(0) # For a=0, remove the this line. For a=1, leave it.
qc_ha.x(1) # For b=0, remove the this line. For b=1, leave it.
qc_ha.barrier()
# use cnots to write the XOR of the inputs on qubit 2
qc_ha.cx(0,2)
qc_ha.cx(1,2)
# use ccx to write the AND of the inputs on qubit 3
qc_ha.ccx(0,1,3)
qc_ha.barrier()
# extract outputs
qc_ha.measure(2,0) # extract XOR value
qc_ha.measure(3,1) # extract AND value

qc_ha.draw()

在这里插入图片描述
然后我们对结果进行测量,就可以实现classical computing中的加法运算了。注意这里q_0和q_1无论取值为0还是1,都满足加法运算的规则。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值