A Case for Synthesis of Recursive Quantum Unitary Programs

Quantum programs are notoriously difficult to code and verify due to unintuitive quantum knowledge associated with quantum programming. Automated tools relieving the tedium and errors associated with low-level quantum details would hence be highly desirable. In this paper, we initiate the study of program synthesis for quantum unitary programs that recursively define a family of unitary circuits for different input sizes, which are widely used in existing quantum programming languages. Specifically, we present QSynth, the first quantum program synthesis framework, including a new inductive quantum programming language, its specification, a sound logic for reasoning, and an encoding of the reasoning procedure into SMT instances. By leveraging existing SMT solvers, QSynth successfully synthesizes ten quantum unitary programs including quantum adder circuits, quantum eigenvalue inversion circuits and Quantum Fourier Transformation, which can be readily transpiled to executable programs on major quantum platforms, e.g., Q#, IBM Qiskit, and AWS Braket.


INTRODUCTION
Quantum programming is a key step in enabling the various application of quantum computing such as factorization, simulation of physics and optimization.However, programming quantum computers is hard due to unintuitive quantum mechanics.To help ease the programming of quantum computers, circuit synthesis techniques have been proposed to automatically generate quantum circuits [Amy et al. 2013;de Brugiere 2020;Kang and Oh 2023;Kitaev 1997;Saeedi et al. 2011;Shende et al. 2006;Younis et al. 2021].
Unfortunately, these synthesis frameworks underperform when the number of qubits of the quantum circuit to synthesize is as large as 5.For example, QFAST [Younis et al. 2021], a recent quantum circuit synthesis framework, can only synthesize QFT and adder circuit up to 5 qubits.And QSyn [Kang and Oh 2023], a quantum circuit synthesis method based on user-supplied components, needs an average time of 687.5 seconds for solving 4-qubit problems and fails to synthesize a 6-qubit circuit within one hour.These methods cannot scale with the rapid development of qubit numbers in hardware, with more than 1000 qubits by the end of 2023 estimated by IBM [Gambetta 2022].Moreover, synthesizing a quantum circuit will even fail at the start because it is impossible to write the exponential-sized matrix specifying the synthesis goal.For example, QSyn requires 16 input-output state vector pairs as the specification for a 4-qubit Toffoli circuit.Additionally, the circuit generated by the synthesizer is hard to understand by humans, which prevents potential human customization to the circuit after synthesis.
In this work, we propose QSynth, the first synthesis framework for inductive quantum programs.In contrast to previous frameworks focusing on circuits, the synthesis target of QSynth is inductivelydefined families of quantum circuits without mid-circuit measurements (i.e.unitaries).QSynth can exploit the inductive structure of quantum programs and, compared to previous circuit synthesis methods, 1) generate quantum circuits with an arbitrary number of qubits, 2) allow user to use a single input-output style specification for synthesis, and 3) produces more readable and structured quantum program code that are easy to customize by human, as illustrated by Figure 1.To enable the synthesis of inductive quantum programs, there are three challenges.First, the synthesis framework requires a representation of the specification of quantum programs.Previous methods such as quantum Hoare triple [Ying 2012], path-sum [Amy 2018], and tree automaton [Chen et al. 2023] are all defined on fixed-dimension quantum systems and thus cannot be directly applied.Naive extensions of these representations with a variable qubit size do not work because symbolically representing matrices and automata is hard, limiting their usage for synthesis and verification.We introduce a specification language in QSynth, which enables intuitive input-output style specification for quantum programs and supports all path-sum quantum states with an arbitrary number of qubits.We also propose the hypothesis-amplitude (ℎ − ) specification that uses two functions to specify quantum programs.The specification written in QSynth-spec language will be compiled into ℎ − specification to use in the verification step, which avoids SMT-unfriendly matrices (or graphical representations like automata).
The second challenge is to find a subset of quantum programs that is both expressive enough and efficient to synthesize.Previous programming languages for verifying quantum programs are either low-level circuit languages that do not support inductive structure (e.g., SQIR [Hietala et al. 2021]) or high-level languages that do not have a detailed structure of unitaries (e.g., Quantumwhile language used in Quantum Hoare Logic [Ying 2012]).We design the Inductive-SQIR (ISQIR) language, an extension of SQIR that supports inductively defined quantum programs.We also Proc.ACM Program.Lang., Vol. 8, No. POPL, Article 59. Publication date: January 2024.
A Case for Synthesis of Recursive Quantum Unitary Programs 59:3 define a Hoare-type verification logic that verifies an ISQIR program with respect to an ℎ −  specification.
Finally, the synthesizer needs automated verification of inductive quantum programs.This requires reasoning about matrices, complex numbers, and formulas with a non-fixed number of terms, all of which have very limited support in SMT solvers.To solve this challenge, we define parameterized path-sum amplitudes, which, together with a sparsity constraint, can be efficiently encoded in SMT solvers.We further show that this set of expressions is expressive enough to specify and synthesize many quantum programs.
We evaluate QSynth on 10 inductive quantum programs including state preparation, arithmetic and textbook quantum algorithm procedures.We showcase that QSynth can synthesize practical quantum programs including quantum adders [Cuccaro et al. 2004;Feynman 1985], a quantum subtractor, the eigenvalue inversion for HHL [Lloyd 2010] algorithm, quantum teleportation [Bennett et al. 1993] and Quantum Fourier Transform [Coppersmith 2002].All synthesis processes succeed in 5 minutes, while many of the programs cannot be synthesized by previous methods when the number of qubits is larger than 6.A further investigation of synthesized programs shows that QSynth successfully captures the inductive structure of the targeting problem and produces better programs than human-written programs in Qiskit.
Contributions.Our contributions in this paper are multi-folded.
• We propose QSynth, the first synthesis framework for inductively-defined quantum unitary circuit family.• We introduce the QSynth-spec language that enables input-output style specification for inductive quantum programs, and the hypothesis-amplitude (ℎ − ) specification for scalable verification of quantum programs.• We develop the syntax and the semantics of the inductive SQIR (ISQIR) language that supports recursively defined families of quantum unitary circuits, and a Hoare-type logic for proving the correctness of ISQIR program, with an ℎ −  specification as predicates.• We design Parameterized path-sum amplitude (PPSA) function, which leads to the efficient encoding of the verification process into SMT instances.• We evaluate QSynth with a benchmark of 10 quantum programs, and show that QSynth is able to synthesize practical quantum programs.

QUANTUM PRELIMINARIES
In this section, we introduce the background knowledge about quantum program.We recommend readers to refer Nielsen and Chuang [2010] for more details about quantum computing.

Quantum States
A quantum state consists of one or more quantum bits.A quantum bit (or qubit) can be expressed as a two dimensional vector The  and  are called amplitudes.We frequently write this vector as  |0⟩ +  |1⟩ where |0⟩ = 1 0 and |1⟩ = 0 1 are basis states.A state written |⟩ is called a ket, following Dirac's notation.When both  and  are non-zero, we can think of the qubit as being "both 0 and 1 at once, " a.k.a. a superposition.For example, 1 ) is an equal superposition of |0⟩ and |1⟩.A qubit is only in superposition until it is measured, at which point the outcome will be 0 with probability | | 2 and 1 with probability | | 2 .
A quantum state with  qubits is represented as vector of length 2  .We can join multiple qubits together by means of the tensor product (⊗) from linear algebra.For convenience, we write we may also write |⟩ where  ∈ N is the decimal interpretation of bits | 0  1 ...  ⟩.For example, a 2-qubit state is represented as a 2 2 = 4 length vector where each component corresponds to (the square root of) the probability of measuring |00⟩, |01⟩, |10⟩, and |11⟩, respectively.We may also write these four kets as |0⟩, |1⟩, |2⟩, |3⟩.Sometimes a multi-qubit state cannot be expressed as the tensor product of individual qubits; such states are called entangled.One example is the state 1 √ 2 (|00⟩ + |11⟩), known as a Bell pair.

Quantum Programs
1 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 Quantum programs are composed of a series of quantum operations, each of which acts on a subset of qubits.Quantum operations can be expressed as matrices, and their application to a state is expressed as matrix multiplication.
For example, the Hadamard operator  on one qubit is expressed as a matrix |1⟩. -qubit operators are represented as 2  × 2  matrices.For example, the CNOT operator over two qubits is expressed as the 2 2 × 2 2 matrix shown at the right.
In the standard presentation, quantum programs are expressed as circuits, as shown in

Unitary SQIR
SQIR [Hietala et al. 2021] is a simple quantum language embedded in the Coq proof assistant.SQIR's unitary fragment is a sub-language for expressing programs consisting of unitary gates.
Syntax.A unitary SQIR program  is a sequence of applications of gates  to qubits : Qubits are referred to by natural numbers that index into a global register.A SQIR program is parameterized by a unitary gate set  (from which  is drawn) and the size  of the global register (i.e., the number of available qubits).In Coq, a unitary SQIR program U hence has type ucom g n.  has type ucom  , where  identifies the gate set and  is the size of the global register.
Fig. 3. Semantics of unitary SQIR programs, assuming a global register of dimension .The   function maps a gate name to its corresponding unitary matrix and extends the intended operation to the given dimension by applying an identity operation on every other qubit in the system.
Fixpoint ghz (n : nat) : ucom g ( n + 1) := match n with Semantics.The semantics of unitary SQIR is shown in Fig 3 .A program  is well-typed if every gate's index arguments are within the bounds of the global register and no index is repeated.The program's semantics follows from the composition of the matrices that correspond to each of the applications of its unitary gates.A gate application's matrix needs to apply the identity operation to the qubits not being operated on.This is the purpose of using  1 ,  2 and where  is the matrix interpretation of the gate   and   is the  ×  identity matrix.
Suppose that  1 and  2 are the matrices corresponding to unitary gates  1 and  2 , which we want to apply to a quantum state vector | ⟩.Matrix multiplication is associative, so  2 ( 1 | ⟩) is equivalent to ( 2  1 )| ⟩.Moreover, multiplying two unitary matrices yields a unitary matrix.As such, the semantics of SQIR program  1 ;  2 is naturally described by the unitary matrix  2  1 .

Path-sum Representation
Path-sum, proposed by recent works on quantum program verification [Amy 2018;Chareton et al. 2020], is a representation for describing quantum states based on Feynman's path integral formalism of quantum mechanics, which is widely applied to circuit simulation [Bravyi and Gosset 2016;Koh et al. 2017] and optimization [Amy et al. 2018[Amy et al. , 2014;;Amy and Mosca 2019].The idea of this formalism is to describe a quantum state's amplitude by an integral over all paths leading to that state.In practice, a discrete sum-over-path technique rather than integral is typically used [Amy 2018;Amy et al. 2014;Amy and Mosca 2019;Bacon et al. 2008;Bravyi and Gosset 2016;Chareton et al. 2020;Dawson and Nielsen 2005;Koh et al. 2017;Montanaro 2017].We can describe a sum-over-path abstractly as a discrete set of paths  ∈ Z  2 , together with an amplitude function  and a state transformation  , both depending on specific path , to represent a unitary  : All representations based on the sum-over-path in these previous works [Amy 2018;Bacon et al. 2008;Chareton et al. 2020;Dawson and Nielsen 2005;Koh et al. 2017;Montanaro 2017] share in common that the amplitude  (, ) of all possible paths have the same magnitude and only the phases are different.These forms of the same magnitude but different phase are so typical in many quantum algorithms that they can be used as a succinct representation in the verification, which makes them useful for synthesis purposes.

OVERVIEW
The workflow of QSynth is shown in Fig 4 .First, the user writes an input-output style specification of the program to be synthesized using the QSynth-spec language.Then, QSynth will translate the specification into a hypothesis-amplitude (h-) pair for later verification.Meanwhile, QSynth will invoke a syntax-guided program searcher [Gulwani et al. 2017] to generate all possible candidate programs written in the ISQIR language within a given search space.For each candidate ISQIR program, QSynth will use the unitary ISQIR logic to verify whether the program satisfies the (h-) specification.The verification process will be done in an SMT solver in which all the numbers are encoded in the form of parameterized path-sum amplitudes (PPSA).If the verification process succeeds, a correct program is synthesized and the program can be translated by QSynth's ISQIR compiler into commercial quantum programming languages including Qiskit, Q# and Braket, as shown in Figure 5.If the verification fails, the searcher will try the next candidate program.
Next, we will walk through QSynth's components using the synthesis of the GHZ state preparation program as an example.which was first studied by Greenberger et al. [1989] and is widely used in quantum information, e.g., [Hillery et al. 1999;Liao et al. 2014;Xia et al. 2006 Target Specification.Our first challenge is how to specify our target program, which generates | ⟩ +1 from |0⟩ +1 .The difficulty is two-folded: (1) we want a specification for any input , which excludes any existing specification methods for fixed dimensions (e.g., Quantum Hoare triples); (2) the specification should be as succinct as possible.Then, a direct matrix representation that might require 2 +1 × 2 +1 is less desirable.
In QSynth, the specification is given in an input-output manner using the QSynth-spec language in the form of GHZ : Then, the input-output style specification is compiled into the following hypothesisamplitude (ℎ − ) specification (Definition 4.1) for later verification.An instantiation of (ℎ − ) to the GHZ target program is given as follows: where the term  () in   is a {0,1}-valued function that returns 1 if the Boolean expression  is True and 0 otherwise.Intuitively, the hypothesis function ℎ specifies the interesting input to the program, the desired program's behaviour which is specified by the amplitude function .Precisely, given input , the amplitude ⟨| [ [{{ }}()] ] |⟩ of basis  on the input  for a desired program  is given by  (, , ), where ,  are bit strings.
In the GHZ example, we are only interested in input |0⟩ +1 , which leads to a trivial ℎ containing only  = 0 in (3.1).The output state, which is 1 Our hypothesis-amplitude specification is arguably as natural as the common classical specifications that describe the desired input-output relationship, except that one could have many such input-output pairs (i.e., superposition) with potential complex amplitudes, in the quantum setting, which requires an explicit use of our amplitude function  (, , ).QSynth verifier leverages the newly developed unitary ISQIR logic (Section 5.2) to verify the goal judgement ℎ ⊲   ↔   , which basically states that candidate program   satisfies the (ℎ, ) specification.QSynth verifier recursively applies the logic rules to split the judgement of ℎ,  for larger programs into that of smaller programs.The side conditions are checked by SMT solvers, and the ℎ,  judgement for constant SQIR program for quantum gates that are independent of  are directly computed.

Candidate Program
Fig. 6.An example of synthesizing  + 1-qubit GHZ state preparation program.
In the GHZ example, QSynth verifier first uses the FIX rule to split the goal judgement into two parts.The first part is two formulas (right bottom of Fig 6) to be checked by the SMT solver, with details elaborated on later.The second part is three judgements for   ,   ,  0 (right hand of the verification goal box in Fig 6).After applying the FIX rule QSynth uses the WEAKEN rule to adjust these judgements into an appropriate format.Since  0 ,   ,   are simple programs (formally called const SQIR programs), their corresponding hypothesis-amplitude specifications (i.e.  ,   ,    on the upper right corner of Fig 6) are predefined in QSynth and can be verified directly using the CONST rule.  returns 1 if  =  else 0, indicating the identity matrix.  represents the matrix of the program const H 0, i.e., 1 , where \2 and \2 are integer division (e.g.10\3 = 3), returns 1 if ,  only have the lowest bit difference and 0 otherwise, indicating the matrix   on qubits  1 , ...,   .   will be discussed later.After this verification step, the synthesis terminates and QSynth compiles   into programs as shown in Fig 5 .SMT solving with PPSA.We continue with the two formulas in the bottom right corner box in Fig 6 generated by the FIX rule and aim to verify them by SMT solvers.
The first formula indicates the base case is correct.The relation ≡  indicates the equivalence between two hypothesis-amplitude specifications given specified .In this GHZ example, the first formula becomes: Note that the amplitude functions   or   are generally complex-valued, the automatic equivalence check of which are not generally supported by any existing tool.
Inspired by recent work on quantum program verification [Amy 2018;Chareton et al. 2020], QSynth restricts  into a succinct path-sum representation yet with rich enough expressiveness (elaborated on in Section 6.1), called the parameterized path-sum amplitude (PPSA) in Definition 6.1.In PPSA representation, the non-zero amplitudes over ,  share the same magnitude, which depends on , but can have different phases.Thus, instead of representing a general amplitude function  (, , ), it suffices to represent  (, , ) by components.For instance,   ,   defined in Fig 6, can be described with three components: • A fraction expression indicating the amplitude: 1 √ 2 for both   ,   .• A Boolean expression indicating the non-zero value:  ( = 0 ∨  = 2 +1 − 1) for   and  (\2 = \2) for   .
• An expression indicating the phase: 2 for   , where  [0] means the lowest (i.e.0th) bit of 's binary representation (e.g.6[0] = (110)  = 0).A direct substitution of   ,   would require QSynth, or SMT solvers, to verify which is infeasible.Using PPSA, one can equivalently verify the following by SMT solvers: The second formula concerns the correctness of the induction case.The function  (ℎ,   ) generates the hypothesis-amplitude specification for the recursive call (i.e.  ( − 1)), and (ℎ 1 ,  1 ) ⊗ (ℎ 2 ,  2 ) calculates the one when composing two ISQIR programs together, both formally in Definition 5.4.In this example, the composition with (ℎ,   ) is trivial since   represents an identity matrix, and the second formula becomes There is another major challenge to verify (3.2) by SMT solvers due to the infinite summation over  ∈ N, which comes from the composition of two amplitude specifications (details in Section 5).As a result,  ′ could have an unbounded number of terms, which makes it infeasible for any SMT solver.
To circumvent this general difficulty, we introduce a sparsity constraint, which restricts the number of non-zero points with any fixed  or  to be constant (Definition 6.2), and prove that the composition of two amplitude functions will have finite terms if one of the composed function is sparse.We also prove that all quantum gates applied on a constant number of qubits (e.g.all SQIR programs) have a sparse amplitude function.We only apply this sparsity constraint to SQIR programs predefined in QSynth, and non-sparse functions can be generated as synthesis specifications.However, the use of the FIX statement could generate non-sparse amplitude functions.
As a result, we only allow one use of the FIX statement in our synthesis, as otherwise we could risk composing two non-sparse amplitude functions that would lead to an infinite sum.The specification for the target program, however, could be non-sparse, as we won't need to compose the target programs with others.
In the GHZ example,    is sparse and we have Here the expression  ⊕ ( [ − 1]«) sets the ( + 1)th bit of With this sparsity of    , we can simplify the formula (3.2) to where With the PPSA representation, it suffices to verify the following SMT instance: Organization.In Section 4 we describe the QSynth's specification language and hypothesisamplitude specification.In Section 5 we introduce the ISQIR programming language for the inductive quantum circuit family, and its associated Hoare-type logic, In Section 6 we introduce the PPSA encoding.In Section 7 we discuss the implementation and the evaluation of QSynth on a benchmark of 10 programs.In Section 8 we discuss the related work.In Section 9 we discuss the limitation of QSynth and future work.In Section 10 we give the conclusion.

SPECIFICATION
In this section, we explain how specifications are provided and processed in QSynth.Users provide the input-output specification in the QSynth-spec language (defined in Section 4.1).Then, the specification will be compiled into a hypothesis-amplitude pair (defined in Section 4.2) as the predicate for later verification.We describe the compilation process in Section 4.3

QSynth-spec Interface
To allow users to give the synthesis specification more intuitively, we design language QSynth-spec shown in Fig 7 .Programmers provide the synthesis specification in QSynth-spec, and QSynth will compile it to the corresponding hypothesis-amplitude specification.
(Spec) A QSynth-spec specification is given in the form  ↦ → . indicates the input quantum state to the desired unitary.It is a ket expression constructed by -bit constant numbers   , a −bit variable  [], or the tensor product of two quantum states.Programmers can arbitrarily declare variables in the .For example, consider the  specification for a -bit quantum adder: where  0 is the carry bit of  + . suggests the state transformed from  by the target unitary program. can be constructed by a variable expression , a state shifted by the phase   , or the tensor product of two states.The variables that appear in  are bound: they can only be a variable declared in  or the sum variable  when it is in the sum scope.Output can also be constructed as the superposition state with the same magnitude but different phase by For example, consider the specifications for -qubit GHZ state program and QFT program.
Programmers can omit the amplitude normalization term, which will be calculated by QSynth during the compilation from QSynth-spec to the hypothesis-amplitude specification.

Hypothesis-amplitude Specification for Verification
A critical component of program synthesis is the ability of expressing desired properties of the target programs, usually called specifications.The pre and post conditions of programs in typical Hoare triples provide a natural approach to express these input-output specifications.Quantum Hoare triples [Ying 2012] are hence a natural candidate for describing input-output specifications for quantum programs.However, contrary to the classical setting where pre/post conditions have a lot of flexibility in description, the conventional pre/post conditions in quantum Hoare triples are described by quantum predicates which are Hermitian matrices of exponential dimensions in terms of the system size.The exponential dimension of quantum predicates incurs both the scalability issue and technical inconvenience in automating the reasoning directly based on quantum Hoare triples.
Moreover, for ISQIR programs, one needs to express the specifications for a family of programs for different sizes, which is like classical program synthesis with a varying-length array of variables.However, existing Hoare triples can only be used to provide specifications for quantum systems of a fixed dimension.
To that end, we develop the so-called hypothesis-amplitude specifications for quantum circuit families, where the hypothesis component (denoted ℎ) of the specification describes a certain subset of input states  in the computational basis, and the amplitude component (denoted ) describes the output state of the program on the given input .Both ℎ,  are functions of the index  so that they can describe a family of quantum circuits.Definition 4.1.A hypothesis-amplitude triple contains ℎ,  and .Here ℎ is a set of tuples (, , ) ∈ N 3 (we abuse the notation ℎ to also represent its indicator function of type N 3 → B) that specifies the interested entries of ' semantics,  is a quantum circuit family parameterized with a natural number , and  (, , ) is a complex function with natural number inputs.
A hypothesis-amplitude triple is a valid judgement, denoted ℎ ⊲  ↔ , when Following the above definition, the hypothesis ℎ is like classical pre-conditions and specifies the set of inputs where the post-conditions are provided.For any such input , the output state of the program  () is given by [ [{{ }}()] ] |⟩ =   (, , )|⟩, which explains why  is called the amplitude.We do not always need to specify the program's semantics for all inputs, so we use set ℎ to filter those unnecessary information.By the linearity of unitary, the input-output specification on a set of inputs in the computational basis can be extended to a specification in the linear space spanned by the given input set.
Compared with quantum Hoare triples, our hypothesis-amplitude specification provides a more flexible and arguably more intuitive way to formalize the desired properties on the target functions.For instance, for state preparation, our specification is almost straightforward to use and avoids the extra efforts of converting specifications into exponential-size quantum predicates. 1 Moreover, for all unitary programs, our hypothesis-amplitude specification could provide the same expressive power as general quantum Hoare triples at the cost of using potentially complicated ℎ, .Nevertheless, efficiently encoding into SMT instances are only known in restricted cases of ℎ,  as discussed in Section 6.
4.3 From QSynth-spec to Hypothesis-amplitude Specification Given a QSynth-spec specification  ↦ → , QSynth compiles it to the hypothesis-amplitude specification in two steps: (1) generates the corresponding hypothesis ℎ and a variable map Π based on  , where Π maps variables claimed in  to the qubits; (2) generates the corresponding amplitude function  based on  and Π.
Generate Π and ℎ from  .QSynth first calculates the total number of input qubits by adding up the length specifications of constants and variables in the input.This number depends on the parameter .Then, QSynth assigns indexes from low to high for each variable and constant in  , according to the order they appear in  .The assignment of the variables is included in the variable map Π.For each constant number  represented by qubits   ∼   , QSynth adds expression  [ : ] =  into the hypothesis ℎ.For example, consider the specification for the quantum adder circuit  : |0⟩|[]⟩| []⟩|0  ⟩, the variable map Π and the hypothesis ℎ generated by QSynth are: Generate  from  and Π. QSynth will then compute the value  (, , ) from the output  and the variable map Π. QSynth first calculates the number of qubits.Then, it calculates the normalization factor  which is the total number of qubits in the summed variable plus the number of additions.Then, QSynth evaluates the output into a basis state  Π,, () by replacing input variables with slices of  according to Π and summed variables with corresponding slices of  together with a phase factor   (,Π,,) .Finally, the value of  (, , ) will be 1/ √ 2    (,Π,,) • ( Π,, () = ).If the output contains additions, there will be a basis state and a phase factor for each term and the  value will be the sum of their .For example, the 's of GHZ and QFT in Equation 4.2 are

INDUCTIVE SQIR AND ITS LOGIC
QSynth's goal is to synthesize programs with inductive structures.To that end, we extend the existing intermediate representation SQIR [Hietala et al. 2021] into a language called Inductive SQIR (ISQIR) that defines a family of quantum circuits inductively in Section 5.1.In Section 5.2, we also develop a logic for reasoning about an ISQIR program with respect to an ℎ −  specification.

Inductive SQIR (ISQIR)
We extend SQIR with an inductive structure, similar to fixpoint in Coq, to equip the language with the ability to describe a family of quantum circuits for general input .
At a high level, any ISQIR program is a succinct way to describe a series of SQIR programs indexed by an integer (or input size)  = 0, 1, 2, • • • .Intuitively, const P represents a repeating series of SQIR programs where every entry in the series is the same SQIR program . seq  1  2 concatenates two series  1 and  2 by concatenating SQIR programs of each entry.We also use  1 ;  2 and seq  1  2 interchangeably for notation convenience.relabel   permutes the qubit labels for the th entry with permutation  ().
fix  is the new inductive structure introduced to ISQIR.Specifically, fix  constructs a series of SQIR programs by recursion, with  base cases  0 , ...,   −1 , and the recursive call for the -th entry is sandwiched by the -th entries of ISQIR programs   and   .The choice of fix  is inspired by commonly seen quantum programs and serves as a good syntax guide for synthesis purposes for all the case studies in this paper.
We formulate the semantics of ISQIR programs as functions from a natural number to a SQIR program, i.e., N → SQIR.
For notation convenience, when relabeling a SQIR program with a map  (i.e.relabel  const P), we usually omit the relabel key word.Thus,   can also be denoted as const CNOT n-1 n.
We also develop the following syntax for general permutation  used in ISQIR programs that is also part of the candidate program search space.Definition 5.3 (Permutation Syntax).

Unitary ISQIR Logic
We develop unitary ISQIR logic shown in Fig 8 to reason about ISQIR program's semantics with respect to the hypothesis-amplitude specification (ℎ, ) with helper functions in Def 5.4.The soundness is formally proven in Theorem 5.1, whose proof is postponed to Appendix A.1 in the supplementary material.
One can view (ℎ, ) as a series of incomplete matrices: only those entries in the set ℎ are known, whose values can be looked up in .This gives the intuition behind our rules.The Weaken rule states that any subset of ℎ can also be observed by .The Const rule lifts SQIR semantics to ISQIR semantics.The Replace rule states that if the observed entries are the same for two amplitude functions, then one can substitute the other one with hypothesis ℎ.The Relabel rule relabels the entries of matrices for both ℎ and .The Seq rule calculates matrix multiplication for each term in the series.
The Fix rule checks observed entries for terms with index  <  (base cases) and computes matrix multiplication for  ≥  (inductive cases). 1 (, , ) 2 (, , ), We also define several restricted equivalence relations:

EFFICIENT ENCODING BY PARAMETERIZED PATH-SUM AMPLITUDE
In this section we explain how to encode the hypothesis-amplitude triple introduced In Definition 4.1 and the functions and relations in Definition 5.4 into the SMT instance.

Encoding The Hypothesis-amplitude Triple
The hypothesis-amplitude triple in Definition 4.1 includes a hypothesis set ℎ and an amplitude function , which will be encoded separately.Encoding the hypothesis set.The hypothesis set ℎ refers to a set of natural numbers.Intuitively, we encode the hypothesis ℎ with a Boolean expression  constructed by , , , whose value is true if and only if (, , ) is inside the hypothesis set.Namely, (, , ) ∈ ℎ ⇐⇒ (, , ) = True.
Encoding the amplitude function.Encoding the complex function  is challenging since there is currently no automated program verification tool that supports complex numbers.We solve this by restricting the function  in a limited form that can be encoded into SMT instances.This is a trade-off between the expressiveness of our specification and the feasibility of automated verification.
Parameterized path-sum amplitude (PPSA) function.We restrict an amplitude function  to be a Parameterized Path-Sum Amplitude function: Definition 6.1.A Parameterized Path-Sum Amplitude (PPSA) function   : N 3 → C is defined as •  is a natural number expression of  and it decides the magnitude of all paths.
By restricting amplitude function  to a PPSA function, we disassembled the complex number function  into the combination of several integer or boolean expressions, which allows us to represent  with a set of SMT expressions that enable us to encode the calculation in Definition 5.4 into the SMT solver.This will be discussed in Section 6.2.
Our design for the PPSA function is inspired by Feynman's sum-over-path formalism described in Section 2.4 which has inspired many quantum state representations.However, all of these representations can only express constant size unitary operators and fail to work for any input size.PPSA inherits the expressibility of the existing sum-over-path representations, which can express most famous quantum algorithms (e.g., [Amy 2018;Chareton et al. 2020]), and works for a general input size.Hence, we believe the restriction to PPSA is mild and serves as a good balance between expressiveness and feasibility.Some common unitary operators that can be represented by h- triple while restricting the amplitude function to PPSA are listed in Table 1.More examples are provided in Section 7.

Name
Unitary Operator H- Specification

Encoding Reasoning Based on ISQIR Logic
To enable SMT-based automation in reasoning, one needs to encode the functions and the equivalence relations of ℎ,  defined in Definition 5.4 into SMT instances.In the cases of the relabeling functions ( • ℎ), ( • ), the predecessor function pred (ℎ, ) and the composition function comp(ℎ 1 ,  1 , ℎ 2 ,  2 ), all used operations are supported by SMT solvers directly and the encoding is trivial.We hence focus our discussison on the non-trivial encoding of the composition function  1 *  2 and the equivalence relations.
Encoding the composition function.Recall the  1 *  2 function from Definition 5.4: Since the summation is over  ∈ N, by definition, the  1 *  2 function is a composition of two infinite-dimension unitaries, and hence cannot be calculated directly.
All existing symbolic matrix multiplication methods can only deal with a fixed dimension or a fixed number of terms (e.g., [Amy 2018]) and hence are not applicable in our case.
Fortunately, we observe that in many cases, non-zero values of the function  are sparse, making the composition possible.In particular, we show the possibility of computing the function  1 *  2 when one of  1 or  2 is sparse.The sparsity of  is precisely defined as Definition 6.2.We say a function  : N 3 → C is sparse iff: there exist two functions X, Y : N 2 → {N} and for any inputs, the sets returned by X, Y always have constant sizes (i.e., independent of inputs , , ), and further satisfy We denote such sparsity by  ⊴ (X, Y).
Intuitively, when  ⊴ (X, Y) holds, for any given  0 ,  0 ∈ N,  ( 0 ,  0 , ) has non-zero values only on a finite of  points, the set of which is Y ( 0 ,  0 ).The same intuition holds for X except for the case when  0 ,  0 are given.Example 6.1.We show the amplitude function that can represent the ISQIR program const H 0 and its sparsity tuple X, Y as an example.
The operation ⊕ is a bit-wise operation and the expression  ⊕ 1 flips the 0th bit of  (e.g.(101 Intuitively, X, Y are constructed in this way since const H 0 only modifies the 0th qubit. Now we explain how to encode  function  1 *  2 when one of  1 ,  2 is sparse.Suppose  2 is sparse and we have  2 ⊴ (X, Y), we know that  2 (, , ) ≠ 0 only when  ∈ X(, ).So  1 *  2 can be calculated by The summation on the right hand has only a fixed number of terms by sparsity which allows encoding into SMT instances.Similarly, when  1 is sparse and  1 ⊴ (X, Y), we have 1 (, , ) 2 (, , ).
Moreover, sparsity of  can be established in many cases.(Proof in Appendix A.1).
• If  is sparse and  is a series of injective natural number mappings, then  •  is sparse.
The above theorem shows that the  functions for all SQIR programs, and for relabeling a SQIR program or composing two SQIR programs are sparse.So non-sparse s only appear in the fixpoint syntax.The candidate program from our searcher has at most one fixpoint due to the challenge discussed in Section 9.So when composing two amplitude functions  1 ,  2 , there is always at least one sparse function and our composition strategy can work.
Encoding the equivalence relations.Given a hypothesis ℎ and two complex functions ,  ′ , suppose the functions ,  ′ are in the form: QSynth verifier checks the equivalence  ≡ ℎ  ′ by the checking following SMT instance and rejects the equivalence when the SMT solver gives a negative result.

EXPERIMENTAL CASE STUDIES
We demonstrate six additional case studies and provide the output Qiskit programs compiled from synthesized ISQIR programs for better illustration.Then in Section 7.7, we compare the performance of QSynth against the previous quantum circuit synthesis frameworks, QFAST [Younis et al. 2021] and Qsyn [Kang and Oh 2023].

Quantum Adder
Motivation and Background.Quantum circuits for arithmetic operations are required for quantum algorithms.One important example is the adder circuit.Feynman [1985] first proposes the quantum full adder circuit to implement |0⟩|⟩|⟩|0⟩ ⊗ → | 0 ⟩|⟩|⟩| + ⟩ where ,  are -bit natural number.The first |0⟩ is the carry bit and it is changed to carry value | 0 ⟩ after the addition.This design unfortunately needs  more qubits to store the sum of  + .To reduce the qubit usage, Cuccaro et al. [2004] proposed a new ripple-carry adder that uses  fewer qubits than the full adder design.When given different specifications, QSynth can synthesize both adder circuits.
Full Adder Synthesis.We let QSynth synthesize a program   that   () provides a -qubit full quantum adder (i.e.  (0) is an identity unitary) with the specification in Equation 4   Cuccaro's Adder Synthesis.To reduce the number of qubits in the circuit, we want to synthesize an in-place adder.The specification is given as: We use Cuccaro's MAJ and UMA circuit structures as predefined modules in the synthesis.QSynth flattens these two modules in the compilation process.

Quantum Subtractor
Another important quantum arithmetic operation is the quantum subtractor.A classical -bit subtractor is usually implemented based on the two's complement theory (i.e. −  =  + Ā + 1 where Ā flips each bit in ), which is also used by many existing quantum libraries (e.g.QLib [Lin et al. 2014],QPanda [Dou et al. 2022]).However, this method requires additional ancilla qubits to build the "+1" operation.To reduce the qubit usage, we let QSynth synthesize a -bit subtractor using the same number of qubits in the -bit ripple adder.
Synthesis with QSynth.We let QSynth synthesize a program with the specification below.def ConditionalAdder ( N ) :

Quantum Conditional Adder
Motivation and Background.Quantum Conditional Adder is a necessary arithmetic operation for many known quantum algorithms, including quantum multiplier and Thapliyal et al. [2019] 10(b)) with its conditional version, which is also the circuit generated by Qiskit.However, this method needs four-qubit Toffoli gates, which needs 14 CNOT gates to implement, increasing the total count of CNOT gates in the decomposed circuit.We let QSynth synthesize a target program using only X gate, CNOT gate, and Toffoli gate to find a better solution.

Eigenvalue Inversion
Background and Motivation.Eigenvalue inversion is a necessary arithmetic step in HHL [Lloyd 2010], a quantum algorithm for linear systems of equations.Given a -qubit eigenvalue state |⟩, the eigenvalue inversion circuit needs to calculate |1/⟩.In practice, only the first  decimal places of the 1/, denoted as   , and the remainder  0 are kept.The precision  depends on the accuracy requirement of the algorithm.
Synthesis with QSynth.We let QSynth synthesize a program that can calculate the first  decimal places of 1/ and keep the remainder  0 for further use.Since QSynth's specification syntax only supports binary integers, we use the fact 2  =  *   + 0 where   is the quotient we want to give the specification.The example below shows our intuition.[Thapliyal et al. 2019]'s general quantum division circuit.Compared to calculating |1/⟩ with Thapliyal's division circuit, which is constructed by  (, )-qubit subtractor and conditional adder, this program uses -qubit one.This significantly reduces the number of qubits required when  is large.

Quantum Fourier Transform
Motivation and Background.Quantum Fourier Transform (QFT) [Coppersmith 2002] is the classical discrete Fourier Transform applied to the vector of amplitudes of a quantum state.QFT is a part of many quantum algorithms, notably Shor's algorithm [Shor 1994], QPE algorithm [Kitaev 1995], and algorithms for the hidden subgroup problem [Ettinger and Hoyer 1999]  be expressed as a map in two equivalent forms: Synthesis with QSynth.We use the specification in Equation 4.2 to synthesize a program   that   () returns the  + 1-qubit QFT circuit.
QSynth fails to synthesize a simple fixpoint structure QFT circuit.Therefore we synthesize it in two steps to help QSynth synthesize a nested structure circuit.First, we let the synthesizer generate a program   that transforms the state of qubit  into state |  ⟩ and keep the state of qubits  0 ∼  −1 unchanged.The specification is:

𝑛-qubit Quantum Teleportation
Motivation and Background.Quantum teleportation [Bennett et al. 1993] is one of the most famous quantum applications that can be implemented in the near term.It is a technique for transferring quantum information from a sender at one location to a receiver some distance away.The sender does not have to know the particular quantum state being transferred.Moreover, the recipient's location can be unknown, but to complete the quantum teleportation, classical information needs to be sent from sender to receiver.The right-hand side circuit shows the process for sending one-qubit state |⟩ from Alice to Bob.A : ψ Synthesis with QSynth.We let QSynth synthesize the unitary circuit part (before the measurement) of the qubit quantum teleportation process.Suggest Alice wants to send a state |  ⟩ stored in  data qubits to Bob, and they each have  more ancilla qubits which are initialized to state |0⟩  for the teleportation process.We follow the same measurement strategy as the one-qubit teleportation: Alice will measure |  ⟩ and Alice's  aniclla qubits after the unitary circuit, then Bob apply bit-wise CZ and CX gate to Bob's  ancilla qubits based on the result.Assume the data qubits, Alice's ancilla qubits and Bob's ancilla qubits are in state |  ⟩, |  ⟩, |  ⟩ respectively after the measurement, Bob can use bit-wise CZ and CX gate to reproduce the state ) and ⊕  is a reduction XOR operation on   (e.g.⊕101 = 1 ⊕ 0 ⊕ 1 = 0).With this intuition, we let QSynth use the specification below to synthesize the unitary circuit part of a -qubit quantum teleportation program,

Performance Evaluation
In this section, we compare the performance of QSynth and previous circuit synthesis methods.
Implementation.In the experiment, we use the Syntax-Guided Top-down Tree Search [Gulwani et al. 2017] as the searcher with the following bounds on the search space: (1) when searching a candidate program under ISQIR syntax in Definition 5.1, we set the maximum program length to 10 and enumerate the value of  in the FIX syntax in {1, 2, 3}; (2) shorter candidate programs are sent to the verifier first; (3) when searching a permutation  under the syntax in Definition 5.3, we set the maximum syntax derivation depth to 4; (4) when deriving the syntax rule  ::= ,  ∈ N, we enumerate  ∈ [0, 3].All benchmarks in this paper can be synthesized under these bounds.
The implementation of QSynth uses 1k lines of Python.All the experiments are run with Z3 solver version 4.8.9 and Python 3.8. 2 summarizes all 10 benchmarks.They are in three categories: arithmetic circuits, state preparation and sub-programs widely used in quantum algorithms.Many benchmarks are collected from textbooks [Nielsen and Chuang 2010].Arithmetic circuits are frequently used in quantum oracle designs which is necessary for most famous quantum algorithms (e.g.Simons, Shor's algorithms, Grover search algorithm).State preparation is necessary for the setup of many quantum applications (e.g.quantum teleportation).We also collect the necessary quantum sub-program used in quantum algorithms from their paper (e.g.HHL algorithm).We compare the performance of QSynth against QFAST [Younis et al. 2021] and Qsyn [Kang and Oh 2023].For QSynth, we use input-output style specification written in QSynth-spec as input.For the other two frameworks, we use their specification interfaces and try to synthesize circuits with  = 3, 4, 5, 6.We use the same gate set when comparing QSynth and Qsyn in each case, while for QFast we use its hard-coded gate set.

Benchmarks. Table
We stop the synthesis and regard the synthesis as a failure if the running time is over 1 hour.All runtimes are a median of three runs.
Table 3 shows the running time of all the experiments.We can see that QSynth successfully synthesizes programs in all 10 benchmarks in at most 5 minutes, while QFAST and Qsyn fail to synthesize circuits for  = 6.From the result, we can see that when the size increases, the time of QFAST and Qsyn indeed grow exponentially, while QSynth only pays a fixed cost for all sizes.The synthesis time of QSynth is comparable to the time to synthesize a corresponding circuit with size 3, with an exception of the n-Toff benchmark.We note that this is because 3-Toffoli is exactly a single Toffoli gate and 4-Toffoli can be done using two Toffoli gates, which are straightforward for QFAST and Qsyn to search.In contrast, QSynth's search is longer because it needs to consider the inductive structure and corner cases of  = 1 and 2. Nevertheless, QSynth quickly outperforms other frameworks on n-Toff at  = 5.

RELATED WORK
Synthesis of quantum circuits.Many methods have been proposed to synthesis quantum circuits of a fixed size [Amy et al. 2013;de Brugiere 2020;Deng et al. 2023a;Kang and Oh 2023;Kitaev 1997;Saeedi et al. 2011;Shende et al. 2006;Xu et al. 2023;Younis et al. 2021].These methods do not consider the inductive structure of quantum programs and do not scale due to their exponential blowup with the number of qubits.
Synthesis of classical programs.The tasks of synthesizing classical programs are intensivelystudied in the recent decades [Gulwani et al. 2017;Kitzelmann 2009].The problem definitions of program synthesis are diverse and orienting, including syntax-guided synthesis [Alur et al. 2013[Alur et al. , 2018;;Hu and D'Antoni 2018;Jha et al. 2010], example-guided synthesis [Gulwani 2011;Gulwani et al. 2012;Polozov and Gulwani 2015], semantics-guided synthesis [D' Antoni et al. 2021;Kim et al. 2021], and resource-guided synthesis [Hu et al. 2021;Knoth et al. 2019].The modern approaches to solve these problems make use of sophisticated search algorithms, such as enumerative search with pruning [Gulwani et al. 2011;Phothilimthana et al. 2016], constraint solver like satisfiability modulo theory (SMT) solver [Feng et al. 2017;Jha et al. 2010;Solar-Lezama 2008], and machine learning [Liang et al. 2010;Menon et al. 2013].We refer curious readers to surveys [Gulwani et al. 2017;Kitzelmann 2009] for a comprehensive picture on the development of classical program synthesis techniques.Many synthesis frameworks are developed into productive tools.For example, the Sketch [Solar-Lezama 2008] framework completes programs with holes by specifications.Rosette [Torlak and Bodik 2013] builds solvers into the language to automatically fill in holes when programming.However, QSynth needs to deal with unique challenges from quantum programs.
Verification of quantum programs.An important procedure in syntax-guided synthesis is to verify any candidate program.Various logic and verification tools for quantum programs are developed in the last decade.QWIRE [Paykin et al. 2017] embedded the formal verification of quantum programs manually in the Coq proof assistant.QBricks [Chareton et al. 2020] do formal verification of quantum programs semi-manually using Why3.Quantum abstract interpretation [Yu and Palsberg 2021] provides efficient tools to test the properties of quantum programs.In particular, the pathsum representation [Amy 2018] of quantum program semantics inspired our representation.Chen et al. [2023] uses tree automaton to verify fixed-size quantum circuits.It is hard to generalize to general-size cases because graphical structures like automaton are hard to symbolically model in SMT solvers.
Quantum Hoare logic [Ying 2012] uses quantum predicates and Hoare triples to express and derive properties of quantum programs.Its language, quantum while language does not have the detailed structure of unitary executions.Its specifications are quantum predicate matrices.Therefore, it cannot be applied to synthesize quantum unitary circuit families.
The use of SMT solvers to automate the reasoning has also appeared in Giallar [Tao et al. 2022], Quartz [Xu et al. 2022] and symQV [Bauer-Marquart et al. 2023], although they only work on quantum circuit compilation passes, quantum circuit optimizations or fixed-size quantum circuit verification.

DISCUSSION AND FUTURE WORKS
QSynth comes with several limitations.At a high level, QSynth sacrifices the expressiveness of the specification due to the limitation in efficient SMT encodings.For example, the lack of the equivalence verification of general complex functions forces us to consider the special form of amplitude in Definition 6.1.The sparsity requirement of  is another such restriction.Any relief of such restrictions would enlarge the space of programs that can be synthesized by QSynth.
Another limitation is that QSynth cannot directly synthesize programs involving nested fixedpoint structures.Synthesizing a program nested loop or fixed-point structure is also a challenging problem in the classical domain.This is because the loop invariant of the program in nested loop structures is unknown and usually non-trivial to figure out.So we make the current QSynth only expand the FIX syntax at most once when generating the candidate program and avoid directly sending a program in nested fixed-point structure to the QSynth verifier.A natural next step is to include the search for the loop invariant in nested loop structures as part of QSynth, and to verify the candidate program against both the specification and the generated loop invariant.
Many quantum algorithms such as Bernstein-Vazirani [Bernstein and Vazirani 1997] and Deustch-Jozsa [Deutsch and Jozsa 1992] have quantum oracle as part of the program.However, it is hard to synthesize and verify quantum programs with oracles because it requires higher-order logic to quantify over arbitrary oracles.It is also an interesting next step to extend QSynth to support quantum oracles.
The design of ISQIR inherits concrete qubit indices from SQIR.This design introduces complications in the inductive variant that have to be addressed with explicit permutations and relabelings.We will explore the possibility of using a different representation of variables to make synthesis less complicated in the future.
Besides extending the expressiveness of specification and the support of more complicated quantum programs, it is also interesting to improve the synthesis performance by integrating classical program synthesis techniques into the quantum domain, including counterexample-guided synthesis, and various search heuristics.

CONCLUSION
We present QSynth, the first quantum program synthesis framework, including a new inductive quantum programming language, its specification, a sound logic for reasoning, and an encoding of the reasoning procedure into SMT instances.By leveraging existing SMT solvers, QSynth successfully synthesizes seven quantum unitary programs and QSynth can generate programs better than the standard solutions in the quantum subtractor and quantum conditional adder cases.These programs can be readily transpiled to executable programs on major quantum platforms, e.g., Q#, IBM Qiskit.
QSynth constitutes the first step toward a fully automated quantum program synthesis framework, which can significantly ease the task of programming in dealing with the low-level details, and hence leave the human programmers to focus on the high-level design of the system.

Fig. 1 .
Fig. 1. Circuit synthesis vs. program synthesis.Circuit synthesis takes an exponential-sized matrix or state vector pairs as input and generates a fixed-size circuit, while program synthesis takes in an input-output specification and generates a program denoting a family of circuits for any input size.
Fig 2(b) shows an example unitary SQIR program for the circuit in Fig 2(a).

Fig. 5 .
Fig. 5. ( + 1)-qubit GHZ state preparation programs in different programming languages.(a) ISQIR program   .(b) The quantum circuit represented by   .(c) Qiskit function compiled from   .Statement circ.cx in Qiskit means appending a CNOT gate to the circuit.Qiskit's semantic requires the program always use class QuantumCircuit(n) to initialize a circuit.So QSynth compiler will wrap program  with an outside function GHZ to initialize the circuit.
Verification of Candidate Programs.Assume the QSynth searcher has identified a candidate   , same as Fig 5 (a), on the left of Fig 6.The program   is constructed by a FIX syntax with subprograms  0 = H 0,   = ID and   = CNOT n-1 n, which is a recursive program with the base case   (0) :=  0 and the inductive case,   () :=   ();   ( − 1);   ().This ISQIR program is equivalent to the recursive Qiskit program in Figure 5c.The FIX syntax, similar to the fixpoint in Coq, enables inductive structures in ISQIR programs.

Theorem 5. 1 .
The rules of unitary ISQIR logic in Fig 8 are sound.
.1.QSynth generates a program   as shown in Fig 10(a)(c) (i.e.Qiskit function full_adder).When  = 0,   does nothing since the circuit only contains the carry bit.When  ≥ 1,   first call   ( − 1) recursively to get a  − 1-bit full adder to calculate | −1 +  −1 ⟩ and the carry bit is stored in qubit 0. Then   uses the one-bit adder circuit   to sum the highest bit in   and   .Proc.ACM Program.Lang., Vol. 8, No. POPL, Article 59. Publication date: January 2024.

Fig. 10 .
Fig. 10.(a)(c) Full quantum adder program   written in Qiskit.circ.ccx(a,b,c)means appending a Toffoli gate that controlled by qubit   ,   on qubit   to the circuit circ.The circuit   is exactly a one-bit quantum full adder circuit.(b)(d) Cuccaro's quantum ripple-carry adder program written in Qiskit language.
Synthesis with QSynth.We let QSynth synthesize a program with the specification below| [1]⟩|0⟩|[]⟩| []⟩ ↦ → | ⟩| *  0 ⟩|⟩| *  + ⟩The term  *  +  indicates qubit  0 is the flag qubit.With this specification, QSynth generates program  shown in Fig 12.We compare the resource count between the conditional adder circuits generated by QSynth and Qiskit, which is shown in Fig 14.All circuits are decomposed with { 3 ,  } gateset by Qiskit's decomposition pass for comparison, where  3 is a generic singlequbit rotation gate.The conditional adder programs generated by QSynth always use fewer quantum resources compared to the one from Qiskit.
Fig 19 shows the program generated by QSynth.
;Zhong-Xiao and Yun-Jie 2006].Preparing the  -qubit GHZ state from |0⟩ ⊗ for any  is a natural task for program synthesis.Namely, we hope to synthesize an ISQIR program  such that [ [{{ }}()] ], the instantiation of  with  ∈ N where N denotes the natural number in the following paper, is a unitary that transfers state |0⟩ +1 to state | ⟩ +1 for any  ≥ 0.

Table 1 .
Examples of Unitary Operators represented by the H- Specification.
's quantum long division algorithm.A -bit Quantum conditional adder circuit implements the transformation |⟩|0⟩|⟩|⟩ ↦ → |⟩| * 0⟩|⟩| *  + ⟩.It sums   and   when the control qubit |⟩ is in state |1⟩ and keeps the state unchanged when |⟩ is in state |0⟩.One way to construct such a program is by replacing each gate in Cuccaro's adder program (i.e., the program in Fig Proc.ACM Program.Lang., Vol. 8, No. POPL, Article 59. Publication date: January 2024. With this specification, the synthesizer generates the program as shown in Fig 17.Statement circ.cp(pi/2**n,N-n, N) in Qiskit means a controlled phase rotation gate   2 on qubit   controlled by qubit   − .Then we insert this ISQIR program   (i.e.Qiskit program Zn) into the database so QSynth can use it for further synthesis, which leads to the QFT program in Fig 18.

Table 2 .
Summary of all benchmarks used in the evaluation.

Table 3 .
Running time of all benchmarks used in the evaluation.