THDivider
QuICT.algorithm.arithmetic.divider.th_divider.SubtractionModule ¶
Bases: CompositeGate
Implement a quantum subtractor named subtraction which is a module of the following divider.
For qreg_size equals n, this gate requires in total 2n qubits.
For both operands, the highest digit must set to \(\vert{0}\rangle\)
due to 2's complement positive binary.
Input
The first "n" qubits are subtrahend of which the higher digit in lower lines.
The following "n" qubits are minuend of which the higher digit in lower lines.
Output
The first "n" qubits are the result of "b-a".
The following "n" qubits are reserved for the minuend.
Parameters:
-
qreg_size(int) –The input quantum register size for subtrahend and minuend.
-
name(str, default:None) –The name of subtraction module.
Raises:
GateParametersAssignedError: If qreg_size is smaller than 3.
Source code in QuICT/algorithm/arithmetic/divider/th_divider.py
QuICT.algorithm.arithmetic.divider.th_divider.CtrlAddSubModule ¶
Bases: CompositeGate
Implement a quantum adder-subtractor circuit named Ctrl-AddSub
which is a module of following divider. For qreg_size equals n,
this gate requires in total 2n + 1 qubits. For both operands,
the highest digit must set to \(\vert{0}\rangle\) due to 2's complement positive binary.
Input
The first qubit is the "ctrl" qubit which determine
whether the module is an adder or subtractor.
The following "n" qubits are first operand of which the higher digit in lower lines.
The last "n" qubits are second operand of which the higher digit in lower lines.
Output
The first qubit is reserved for 'ctrl' qubit.
The following "n" qubits are the result of "b-a" or "b+a".
The last "n" qubits are reserved for the operand.
Parameters:
-
qreg_size(int) –The input quantum register size for operands.
-
name(str, default:None) –The name of CtrlAddSubModule.
Raises:
GateParametersAssignedError: If qreg_size is smaller than 3.
Source code in QuICT/algorithm/arithmetic/divider/th_divider.py
QuICT.algorithm.arithmetic.divider.th_divider.CtrlAddNopModule ¶
Bases: CompositeGate
Implement a quantum conditional addition circuit called Ctrl_AddNop
which is a module of following divider. For qreg_size equals n,
this gate requires in total 2n + 1 qubits. For both addends,
the highest digit must set to \(\vert{0}\rangle\) due to 2's complement positive binary.
Input
The first qubit is the "ctrl" qubit which determine whether to do add.
The following "n" qubits are first addend of which the higher digit in lower lines.
The last "n" qubits are second addend of which the higher digit in lower lines.
Output
The first qubit is reserved for 'ctrl' qubit.
The following "n" qubits are the result of "b + a" or reserved for the first addend.
The last "n" qubits are reserved for the second addend.
Parameters:
-
qreg_size(int) –The input quantum register size for addends.
-
name(str, default:None) –The name of CtrlAddNopModule.
Raises:
GateParametersAssignedError: If qreg_size is smaller than 3.
Source code in QuICT/algorithm/arithmetic/divider/th_divider.py
QuICT.algorithm.arithmetic.divider.th_divider.THRestoreDivider ¶
Bases: CompositeGate
A quantum divider using Restoring Division Algorithm. For qreg_size equals n, this
gate requires in total 3n qubits. For n-qubit binary encoded dividend and divisor,
calculates quotient and remainder. The quotient will be stored on extra n clean qubits
and the remainder will be stored on dividend's register.
Note
The dividend and divisor are 2’s complement positive binary.
If divisor is set to zero, the result of running this divider is:
Examples:
from QuICT.core import Circuit
from QuICT.algorithm.arithmetic import THRestoreDivider
circuit = Circuit(9)
THRestoreDivider(3) | circuit
Implementation Details(Asymptotic)
| Parameter | Info |
|---|---|
| Input Size | \(n\) |
| Quotient Size | \(n\) |
| Remainder Size | \(n\) |
| num. ancilla | \(0\) |
| Gate set | \(CCX, CX, X, H, T, T^\dagger\) |
| Width | \(3n\) |
| Depth | \(13n^2-4n-2\) |
| Size | \(31n^2-33n\) |
| CX count | \(14n^2-18n\) |
| CCX count | \(4n^2-3n\) |
References
[1]: "Quantum Circuit Designs of Integer Division Optimizing T-count and T-depth" by Himanshu Thapliyal, Edgard Muñoz-Coreas, T.S.S.Varun and Travis S.Humble https://ieeexplore.ieee.org/document/8691552.
Parameters:
-
qreg_size(int) –The input quantum register size for divisor and dividend.
-
name(str, default:None) –The name of the divider gate. Default to None.
Raises:
GateParametersAssignedError: If qreg_size is smaller than 3.
Source code in QuICT/algorithm/arithmetic/divider/th_divider.py
QuICT.algorithm.arithmetic.divider.th_divider.THNonRestDivider ¶
Bases: CompositeGate
A quantum divider using Non-Restoring Division Algorithm. For qreg_size equals n,
this gate requires in total 3n-1 qubits. For n-qubit binary encoded dividend and divisor,
calculates quotient and remainder.
Note
The dividend and divisor are 2’s complement positive binary.
If divisor is set to zero, the result of running this divider is:
Examples:
from QuICT.core import Circuit
from QuICT.algorithm.arithmetic import THRestoreDivider
circuit = Circuit(11)
THNonRestDivider(4) | circuit
Implementation Details(Asymptotic)
| Parameter | Info |
|---|---|
| Input Size | \(n\) |
| Quotient Size | \(n\) |
| Remainder Size | \(n-1\) |
| num. ancilla | \(0\) |
| Gate set | \(CCX, CX, X, H, T, T^\dagger\) |
| Width | \(3n-1\) |
| Depth | \(10n^2+2n-9\) |
| Size | \(24n^2-16n-18\) |
| CX count | \(12n^2-7n-14\) |
| CCX count | \(n^2+n-4\) |
References
[1]: "Quantum Circuit Designs of Integer Division Optimizing T-count and T-depth" by Himanshu Thapliyal, Edgard Muñoz-Coreas, T.S.S.Varun and Travis S.Humble https://ieeexplore.ieee.org/document/8691552.
Parameters:
-
qreg_size(int) –The input quantum register size for divisor and dividend.
-
name(str, default:None) –The name of divider gate. Default to None.
Raises:
GateParametersAssignedError: If qreg_size is smaller than 4.