Open access peer-reviewed chapter - ONLINE FIRST

Floating-Point Arithmetic with Consistent Rounding on a Quantum Computer

Written By

René Steijl

Submitted: 24 February 2024 Reviewed: 06 May 2024 Published: 07 June 2024

DOI: 10.5772/intechopen.1005546

Quantum Information Science IntechOpen
Quantum Information Science Recent Advances and Computational Science App... Edited by René Steijl

From the Edited Volume

Quantum Information Science - Recent Advances and Computational Science Applications [Working Title]

René Steijl

Chapter metrics overview

13 Chapter Downloads

View Full Metrics

Abstract

Implementation of floating-point arithmetic with consistent rounding is a critical component of many quantum algorithms. Quantum circuit implementations for squaring and division serve as examples here. This work was motivated by ongoing work in developing quantum algorithms for scientific and engineering computing applications, where this type of arithmetic often forms part of the algorithm. A key feature of the work is the use of a reduced-precision floating-point representation of real data specifically designed for near-term future quantum computing hardware with a limited number of qubits (e.g., less than 100) and with an increased level of fault tolerance as compared to current quantum computing hardware. The quantum circuit implementations of the squaring of a floating-point number and the division of two floating-point numbers are detailed here, highlighting similarities in the quantum circuit implementation for the logical steps required for rounding-to-nearest in line with the IEEE 754 standard for the two arithmetic operations. This similarity is an important feature regarding future work where an automated generation of this type of quantum circuit from a set of standard modules and circuit templates is employed.

Keywords

  • quantum circuit model
  • quantum arithmetic
  • conservation laws
  • floating-point representation
  • consistent rounding

1. Introduction

In quantum computing [1] research, significant progress is being made in developing quantum information processing hardware. This has so far created prototype quantum computers in research centers, as well as small-scale quantum computers accessible through the cloud to a wider audience. The current machines belong to the Noisy Intermediate Scale Quantum (NISQ)-computing era [2], characterized by the presence of a small number of qubits (typically less than 100) with significant sensitivity to noise and quantum decoherence and very limited quantum error correction. The ongoing quantum hardware development efforts create quantum computers with an ever-increasing number of qubits and increasing levels of fault tolerance.

The context of the present work is the ongoing development effort in creating quantum algorithms for computational science and engineering applications implemented using the quantum circuit model on future, more fault-tolerant quantum computers. In this type of quantum algorithm, there is often a need to perform arithmetic operations on real (non-integer) numbers within the quantum circuit-based implementation. In the quantum computing (QC) literature, there is a significant body of work on quantum circuit implementation for integer arithmetic [3, 4, 5], which can be re-used in fixed-point representations of real numbers. However, from the history of computing on classical hardware, it is clear that for most applications, a floating-point representation of data is more effective. Once floating-point numerical computation on classical computers became commonplace, the industry standard IEEE 754 was introduced [6]. A key feature of the IEEE standard is that it requires correctly rounded operations, including the correctly rounded arithmetic operations considered here. Typically, rounding to the nearest floating-pointing number available in the destination (output register) is used. A similar standard for floating-point representations on a quantum computer does not yet exist, but is desirable [7].

Recently, a small number of works have focused on quantum algorithms with a floating-point type representation of data. These works include research on floating-point arithmetic [8, 9, 10, 11, 12, 13] as well as research on data encoding and representation of quantum images [14, 15].

The present work discusses quantum circuit implementations for two example calculations typically found in computational science and engineering applications: evaluating the square of floating-point numbers (e.g., as part of kinetic energy evaluation) and the division of two floating-point numbers.

The quantum algorithms of interest here often involve the discretization and solution of partial differential equations (PDEs) that govern the conservation of physical quantities such as mass, momentum and energy. Therefore, it is important to have a consistent rounding in the arithmetic operations to avoid compromising the conservation properties of the discretization and solution methods. Rounding to the nearest floating-point number in the output register of an arithmetic operation is the preferred rounding mode in the context of computational science and engineering applications.

The key contributions of this work can be summarized as follows:

  • Demonstration of a quantum circuit implementation of floating-point squaring with detailed analysis of how rounding-to-nearest can be achieved;

  • Demonstration and analysis of quantum circuit implementation of floating-point division with rounding-to-nearest;

  • Detailed discussion of the modular structure and similarities of the quantum circuit implementation of rounding-to-nearest for both arithmetic operations;

  • Discussion of prospects for a wider range of quantum floating-point arithmetic.

The rest of this work is organized as follows. Following the review of related work in Section 2, Section 3 briefly reviews and summarizes key QC principles. Then, the floating-point representation used in the quantum circuit implementations is defined in Section 4. Section 5 discusses the quantum circuit implementation of the squaring of a floating-point number. Quantum circuit implementations for floating-point division are detailed in Section 6. Finally, Section 7 summarizes key findings and directions for future work.

Advertisement

2. Brief review of related work

An early work related to quantum circuits for floating-point arithmetic involved the complexity analysis of floating-point addition and multiplication by Häner and co-workers [8], which showed the significant challenges involved in terms of circuit complexity for IEEE-754 type precision. This motivated the present author to introduce floating-point formats for quantum algorithms with a reduced precision [12, 16, 17], such that the required number of qubits and the circuit complexity remain within limits of near-future quantum computers with an increased level of fault tolerance as compared to NISQ-era hardware.

Optimized circuits for floating-point addition and multiplication were detailed by Gayathri et al. [9] with a particular focus on minimizing the number of T-gates [1] in the implementation. The T-count optimized implementation for single-precision floating-point division was also investigated [10]. An efficient quantum circuit implementation for taking the square root of a floating-point number was detailed more recently [11]. In that work, the classical Babylonian algorithm was implemented using circuits for integer division.

Although the previously referenced works detailed key steps in quantum circuit implementations for floating-point arithmetic, the aspect of rounding was not addressed in detail. This formed the main motivation for the present work.

Key challenges in developing quantum circuit implementations for a divider are the reversibility requirement and fault tolerance, as analyzed by Babu and Mia [18]. The fault-tolerance aspect of a quantum circuit implementation of a floating-point divider was recently addressed by Yuan and their colleagues [13]. Implementations of dividers based on the long division approach perform a series of controlled subtractions for which a comparison operation between two integers encoded by qubit strings is required. Efficient quantum circuit implementations of such “comparator” circuits were published by Xia et al. [19]. Highlighting further recent research work related to quantum floating-point arithmetic, the work by Orts et al. [20] shows efficient circuit implementations for detecting the leading zero in a bit string, and operation typically required in subtraction, division, and multiplication operations.

Advertisement

3. Quantum computing essentials

In this section, some key concepts of quantum computing are reviewed. A full treatment can be found in many textbooks, for example, [1]. In the present work, the quantum circuit model is used to represent quantum algorithms, where a series of quantum gate operations act on a quantum state defined by a qubit register with n qubits in a coherent state. Figure 1 shows two example quantum circuits with three qubits (a, b, and c) with three successive quantum gate operations. Dirac’s bra-ket notation is used so that the quantum state defined by a single qubit can be defined as q=a0+b1, such that a2 is the probability of finding the qubit in state 0 when quantum measurement is performed, and b2 is the probability of finding the qubit in state 1. Since a quantum measurement is guaranteed to return one of the two states, it follows that a2+b2=1. For a quantum state defined by n qubits in a coherent state, we can write qn1qn2q1q0=i=12n1Ci, where the 2n complex amplitudes Ci (i02n1) define the state. Often, the indices are expanded in binary representation to define the 2n computational basis states.

Figure 1.

Definition of MAJ and UMA operations consisting of three gate operations, as used in Cuccaro-type adders.

In quantum circuit diagrams used in this work, each of the qubits is represented by a horizontal solid line, with a vertical arrangement of the multiple qubits in the register. Quantum gates either work on a single qubit (“single-qubit gates”) or work on multiple qubits (“multi-qubit gates”). The quantum computation progresses step-by-step in the horizontal direction, starting from the initial qubit register state defined on the left-hand side of the quantum circuit diagram.

The two example quantum circuits shown in Figure 1 are the building blocks of quantum arithmetic circuits to be discussed later. On the left-hand side of Figure 1, first a controlled X gate is applied. This two-qubit gate applies the X-gate (the quantum computing equivalent of NOT in classical circuits) to qubit b conditional on qubit a=1. Applying X changes 1 to 0 or 0 to 1. Then, a second controlled-X is applied, now with qubit c as the target qubit. Finally, a Toffoli three-qubit gate is applied. This Toffoli gate applies X to the target qubit (a here) conditionally on the state of two control qubits. In the rest of this work, “multiply-controlled” versions of the Toffoli gate are used in the quantum circuit diagrams with more than two control qubits.

It should be noted that on actual quantum computing hardware, only a small hardware-specific set of gate operations (“native gates”) are implemented. The quantum circuit diagrams used in the present work therefore define algorithms at a higher level of abstraction, and in case of hardware realization, a further translation step toward native gates would be required.

Since a quantum circuit is composed of unitary operations [1], every quantum circuit has an inverse. The inverse of a quantum circuit can simply be composed of the inverse of all its constituent quantum gates, applied in reverse order. Here, it can be noted that the UMA circuit shown on the right-hand side of Figure 1 is not the inverse of the operations from the MAJ operation, since the final controlled-X in UMA is different from the first controlled-X in the MAJ operator.

In the present work, the concept of applying the inverse of an operation defined by a set of quantum gate operations is typically used as uncomputation, aimed at returning qubit states to their original state. This is typically used to return qubits allocated to create workspace to their initial state so that these can be re-used in subsequent parts of the circuit.

The quantum circuit implementation of the floating-point dividers considered here is based on modular quantum adders originally introduced by Cuccaro [4]. Figure 2 shows the example of a 3-qubit full adder, such that an integer “a” defined in 3-bit binary representation as a2a1a0 (with a2 and a0 representing the most significant bit and least-significant bit in the binary representation, respectively) is added to integer “b” (represented as b2b1b0 in binary representation). The Cuccaro full adder stores the result in the “b” input. For a full adder, an additional bit is therefore needed for the “b” register to ensure that the output can be represented. The qubit registers a2a1a0 and b3b2b1b0 correspond to the corresponding bits of “a” and “b.” Their initial state on the left-hand side of Figure 2 defines the intended addition. Upon completion, the quantum state on the right-hand side of the circuit represents the output. The changed state of qubits b3b2b1b0 relative to that at initialization represents the computational work performed. In later sections, modulo adders will also be used. For the Cuccaro-type adders used here, the underlying idea is that modulo adder can be obtained from the full adder by removing the controlled-X operation in between the top MAJ and UMA blocks. The second modification involves not using the additional qubit on the “b” register, since by definition it is not needed for a modulo addition. The MAJ and UMA blocks act on three qubits and were previously defined in Figure 1. Furthermore, the quantum circuit implementation includes a “carry” qubit c, initialized as 0 in the applications considered here. A 3-qubit modulo adder can be obtained from the full-adder circuit shown in Figure 2 by removing the qubit b3 and the controlled X operation between the MAJ and UMA blocks at the top of the circuit. Also, using the concept of 2’s complement representation of integer numbers, modulo adder can be used to perform subtraction operations.

Figure 2.

Illustration of Cuccaro-type full addition. Three-bit integer defined by a2a1a0 is added to integer defined by b3b2b1b0 with the result stored in b3b2b1b0.

Advertisement

4. Floating-point representation in quantum circuits

In previous work, the author introduced a floating-point representation with reduced precision relative to the IEEE-754 single-precision format [12]. A key motivation was the capability to represent a much wider range of real numbers as compared to a fixed-point representation when using the same number of qubits. In this floating-point format, a base 2 representation is used, so that a non-zero, signed real number y is represented in normalized form as:

y=±SIG×2EXP,where1S<2E1

where the numbers SIG and EXP are the mantissa (or significant) and the exponent, respectively. The standard convention for floating-point representations is followed here. SIG is defined in a binary fixed-point representation such that the most significant bit is followed by the binary point and the fractional part to the right of this point [6]. The mantissa is defined using M bits in a binary representation as,

SIG=mM1.mM2m1m02E2

Excluding the special cases involving sub-normal numbers and overflow conditions (to be detailed later), it is assumed that the most significant bit in the binary representation of SIG equals 1. Floating-point numbers so defined are termed normalized [6]. Eq. (1) shows that normalized numbers cannot exactly represent the real value of zero. To account for this shortcoming and to better represent the smallest numbers in the range of numbers covered by the floating-point representation, sub-normal numbers are employed. Specifically, for the smallest value of 2EXP in Eq. (1) used in the representation, an additional set of numbers is defined for which the most significant bit in SIG equals 0. In the floating-point representation, setting all bits used to define the exponent in binary to 0 (i.e., 0000) makes the number a sub-normal number. The value for EXP used is identical to that used for the smallest of the normalized numbers, that is, with exponents defined as 0001 in binary representation. Following the IEEE-754 floating-point formats, the exponent bits are also used to identify cases where overflow has occurred in the considered arithmetic operations, that is, where the real value to store does not fit within the range of numbers covered by the floating-point representation. In that case, all exponent bits are set to 1, that is, the exponent is defined as 1111. More details on using this approach for the IEEE-754 format can be found in standard textbooks, for example, Overton’s book [6]. In the quantum circuit implementation, a sign qubit is used which is in state 0 for a positive number. A negative number has this sign qubit in state 1. Following the “hidden-bit” approach used in the IEEE-754 standard [6], the most significant bit is not stored and M1 qubits are used here to store only the fractional part of the mantissa. The exponent is defined using E bits in a binary representation as,

EXP=eE1eE2e1e02EXPbiasE3

where EXPbias is the exponent bias. In this work, 3 qubits are used in the definition of the exponent E=3, contrasting with the 8 bits used in the IEEE-754 single-precision format. For E=3, sub-normal numbers are defined by the exponent qubit string in state 000. Similarly, the exponent qubit string in state 111 represents overflow conditions. Also, the quantum circuit implementations are detailed for M=4, so that 3 qubits store the fractional part of the mantissa, in contrast to the 23 bits used this in the IEEE 754 single-precision format. This is done for illustration purposes, since for real-world computational engineering application M needs to be significantly larger; for example, it is expected that at least M=8 is required for most applications. For E=3, exponent 0002=0 defines sub-normal numbers, while 1112=7 defines “overflow” conditions. For normalized numbers, this leaves the range 1 to 6, and therefore EXPbias=3 creates a symmetric bias. For this symmetric bias, and assuming M=4, the qubit strings 011000 and 011111 define a floating-point number with magnitudes 8/8 and 15/8, respectively (where the sign qubit was omitted for clarity). The smallest normalized number represented by qubit string 001000 is 8/32. The smallest non-zero sub-normal number equals 1/32 and is represented by the qubit string 000000. A key aspect of the present format is the use of an asymmetric bias. This enables the range of numbers that can accurately be presented to be tailored to the considered problem. This was demonstrated for quantum circuit implementation of one-dimensional lattice models for fluid dynamics [16, 17]. For the previously considered examples with M=4, an asymmetric bias of EXPbias=5 means that the qubit strings 011000 and 011111 define the number 8/32 and 15/32, respectively. Also, for this asymmetric bias, the smallest non-zero sub-normal number represented by qubit string 000000 takes on the value 1/128.

Advertisement

5. Quantum circuits for kinetic energy evaluation

This section considers the squaring of floating-point numbers as required, for example, in the evaluation of kinetic energy of a fluid or a solid object. Here, a one-dimensional flow with velocity u is assumed for illustration purposes. Also, to simplify the circuits, no sign qubits are used, with all real data assumed to be positive. The required operation can then be summarized as follows. For an input u defined as a quantum floating-point number with M-qubit representation of the significant (M1 qubits for fractional part), an integer squaring is performed to create a 2Mbit temporary result. Based on the exponent of u and the exponent bias used, the next step defines the square in terms of the floating-point format. It is in this second step that rounding aspects are to be considered. Following the definition of the square in floating-point format, the mantissa-squaring step is uncomputed, so that the qubit register at completion of the full quantum circuit for floating-point squaring differs from the initial quantum register state only in terms of the qubits defining kinetic energy (squared number) output.

5.1 Performing mantissa squaring

Integer squaring can be implemented in quantum circuits based on a number of different approaches, e.g., Quantum Fourier-based [5, 12], building on the concept of shift-and-add using controlled additions [17] or optimized logic-based approaches. Since the main focus of this work is the definition of the quantum floating-point output with consistent rounding, this aspect is not analyzed further, and optimized logic-based circuits are used for integer squaring. A 4-bit representation of the mantissa of u is considered here M=4.

Figure 3 shows the example circuit for the squaring of a 4-bit integer defined in a3a2a1a0 (with a3 the most significant bit in the binary representation), with the 8-qubit integer result defined in p7p6p5p4p3p2p1p0. The quantum circuit shown was designed with minimum circuit width in mind, and the creation of five “garbage” qubits g0 to g4 was tolerated. Garbage qubits as used here are additional qubits in the quantum circuit used to represent results from intermediate steps in the squaring computation. Assuming that these qubits are initialized in the 0 state at the left-hand side of the circuit, their final state on the right-hand side of the circuit may have changed depending on the particular squaring performed.

Figure 3.

Quantum circuit for squaring of an integer defined by 4 qubits a3a2a1a0, with results in p7p0 such that 5 garbage qubits are created.

Based on the quantum circuit shown in Figure 3, a quantum circuit used for mantissa squaring is created that does not create garbage output, but instead uses 5 ancilla qubits that are initialized as 0 and return to 0 at the completion of the squaring. As can be seen, the elimination of garbage qubits comes at the cost of increased circuit depth, that is, an increased number of gate operations. The quantum circuit with 17 qubits is shown in Figure 4.

Figure 4.

Quantum circuit used to compute square of the mantissa of u in floating-point squaring.

In the quantum circuit shown in Figure 4, the 17 qubits represent the following:

qu3qu2qu1qu0:4qubits defining4bitinputur7r6r5r4r3r2r1r0:8qubit defining outputanc4anc3anc2anc1anc0:5ancilla qubitsE4

Using computational-basis encoding [1], the quantum circuit for squaring can be used as follows. The 17-qubit register is first initialized such that a single complex amplitude is non-zero, that is, it is set to 1. The index of this single non-zero complex amplitude is fully defined by the input integer number, that is, the binary representation of the number defined by qu3qu2qu1q0. For an integer defined by 4 qubits, the 8 possible outcomes (for a most significant qubit qu3=1) can be summarized as:

u=8Cin10000000000000000Cout10000100000000000u=9Cin10010000000000000Cout10010101000100000u=10Cin10100000000000000Cout10100110010000000u=11Cin10110000000000000Cout10110111100100000u=12Cin11000000000000000Cout11001001000000000u=13Cin11010000000000000Cout11011010100100000u=14Cin11100000000000000Cout11101100010000000u=15Cin11110000000000000Cout11111110000100000E5

where Cinindx0 the complex amplitude in the initial state vector with non-zero magnitude at index indx0 represented in binary representation and the left-hand side above. At the completion of the quantum circuit, a single complex amplitude Coutindx1 will have non-zero amplitude at index indx1 defined in binary representation on the right-hand side of the listed results.

5.2 Computing u2 with rounding-to-nearest

For the quantum circuit implementation of squaring u, now defined as a floating-point number with 4 mantissa qubits and 3 exponents qubits, the following qubits are used:

eu2eu1eu0:3qubits defining exponent ofuqu3qu2qu1qu0:4qubits defining mantissa ofur7r6r5r4r3r2r1r0:8qubit defining outputanc4anc3anc2anc1anc0:5ancilla qubitsesq2esq1esq0:3qubits defining exponent of outputmsq2msq1msq0:3qubits defining mantissa of outputwherehiddenqubitapproach is usedE6

For the considered floating-point squaring, the quantum circuit shown previously in Figure 4 is first applied on the subset of 17 qubits defined previously. This defines the squaring output in the 8 qubits r7r6r0 with r7 defining the most significant bit. This 8-qubit register along with the exponent of the input u is then used to define the output u2 in terms of the quantum floating-point format. Assuming EXPbias=8, a quantum circuit implementation of the required logical operations is shown in Figure 5. Here, the dash slices separate sub-circuits intended for different input exponents.

Figure 5.

The circuit shown sets results for u2 in floating-point format for M=4 using “rounding-to-nearest” (E=3, with EXPbias=8).

For the used exponent bias, cases with eu2eu1eu0=000 (i.e., sub-normal input u) and eu2eu1eu0=001 are guaranteed to create u2 truncated to 0. This can be seen from the fact that u defined by 001111 corresponds to a value of 15/8×218=15/1024 and therefore, u2 is smaller than half the smallest non-zero sub-normal number defined by 000001 (or 1/1024) so that rounding-to-nearest always leads to 0.

The left-hand side of the quantum circuit shown at the top of Figure 5 deals with cases defined by eu2eu1eu0=010. As can be seen, for u inputs leading to r7=1, rounding up can then create the smallest non-zero sub-normal output 000001. The next block of gate operations defines the required logic for eu2eu1eu0=011. As a first step, output mantissa qubits msq1msq0 are initialized using the state of r7r6. In case rounding-by-truncation would have been used, the work required for this input exponent would be completed. However, for the rounding-to-nearest employed here, cases need to be identified for which rounding up is required, here represented by anc1=1 (i.e., ancilla qubit temporarily set to 1). Following a similar approach, the other blocks of gate operations shown in Figure 5 account for u inputs with eu2eu1eu0=100 as well as eu2eu1eu0=101 or 110. In all cases, the output mantissa qubits are initially defined according to the rounding-by-truncation (or rounding down) approach, followed by an identification of cases requiring a subsequent rounding up. The rounding up is implemented using multiply-controlled X gate operations creating an increment to mantissa qubits (using hidden-qubit approach) and exponent qubits. For input u with eu2eu1eu0=100, the increment operation applied for cases with rounding up can transform the largest sub-normal number 000111 into the smallest normalized output 001000. For input cases with eu2eu1eu0=101 or 110, the output is guaranteed to be a normalized number and therefore the increment operation performed for rounding up can be seen to include controlled-X gate operations on all the output exponent qubits esq2esq1esq0 so that output exponent can be incremented by 1 where required.

Identifying cases that require rounding up is performed as follows:

  • If the most significant qubit in r7r6r1r0 that is not yet used to define the initial state of the output mantissa qubits is in state 1, rounding up is needed if any of the further less significant qubits in r7r6r1r0 is in state 1;

  • Identifying a “tie.” If the most significant qubit in r7r6r1r0 that is not yet used to define the initial state of the output mantissa qubits is in state 1 with all other less significant qubits in state 0, a tie has occurred. In that case, rounding up is applied if the least significant qubit in the initialized output mantissa is in state 1, that is, msq0=1.

The approach used here is consistent with the rounding-to-nearest approach used in the IEEE 754 standard.

Advertisement

6. Quantum circuits for floating-point division

Building on the concepts illustrated in the quantum circuit implementation of floating-point squaring with rounding-to-nearest for the output, the more complex example of floating-point division will be detailed. It is shown here that for the floating-point divider, the quantum circuit implementation of logical steps required to perform rounding-to-nearest for the output displays significant similarity with those for the squaring detailed in Section 5.2.

6.1 Non-restoring and restoring integer dividers

First, quantum circuit implementations for non-restoring and restoring integer dividers are discussed, to pave the way for the mantissa division required in the floating-point division circuits discussed later. The integer divider considered here performs the division of a 4-bit integer dividend by a 4-bit integer divisor using the concept of long division. Since the aim is to re-use the resulting quantum circuits later on in the quantum floating-point dividers (where it is assumed that both dividend and divisor are normalized numbers), the assumption is made that 4 qubits define the dividend q3iq2iq1iq0i with q3i=1, and similarly 4 qubits define the divisor, that is, q3dq2dq1d10d with q3d=1.

Before detailing the quantum circuit shown in Figure 6, the underlying principle of a quantum circuit implementation based on long division is summarized. To achieve a 4-bit quotient as output of the division by a 4-bit divisor, it follows that the dividend needs to be a 7-bit integer. Starting from the initial 4-bit (input) dividend, a 7-bit workspace is created by padding three 0 bits at the least-significant end (effectively multiplying the integer value by eight). The long division then proceeds as follows. Starting from the 4 most significant bits in the 7-bit workspace, a comparator operator (denoted as C) is used to check if the binary value represented by the 4 bits equals or exceeds the divisor value. If so, the most significant qubit defining the quotient will be set to 1. Uncomputing the comparator C (denoted by UC) restores the 7-bit register to its state before applying C. Then, subtraction by the value of the divisor (denoted by Sub) is applied conditionally on the state of the corresponding quotient qubit. These steps are then repeated a further three times, each time shifting the 4-bit sub-string of the workspace the comparators work on by one bit toward the least significant bit. For the illustrated division for 4-bit dividend and divisors, the 4 repeated steps will fully define the 4-qubit quotient. The final subtraction steps are not needed to define this quotient, as shown in Figure 6. The SWAP operations shown in Figure 6 are there to arrange the qubits in the correct ordering for successive applications of the comparator C, uncomputation of comparator UC, and the controlled subtractions. All three operations employ a qubit ordering consistent with Cuccaro-type modulo adders.

Figure 6.

Quantum circuit for non-restoring integer division based on 7-qubit integer register and 4-qubit divisor. Creates 4-qubit output qq3qq2qq1qq0.

For the quantum circuit implementing a non-restoring integer divider defined in Figure 6, the qubits are named as follows:

qq3qq2qq1qq0:4qubits defining4bitquotientq3dq2dq1dq0d:4qubits defining4bitdivisorq4d:additional qubit used in2scomplement representationq3iq2iq1iq0i:4qubits defining4bitdividendtest:qubitusas1stcomparator outputc:carryqubit in Cuccarotype arithmeticqin2qin1qin0:3additional qubits in7qubit workspaceE7

The additional qubit q4d is required in the temporary conversion of an unsigned 4-bit representation to a 5-bit 2s complement representation used in the conditional subtractions of the divisor value. The subtractions performed by the sub-circuits termed Sub are based on Cuccaro-type modulo adders. Subtraction instead of addition is achieved by converting the “a” input integer of the adder (notation follows that in Figure 2) into 2s complement representation, and reversing this after the modulo additions is completed. For the controlled subtraction of the divisor defined by 4 qubits, as illustrated here, a 5-qubit modulo adder is employed involving 11 qubits, as shown in Figure 6 for the blocks termed Sub. As discussed in Section 3, Cuccaro-type modulo adders can directly be derived from the Cuccaro-type full adders detailed previously. A 5-qubit modulo adder can be created using 5 successive MAJ sub-circuits, followed by 5 UMA blocks, using the same structure as illustrated for the 3-qubit full adder in Figure 2.

Using the concept of long division, a 4-bit quotient can be obtained by first expanding the 4-bit dividend to a temporary 7-bit workspace defined by 7 qubits as q3iq2iq1iq0i000, that is, 3 qubits initially in state 0 are padded at the back of the original dividend. Using this 7-qubit representation of the dividend guarantees that 4-qubit quotient results with a non-zero most significant bit. As illustrated in Figure 6, long division then creates a quotient defined by 4 qubits as qq3qq2qq1qq0 using the successive application of comparator operations C (as well as the uncomputation of the comparator operator, UC) and controlled subtractions. Here, a 0 output of the comparator means that the integer value represented by the 4-bit segment of the workspace considered matches or exceeds the integer value of the divisor. In this case, the subtraction is performed and the corresponding output qubit is set to 1. Figure 7 shows the quantum circuit implementation of the comparator operation used here based on the work of Xia et al. [19].

Figure 7.

Example comparator circuit. The result is 1 in cases where the integer defined by q3dq2dq1dq0d is greater than the integer represented by q3iq2iq1iq0i, and 0 in both other cases. For consistency with Cuccaro adders, the ancilla qubit is termed c.

It should be noted that the quotient defined by the 4 qubits qq3qq2qq1qq0 can have qq3=0. In the quantum floating-point dividers considered here, this occurrence of 0 for the most significant quotient qubit is to be avoided since, in that case, the least significant output mantissa qubit cannot be defined if the output (quotient) is a normalized number. To prevent this problem, the following changes can be introduced. First, instead of padding 3 qubits in state 0 to the original 4 qubits defining the dividend, now 4 additional qubits are added to create an 8-qubit workspace. As shown in Figure 8, the long division then simply involves an additional step (with comparator and uncomputation of comparator, followed by a controlled subtraction) to define a quotient defined by 5 qubits qq4qq3qq2qq1qq0. If this integer divider is employed as part of a quantum floating-point divider with 4-qubit mantissa for dividend, divisor, and quotient, then we can use this 5-qubit output as follows. In case qq4=0, the 4 mantissa qubits of the quotient are taken as qq3qq2qq1qq0. Alternatively, if qq4=1, then qq4qq3qq2qq1, so that qq0 will be discarded.

Figure 8.

Quantum circuit for non-restoring integer division based on 8-qubit integer register and 4-qubit divisor. Creates 5-qubit output qq4qq3qq2qq1qq0.

It is important to note that the quantum circuits shown in Figures 6 and 8 are non-restoring division circuits, indicating that upon setting the quotient defined by either qq3qq2qq1qq0 or qq4qq3qq2qq1qq0, both circuits also change the state of (many) of the other qubits. In applications of integer dividers where such further changes of quantum states are not desirable, a modification of the divider to a restoring version is needed. Figure 9 shows the quantum circuit implementation of a restoring integer divider for 4-bit dividend, divisor, and quotient based on a 7-bit workspace. Comparing the circuit in this figure to the previous non-restoring circuit in Figure 6, it can be seen that the required changes involve setting up three successive controlled additions to un-compute the effect achieved by the corresponding three controlled subtractions used in defining the quotient qubits. A similar modification to create a restoring version of the non-restoring quantum circuit implementation shown in Figure 8 would similarly involve a series of 4 controlled additions.

Figure 9.

Quantum circuit restoring integer division based on 7-qubit integer register and 4-qubit divisor. Creates 4-qubit output qq3qq2qq1qq0.

6.2 Extension to floating-point division

We now consider the floating-point division where the dividend, divisor and quotient are all defined in floating-point format with 4 mantissa qubits M=4, and 3 qubits defining the exponent E=3.

Based on the integer divider with the 8-qubit workspace, the mantissa division step for a floating-point divider can be created. The use of the 8-qubit workspace guarantees that even if the 5-qubit quotient resulting from long division has its most significant qubit as 0, there are still 4 quotient qubits left to fully define the 4-qubit output mantissa.

In the context of rounding the output of the floating-point division, it is important to consider that at the end of the long-division steps, used to define qq4qq3qq2qq1qq0, the 8-bit workspace will be such that the leading 4 qubits q3iq2iq1iq0i will be in state 0000, while the 4 additional qubits qin3qin2qin1qin0, which were initialized at 0000) now define the remainder of the long division.

In the interest of clarity and brevity, divisions leading to quotients defined as normalized floating-point numbers are considered for now. The extension to sub-normal output is discussed later in this section.

As a first step in setting output employing rounding-to-nearest, the output mantissa qubits are initialized using the rounding-by-truncation (or rounding down) approach by considering two different cases. For qq4=1, the 3 output mantissa qubits (defining the fractional part) mf2mf1mf0 are initialized using qq3qq2qq1. For qq4=0, the 3 output mantissa qubits mf2mf1mf0 are initialized using qq2qq1qq0.

To introduce rounding-to-nearest for the quotient, the two different cases also require a different treatment:

  • For cases with qq4=1, the state of qubit qq0 and the state of the remainder of the long-division step defined in qubits qin3qin2qin1qin0 together define the type of rounding required. Specifically, qq0=0 means that rounding down is to be used, while for qq0=1, the state of qubits qin3qin2qin1qin0 determines whether rounding up is required, a process that also involves identifying a possible “tie,” similar to that described for the floating-point squaring;

  • For cases with qq4=0, it is only the state of the “remainder qubits” qin3qin2qin1qin0 that defines the required type of rounding. In this case, divisions with an even divisor and those with an odd divisor need to be considered separately in terms of identifying the occurrence of a “tie.”

Clearly, introducing rounding-to-nearest in a floating-point divider using the 8-qubit workspace restoring integer divider is complicated by the significant differences for the cases with qq4=1 versus cases with qq4=0 as an output of the long division.

To address this problem, an alternative approach is now proposed using a workspace extended by a further qubit. Specifically, starting from a 4-qubit string defining the dividend, 5 additional qubits initiated at state 0 are used at the least-significant end of the register. This effectively multiplies the original number represented by 32, ensures that the required 6-qubit quotient is obtained. Of course, this involves creating an additional step in the long division, but the added complexity is accepted here on the basis of the simplified steps for defining and rounding of the output. As will become clear from the following analysis, this approach enables the required logic for rounding-to-nearest of the output to be implemented in quantum circuits following a similar approach introduced for the floating-point squaring in the previous section.

Figure 10 shows the first part of the quantum circuit implementation for the restoring long division used to define the 6-qubit quotient qq5qq4qq4qq2qq1qq0. Figure 11 shows the part of the quantum circuit implementation that restores all the qubits not defining the quotient output to their original state.

Figure 10.

Quantum circuit for restoring integer division based on 9-qubit integer register and 4-qubit divisor. Creates 6-qubit output qq5qq4qq3qq2qq1qq0. Part 1.

Figure 11.

Quantum circuit for restoring integer division based on 9-qubit integer register and 4-qubit divisor. Creates 6-qubit output qq5qq4qq3qq2qq1qq0. Part 2.

The key idea now is to use the 9-qubit workspace integer division circuits shown in Figures 10 and 11 for the purpose of the division of the dividend mantissa by the divisor mantissa. In addition to mantissa division, a key role in floating-point division is played by the difference of the dividend of divisor exponents, since this difference largely determines the output exponent (as detailed later).

In the interest of brevity, the quantum circuit implementation considered here includes the following simplifications:

  • only positive numbers will be considered here, so there is no need to use qubits defining the sign for dividend, divisor and quotient;

  • no qubits are allocated to define the exponent of the dividend and divisor. Instead, three qubits de2de1de0 are allocated initialized at 0. It is assumed that an operator ΔE sets the qubits de2de1de0 to contain the binary representation of the difference between the exponent of the dividend and the exponent of the divisor, with EXPbias subsequently added to this difference.

In Figure 12, the quantum circuit implementation of the floating-point divider considered here is shown. The quantum circuit implementation shown assumes that the quotient is a normalized floating-point number. At the end of this section, an extended version without this restriction is presented. Building on the integer divider based on the 9-qubit workspace, the following additional qubits are defined:

Figure 12.

Quantum circuit implementation of floating-point divider assuming a normalized quotient is created.

de2de1de0:4qubits defining the exponent differenceef2ef1ef0:3exponent qubits for quotientmf2mf1mf0:3qubits for mantissahiddenbitnot storedE8

In Figure 12, Div represents the non-restoring part of the integer divider shown in Figure 10. On the right-hand side of the circuit, this divider is uncomputed, as indicated by UDiv. Also, at the end of the floating-point division, the operator ΔE is also uncomputed (shown as UΔE) to restore de2de1de0 to 000.

The quantum floating-point division as shown in Figure 12 proceeds as follows:

  • Operator ΔE defines the difference between dividend and divisor exponents (and adds the exponent bias);

  • Long division of the mantissa of dividend and mantissa of divisor, shown as operator Div in the quantum circuit;

  • Based on the exponent difference set by ΔE and stored in qubits de2de1de0, the exponent of the floating-point output for quotient defined by ef2ef1ef0 is initialized;

  • For long divisions resulting in qq5=1, the three qubits mf2mf1mf0 defining the quotient mantissa (using hidden-qubit approach) are set using qq4qq3qq2. For long divisions resulting in qq5=0, the three qubits mf2mf1mf0 are set using qq3qq2qq1;

  • For the four qubits defining (part of) the remainder of the long division, qin3qin2qin1qin0 all in state 0, temporarily set the qubit c=1;

  • After completing the long division, the qubit test (in state 0) is temporarily in the location of qubit q4d during initialization (due to qubit swap operations performed). The qubit test will now be set to 1 for cases requiring rounding up;

  • For cases with qq5=1, rounding up is always needed for qq1qq0=11 and cases with qq1qq0=10 and c=0. Similar to the floating-point squaring discussed previously in Section 5.2, a tie occurs for qq5=1, qq1qq0=10 and c=1. Then mf0=1 (set by qq2=1) determines cases with rounding up.

  • For cases with qq5=0, rounding up is needed for qq0=1 and c=ket0, while a tie is found for qq0=1 and c=ket1. The tie-break is decided by the state mf0=1 (set by qq1=1 in this case);

  • The following 6 multiply-controlled X operations apply the rounding up by incrementing the mantissa and where needed the exponent;

  • The remaining operations perform uncomputation to restore the qubits not defining the quotient output in their original state.

From this outline, it is clear that the fundamental steps involved in defining rounding-to-nearest for the floating-point divider output demonstrate strong similarity with the corresponding steps in the floating-point squaring.

In the final part of this section, an extended quantum circuit implementation of the divider shown in Figure 12 is considered that can also create quotients defined as sub-normal floating-point numbers. As shown in Figure 13, the first change involves making the quantum gate operations used to initialize ef2ef1ef0 and mf2mf1mf0 and the subsequent rounding conditional on the difference of the dividend and divisor exponents. Specifically, in Figure 13, the qubit q3i (guaranteed to be in state 0 after long division) is temporary set to 1 for cases where the quotient is guaranteed to be a normalized floating-point number. This qubit is then used as (additional) control qubit for the gate operations defining the exponent and mantissa qubits for quotient as well as the subsequent rounding operations. As can be seen, the register de2de1de0 is extended to four qubits by adding de3, since including the capability to output sub-normal quotients means that the difference in exponents defined by ΔE now includes negative numbers. Negative numbers are represented using 2’s complement formulation, requiring the additional qubit.

Figure 13.

Quantum circuit implementation of floating-point divider, with quotient defined as either normalized or sub-normal number. Part 1.

The left-hand side of the quantum circuit shown in Figure 14 considers cases defined by de3de2de1de0=0001. For the case a symmetric bias (EXPbias=3 for E=3) is employed, this means that the exponent of the divisor is greater than the exponent of the dividend by a factor of 2. For long divisions leading to results with qq5=1, the quotient is always a normalized number. The largest fraction that needs to be represented is 15/8/4=15/32, which can be exactly defined as 001111 in floating-point format. The smallest fraction that needs to be represented is then 8/15/4 (rounded down to 4/32 or 000100 in floating-point format).

Figure 14.

Quantum circuit implementation of floating-point divider, with quotient defined as either normalized or sub-normal number. Part 2.

The right-hand side of the quantum circuit shown in Figure 14 considers cases defined by de3de2de1de0=0000. The smallest fraction that needs to be represented for EXPbias=3 is then 8/15/8 (rounded down to 2/32 or 000010 in floating-point format). Similarly, the largest fraction is 15/8/8 (rounded up to 8/32 or 001000 in floating-point format). This shows that using the rounding-to-nearest rounding mode with the required rounding up for the largest fraction is the reason a normalized output results for that case. Rounding-by-truncation creates the sub-normal 000111 for this largest fraction.

In Figure 15, the final two possible results for the difference in exponents of dividend and divisor are considered, followed by the uncomputation of the long division and un-computation of ΔE, so that all qubits not used to define quotient output have been restored to their original state. The left-hand side of the quantum circuit shown in Figure 15 considers cases defined by de3de2de1de0=1111 (or 1 in 2’s complement). For the case a symmetric bias is employed, this means that the exponent of the divisor is greater than the exponent of the dividend by a factor of 4. The smallest fraction that needs to be represented is then 8/15/16 (rounded down to 1/32 or 000001 in floating-point format). Similarly, the largest fraction is 15/8/16 (rounded up to 4/32 or 000100 in floating-point format). The right-hand side of the quantum circuit shown in Figure 15 considers cases defined by de3de2de1de0=1110 (or 2 in 2’s complement). In that case, the largest fraction to be represented is 15/8/32, with rounding-to-nearest requiring rounding up to 2/32 or 000010 in floating-point format. For the smallest fraction 8/15/32, the qubit qq5 will have state 0, but the rounding-to-nearest requires rounding up to 1/32 or 000001 in floating-point format. This means that only the required rounding up needed for the smallest fraction avoids truncation of the output to 0.

Figure 15.

Quantum circuit implementation of floating-point divider, with quotient defined as either normalized or sub-normal number. Part 3.

Comparing the quantum circuit implementations shown in Figures 1315 to the quantum circuits in Figure 12 clearly shows the significant additional complexity created by dealing with potential sub-normal output. However, the steps involved in performing the rounding-to-nearest of the output remain essentially the same.

Advertisement

7. Conclusions

Two applications of quantum arithmetic involving a reduced-precision floating-point representation were analyzed in detail, with a particular focus on how the floating-point output can be defined using a rounding-to-nearest approach similar to the IEEE-754 standard. The analysis shows that despite the obvious differences in the arithmetic involved in the squaring of a number and the division of two numbers, the quantum circuit implementation of the logic required for rounding-to-nearest for both applications shows significant similarities in the modular designs used here. This is an important finding for future work, in particular when quantum circuit compilation techniques are to be used for the automated definition of quantum arithmetic circuits using a larger number of mantissa and/or exponent qubits than in the examples shown here. In future work, the application to a wider class of arithmetic operations will be considered.

Advertisement

Abbreviations

QC

quantum computing

CFD

computational fluid dynamics

IEEE

Institute of Electrical and Electronics Engineers

References

  1. 1. Nielsen MA, Chuang IL. Quantum Computation and Quantum Information: 10th Anniversary Edition. 2nd ed. Cambridge: Cambridge University Press; 2010
  2. 2. Preskill J. Quantum computing in the NISQ era and beyond. Quantum. 2018;2:79. DOI: 10.22331/q-2018-08-06-79
  3. 3. Draper TG. Addition on a quantum computer. arXiv.org 2000; 0008033. was cited in original version
  4. 4. Cuccaro SA, Draper TG, Kutin SA, Moulton DP. A new quantum ripple-carry addition circuit. arXiv.org 2004; 0410184. No journal version available
  5. 5. Ruiz-Perez L, Garcia-Escartin JC. Quantum arithmetic with the quantum Fourier transform. Quantum Information Processing. 2017;16(6):152. DOI: 10.1007/s11128-017-1603-0
  6. 6. Overton ML. Numerical Computing with IEEE Floating Point Arithmetic. 1st ed. Philadelphia: SIAM; 2001. 97 p
  7. 7. Bhaskar MK, Hadfield S, Papageorgiou A, Petras I. Quantum algorithms and circuits for scientific computing. Quantum Information and Computation. 2016;16(3-4):197-236. DOI: 10.5555/3179448.3179450
  8. 8. Haener T, Soeken M, Roetteler M, Svore KM. Quantum circuits for floating-point arithmetic. In: Kari J, Ulidowski I, editors. Reversible Computation. RC 2018, Lecture Notes in Computer Science. Vol. 11106. Cham, Switzerland: Springer; 2018. DOI: 10.1007/978-3-319-99498-7-11
  9. 9. Gayathri SS, Kumar R, Dhanalakshmi S, Kaushik BK. T-count optimized quantum circuit for floating point addition and multiplication. Quantum Information Processing. 2021;20:378. DOI: 10.1007/s11128-021-03296-6
  10. 10. Gayathri SS, Kumar R, Dhanalakshmi S, Dooly G, Duraibabu DB. T-count optimized quantum circuit designs for single-precision floating-point division. Electronics. 2021;10(6):703. DOI: 10.3390/electronics10060703
  11. 11. Gayathri SS, Kumar R, Haghparast M, Dhanalakshmi S. A novel and efficient square root computation quantum circuit for floating-point standard. International Journal of Theoretical Physics. 2022;61:234. DOI: 10.1007/s10773-022-05222-7
  12. 12. Steijl R. Quantum algorithms for nonlinear equations in fluid mechanics. In: Zhao Y, editor. Quantum Computing and Communications. London, UK: IntechOpen; 2022. DOI: 10.5772/intechopen.95023
  13. 13. Yuan S, Gao S, Wen C, Wang Y, Qu H, Wang Y. A novel fault-tolerant quantum divider and its simulation. Quantum Information Processing. 2022;21(5):182. DOI: 10.1007/s11128-022-03523-8
  14. 14. Yan F, Chen K, Venegas-Andraca SE, Zhao J. Quantum image rotation by an arbitrary angle. Quantum Information Processing. 2017;16:282. DOI: 10.1007/s11128-017-1733-5
  15. 15. Zhang R, Xu M, Lu D. A generalized floating-point quantum representation of 2-D data and their applications. Quantum Information Processing. 2020;19:390. DOI: 10.1007/s11128-020-02895-z
  16. 16. Moawad Y, Vanderbauwhede W, Steijl R. Investigating hardware acceleration for simulation of CFD quantum circuits. Frontiers in Mechanical Engineering. 2022;8:925637. DOI: 10.3389/fmech.2022.925637
  17. 17. Steijl R. Quantum circuit implementation of multi-dimensional nonlinear lattice models. Applied Sciences. 2023;13(1):529. DOI: 10.3390/app13010529
  18. 18. Babu HH, Mia S. Design of a compact reversible fault tolerant division circuit. Microelectronics Journal. 2016;51:15-29. DOI: 10.1016/j.mejo.2016.01.003
  19. 19. Xia H, Li H, Zhang H, Liang Y, Xin J. Novel multi-bit quantum comparators and their application in image binarization. Quantum Information Processing. 2019;18(7):229. DOI: 10.1007/s11128-019-2334-2
  20. 20. Orts F, Ortega G, Combarro EF, Rua IF, Garzon EM. Optimized quantum leading zero detector circuits. Quantum Information Processing. 2023;22:28. DOI: 10.1007/s11128-022-03784-3

Written By

René Steijl

Submitted: 24 February 2024 Reviewed: 06 May 2024 Published: 07 June 2024