Quantum Calculi—From Theory to Language Design

: In the last 20 years, several approaches to quantum programming have been introduced. In this survey, we focus on the QRAM (Quantum Random Access Machine) architectural model. We explore the twofold perspective (theoretical and concrete) of the approach and we list the main problems one has to face in quantum language design. Moreover, we propose an overview of some interesting languages and open-source platforms for quantum programming currently available. We also provide the higher-order encoding in the functional languages qPCF and IQu of the well known Deutsch-Jozsa and Simon’s algorithms.


Introduction
Quantum computers are nowadays a tangible reality. Even if physicists and engineers have to continuously address problems in the realization of quantum devices, the advance of these innovative technologies has presented a noticeable speedup. Examples of this are the universal architectures behind IBM Quantum Experience or Rigetti's Forest platform [1] that are potentially able to solve problems more efficiently than a classical computer.
In the last fifteen years, the definition and the development of quantum programming languages catalyzed the attention of a part of the computer science research community [2][3][4][5][6][7][8]. The interest in the development of a quantum language of is twofold. On the one hand, it presents a theoretical challenge: a calculus able to characterize (all or an interesting class of) quantum computable functions provides the basis for a quantum computability theory. On the other hand, a solid quantum programming design is essential to design robust, powerful and easy languages, which effectively allow users to program emerging quantum architectures. In quantum language design, a computer scientist has to address (at least) the following questions: What is the Architectural Model the language refers to?; How to manage quantum data (which are non-duplicable to ensure the no-cloning property, so need a form of linear treatment)?; what class of quantum functions one aim to program (expressive power)?
In this survey, we provide some possible answers, starting from the state of art and proposing some examples of quantum programming in two functional calculi, called qPCF and IQu respectively.
Moreover, we browse the state of art of some important quantum languages, mainly focusing on the functional programming style.
The purpose of this article is not to reconstruct the entire history of quantum languages but to provide an agile introduction to (part of) the topic and the tools for further study.

Note
In this paper, we assume familiarity with basic concepts about quantum computing such as quantum bits [9], quantum state/registers [10][11][12][13], quantum data properties and quantum algorithms [14]. For the mathematical background, in particular the algebraic characterization of quantum computational spaces and operators, see for example, Reference [15].
The QRAM model can be formulated in several version-for example, one can consider a simplified architecture, where measurement is postponed at the end of the computation [8,20]; otherwise, one can admit general measurements (in this case part of the computation possibly depends on intermediate measurement results) [3,21,22]. In a more general perspective, the natural unidirectionality of the QRAM (the classical "client" morally depends on the quantum " server") can be relaxed. This has been done in Reference [7], where the notion of dynamic lifting is introducedoversimplifying the story, the classical computer is able to receive a query and send back to the quantum device the continuation of the computation. Dynamic lifting is supported, for example, by the language Quipper.
We focus on the QRAM model since the only superposition of data reflects what physicists are realizing in the development of quantum devices. Moreover, this choice based on classical control makes easier the sound description of quantum programs. In fact, it is quite easy to observe that if the set of unitary transformation clearly forms an algebra, they do not form a Hilbert space (the same holds for the set of Quantum Turing Machines).
Projects as Quipper [7], where the QRAM is definitively reformulated in terms of quantum-coprocessor [23], or the recently developed quantum circuit definition language QWIRE [21,24] and the Q# language by Microsoft [25] follow the qd&cc approach.Following the same direction, in Section 4.5.3 we propose two higher-order encoding examples according to syntax and operational semantics of the paradigmatic languages qPCF and IQu.
In literature can be found other approaches to quantum programming that can be considered as orthogonal to the QRAM based one. Oversimplifying, the concept of quantum superposition has been extended from data to programs, introducing notions of "sums of programs" and "quantum control". Roughly speaking, given two correct programs M and N also the combination αM + βN (where α and β are scalar coefficients) is considered meaningful as its semantical and denotational account. The origin of this approach can be traced in the lambda calculus introduced by L. Vaux in Reference [26], where the author, out from the quantum setting, extended the pure lambda-calculus by endowing the set of terms with a structure of vector spaces to study main properties and the relationship with the ordinary lambda-calculus. Based on Vaux's investigations, some versions of the (linear) algebraic and vectorial lambda calculus have been successively studied, also establishing connections with quantum computation (see for example, Reference [27]). The related notions of superposition of program and quantum control (where the control flow notions of sequencing, conditionals, loops and recursion are not entirely classical as for ordinary quantum algorithms) have been addressed in some recent papers. Even if the effective practical utility of these proposals is not yet visible, they offer new interesting perspectives on quantum computability and quantum programming theory. See for example, Reference [28] by Mingsheng and Reference [29] by Sabry, Kaiser-Vizzotto and Valiron.

On the Expressive Power of a Quantum Language
What is the expressive power of a given quantum programming language? Even then, the question can be addressed from two perspectives. For a quantum computability viewpoint, it is interesting to characterize the class of the quantum computable functions encodable in the language. This can be reached, for example, by establishing an expressive equivalence with another computational model, such as the Quantum Turing Machines (QTM). Since QTMs are very complex and programming on they is very challenging, the equivalence can be retraced passing through the equivalence (on total functions) between QTM and finitely generated Quantum Circuit families (QCF), a subclass of QCF. This has been proved, for example, in Reference [8] for the quantum lambda calculi Q. The proof is complex and the result can be roughly summarized as in Figure 1, where the continuous arrow represents a direct equivalence (for which at least a proof has been showed in literature) and the dotted arrow represents an indirect equivalence (obtained as a byproduct): The equivalence with a (sub)classes of QCFs is interesting also from a programming perspective. Some recent research trends suggests that quantum languages can be conveniently formulated and viewed as (higher-order) circuit definition languages [20,21,23,30] (see also Section 3).
Following this idea, a higher-order program parametrically encodes an entire family of circuits: when it is fed with an input dimension, it returns the correct circuit description for the given arity.
In the Quipper language [7], a neat distinction between the notion of parameters and inputs is given. Informally, parameters capture compile-time information (e.g., problem size), whereas inputs concern the run-time circuit generation.
In Section 4.5.3 we see two higher-order examples, respectively the encoding of the Deutsch-Jozsa algorithm [9] in the languages qPCF and IQu and the encoding of Simon's quantum subroutine (the central part of Simon's algorithm [9]) in the language IQu.
For other parametric encodings of quantum circuit families see also Quipper's literature and documentation in References [31,32].

On the Linearity of Quantum Data
It is well-known that quantum data are not duplicable (no cloning property) [33]. Therefore, the design of the type system for a quantum programming language necessarily has to address the problem of data linearity. In this section, we specifically take a look at this aspect through a quick overview of some languages in literature. A more general discussion about the state of art of quantum programming is in Section 3.
Following Selinger's suggestion in his seminal work about quantum programming theory [16], higher-order language can be equipped with some kind of linear type system along the lines of Girard's linear logic (LL), in order to account for the non-duplicability of quantum data [3,8,[34][35][36][37][38].
Several versions of LL have been used in literature.For example, Selinger and Valiron's quantum lambda calculus [3] (on which the programming language Quipper is partially inspired) is based on the multiplicative fragment of affine LL, that is, contraction structural rule is not allowed. This choice is justified by the no-cloning property of quantum states and, logically, signifies that one can not duplicate resources but can discard them.
Instead, Altenkirch and Grattage [4,39] chose a different approach to the (central) problem of copy and discard quantum data. In their language QML (that can not be completely considered QRAM based but is relevant for this discussion) is possible to write expressions like let x = (false + true)in x, x which (apparently) violates no-cloning properties, since the variable x is duplicate in the let expression (notice also that a limited superposition "+" between ground value is admitted). The previous expression does not clone quantum data (this is guaranteed by the formal semantics the authors provide): it shares a copy of the quantum datum among different references. This is captured through a type system based on multiplicative strict LL, that is, linear logic with contraction and without weakening. We spend some further words about these calculi in Section3.
In Dal Lago et al. [34] the untyped quantum lambda calculus Q is introduced and studied. The set of well-formation rules (w.f.r.) is based on Wadler's formulation of LL and the ! ("bang") operator allows distinguishing between duplicable (classical) and non-duplicable (quantum) resources. Classical variables and quantum variables (variables "pointing to" qubits) belong to different syntactical classes. These choices statically respect the linearity of quantum data, that can neither be duplicated or erased (duplication and erasing of classical data are allowed). Moreover, the surface reduction is adopted, to avoid dynamic duplication of linear resources: informally, a term of the form !(M) can not contain quantum variables (this is guaranteed by w.f.r. ) and can not be reduced. Lambda calculus' β-reduction is modified accordingly (in particular, β-reduction is split into three different rules). A small example clarifies the design of the language and the operational behavior of programs.
Example 1 (How to violate quantum linearity). In Q computational steps are defined between configurations that is, triples of the form [Q,QV,M] where Q is "the quantum memory" (it keeps information about the mathematical state we are computing and qubit names), QV is the set of qubit names contained in the lambda term M. Q inherits configurations from Reference [3] (and this tradition can be retraced in Idealized ALGOL programming style [40]).
Let us consider the following well-formed expression, where 1 represent a empty quantum state (a memory containing 0 qubits), the subterm new (1) create a qubit and its name and cnot is the controlled not operator [9]: Observe that the sub-term !(new 1) is a duplicable term because it is marked with the bang and, by w.f.r., does not yet contain references to quantum data. The operational behavior of new c, where c is a constant 0 or 1 is the following: the contraction creates a new quantum bit in the quantum register q and a new quantum variable in the lambda term (this corresponds to the preparation of the input state). We show now a correct computation, where: (i) we do not reduce in the scope of the bang; (ii) we perform firstly the c β reduction, corresponding to classical β reduction (we are passing a duplicable argument to a λ binding a classical variable !x); (iii) we separately (in two steps) create two new quantum bits and the associated quantum variables by contracting subterms new 1 (each of them creates a different, fresh quantum data) (iv) finally we evaluate the cnot on the two qubits created in the reductions by the evaluation → U . The "link" between a qubits name and the related qubit φ is represented in the first element of the configuration by the notation p → |φ ).
The the quantum state |p → 1 ⊗ |q → 0 represents the output of the application of the controlled-not on the state |10 (see Reference [9]). However, if we reduce under the scope of the bang (namely reducing the subterm new (1) before executing the c β -reduction and then create a single quantum variable), we would obtain the following computation: Notice that we have duplicated the quantum variable p, creating a double reference to the same qubit. As a consequence, we could apply a binary unitary transform (cnot) to a single qubit (the one referenced by p), which is not compatible with the basic principles of quantum computing.
The use of Linear Logic is not the only way to control the linearity of quantum data. In the last years, different solutions partially or completely based on dependent types have been useful in the definition of safe quantum languages. See Section3 and References [20,41].

Quantum Programming Languages
In recent years, we have seen an increase in quantum software platforms. Mainstream industries, such as IBM and Microsoft, invested a huge amount of resources both in software development and in the technological advance.
The world of quantum programming can claim two decades of interesting research and is growing day-by-day. In this section, we only focus on a fragment of this world and remand to the literature for a complete overview. Quantum languages can be divided into three classes: practical-minded tools for generating quantum circuit description; quantum languages with a limited (or still underdeveloped) theoretical account; theoretically attractive languages with a focus on semantics and denotational models.
To the first category belongs Forest, the quantum software platform developed by Rigetti and Qiskit (Quantum Information Software Kit), an opensource platform developed by IBM for the 20-qubits quantum computer IBM Q Experience. Forest includes an opensource quantum language called PyQuil embedded in Pyton and offers to the user both a small online real quantum architecture named Quantum Processing Unit (QPU) that support computations up to 8 qubits and a remote Quantum Virtual Machine (QVM) for simulation up to 30 qubits. Qiskit native language is OpenQASM, a low-level quantum assembly language that provides instruction to the actual quantum devices, similarly to PyQuil. IBM provides local and cloud-based quantum simulators (up to 25 qubits). For a complete account and comparison of open-source quantum programming platforms, see Reference [1].
The second category hosts languages such as Quipper by Selinger, Valiron et al. [42] and the Quantum developers KIT, based on the language Q# by Microsoft. Quipper represents one of the more advanced academic reality in the landscape of quantum languages. Quipper represents one of the more advanced academic reality in the landscape of quantum languages. Quipper is embedded (an embedded language provide a "quantum core" sophistically interfaced with a host "classical" language) in Haskell and is based on the QRAM model, successively rephrased in terms of quantum co-processors in Reference [23]. Quipper is higher-order, scalable, permits to easily write programs using ancillae qubits [9], allows to compile classical programs into quantum circuits and simulate in Haskell quantum computations. Moreover, the language pursues the goal to optimize the number of resources needed for computations. Also to this end, in Quipper a neat separation between compile-time inputs (called parameters) and run-time inputs (sometimes called states) is explicit. Quipper does not have a dedicated type system and so lacks both linear and dependent types (see Section 2.3) and does not support a denotational semantics. For this reason, in the present survey, we will focus only on a class of Quipper sub-languages called Proto − Quipper.
Q#, recently introduced by Microsoft, is a stand-alone (i.e., non-embedded) domain-specific programming language used for expressing quantum algorithms. It allows us to write sub-programs that execute on an adjunct quantum processor under the control of a classical host program (in this sense, Q# is a QRAM based language) and also includes a resource estimator. Literature about theoretical properties of Q# is still missing. Despite some feature such as the use of polymorphic types being very interesting, in this paper we do not go deeper in the discussion and remand to the on-line documentation [25].
The third category is the one we focus on in Section 4.

Foundational Quantum Programming Languages
In this section, we discuss some quantum languages called here "foundational" since they have been deeply studied from a theoretical viewpoint. In particular, as previously said, we focus on some QRAM based functional calculi, reserving Section 4.6 to provide references to other (interesting or historically important) languages we do not address here.

Quantum Lambda Calculi
In Reference [16], Selinger rigorously defined a first-order quantum functional language. This paper represents a milestone for a part of the calculi developed in the following years and definitively founds the QRAM-based programming model, where only data (qubits) are superposed and where programs live in a standard classical world. Subsequently the author, in joint work with Valiron [3], defined a quantum λ-calculus with classical control, here dubbed λ sv , that we have briefly discussed in Section 2.3.
The main goal of Selinger and Valiron's work is to give the basis of a typed quantum functional language, based on a call-by-value λ-calculus enriched with constants for unitary transformations and an explicit measurement operator which allows the program to observe the value of one qubit.
Reductions are defined between program states, whose definition is similar to the one of configuration (Section 2.3). Because of the presence of measurement, the authors provide an operational semantics based on a probabilistic call-by-value evaluation. The type system of λ sv is based on linear logic (linearity is extended to higher types), by distinguishing between duplicable and non-duplicable resources. The type system of λ sv is based on linear logic (linearity is extended to higher types), by distinguishing between duplicable and non-duplicable resources.
Selinger and Valiron's type syntax is the following: A, B ::= α|X|!A|A → B| |A ⊗ B where α ranges over a set of type constants, X ranges over a countable set of type variables, → represents the linear implication and is the linear unit type.
As previously said the authors restrict the system to be affine, that is, contraction structural rule is not allowed. The type system avoids run-time errors and is also equipped with subtyping rules, which provide a more refined control of the resources. λ sv enjoys some good properties such as subject reduction and progress and a strong notion of safety. The authors also define a new interesting quantum type inference algorithm, based on the idea that a linear (quantum) type can be viewed as a decoration of an intuitionistic one.
An example of λ sv well-typed term, encoding the EPR circuit is λ sv as EPR = λx.CNOT H(nw(0)), nw(0) and has type !( → (qbit ⊗ qbit)) where qbit is the base type of qubits. The nw constant behaves like the new constant used in Section 2.3. λ sv 's reductions are performed in a call-by-value setting. This is a central characteristic since different strategies are not equivalent (see the original paper or Reference [8]). Moreover, a mixed strategy can produce an hill-formed term.
In Reference [43], the authors provide a categorical semantics for λ sv . For some recent investigations on semantic models, see Reference [44]. See also Reference [45], where the authors define a particle-style geometry of interaction [46] for λ sv .
The pure quantum lambda calculus Q we employ in Example 1 is morally an heir of λ sv , despite the fact that it has been introduced for different scopes. In particular, the "quantum Turing completeness" (i.e., the equivalence with the Quantum Turing Machines) of Q has been proved, in joint with properties of the set of well forming rules (such as Subject Reduction) and a notion of standardization, that ideally aims to capture the separation between classical and quantum part of the computation. Oversimplifying, Standardization Theorem says that a correct computation of a well-formed program always corresponds a computation where reduction steps are performed in the following order: first, one reduces classical redexes (this corresponds to the generation of the suitable quantum circuit among the entire infinite quantum circuit family according to the input dimension one provides); second, one reduces subterms of the shape new(c) (see Example 1); finally, subterms of the shape U q 1 , . . . , q k ), where U is a constant representing a unitary operator and q 1 , . . . , q k is a pattern of quantum variable representing qubits in the quantum register (this corresponds to the evaluation of the circuit generated at stage 1 on the input prepared at stage 2). Different versions of this idea have been implicitly used in several following proposals, in particular for systems designed as quantum circuit generator languages. For the quantum lambda calculus Q two other sibling systems have been defined: SQ [35], a sub-calculus of Q intrinsically quantum polytime (where soft linear logic is used as a basis for the w.f.r. set) and for Q * [36] and extension of Q with a partial measurement operator. Differently from λ sv , in Q * , no strategy is imposed and a form of confluence (based on a notion of probabilistic distributions of observable results) is proved. For a complete account about the "Q-Family", see Reference [8].
An interesting development of Selinger and Valiron's quantum lambda calculus has been developed in Reference [37], where the author propose a fully expressive lambda calculus (λ sv does not allow to encode an entire infinite quantum circuit family) and provide a denotational semantics for higher-order programs based on Girard's quantitative semantics.

QML and the QIO-Monad
Another seminal contribution in the definition of quantum functional calculi is QML, the typed quantum language for finite quantum computations we briefly compared with λ sv in Section 2.3. QML has been developed in References [4,39,47,48].
QML permits to encode quantum algorithms easily. More precisely, a single term can encode a quantum circuit, that is, captures an algorithm of type Q k → Q k , where Q is the type of the qubits for a given k ∈ Nat. The syntax allows building expressions such as αt, where α is an amplitude and t is a term or expressions like t + u where the symbol "+" represents the superposition of terms. However, superposition is controlled by a restrictive notion of "orthogonality" between terms, defined employing a notion of inner product between judgments [4]. Intuitively, t⊥u holds when t and u are "distinguishable in some way" [39]: in other words, one can derive the judgement true⊥false from t⊥u by means of orthogonality rules. Orthogonality of judgments is automatically inferred by static analysis of QML's terms [48].
Quantum superposition can be combined with the conditional construct. The syntax includes both the if then else and the quantum conditional if • then else ; the quantum conditional if • then else is allowed when the values in the branches are orthogonal. For example, the following term represents the encoding of the Hadamard gate in QML: . The denotational semantics of QML has been defined in terms of superoperators. Starting from QML and as a step toward higher-order quantum programming, Altenkirch et.al successively introduced the Quantum IO-monad [44]. The QIO-monad is a functional interface to quantum programming, implemented as a Haskell library and provides a constructive semantics for quantum programming. The main idea to Quantum IO-monad is to split reversible (i.e., unitary, purely quantum) and irreversible (i.e., probabilistic) computations and provides a reversible let operation, supports the use of ancillas (i.e., auxiliary qubits). Various central quantum procedures (e.g., the complete implementation of Shor's algorithm) are implemented.
As pointed out in Reference [19], the QIO-monad represents the early step towards embedding quantum computation inside a functional host language, the key idea behind languages as Quipper and QWIRE. See also Green's Ph.D. thesis, where the author embedded the Quantum IO-Monad inside Agda, a dependently-typed programming language, showing the usefulness of dependent types in the setting of quantum languages. Dependent types prevent some instances of qubit cloning and represent an important tool to address quantum data linearity (see the language QWIRE and qPCF below).

Proto − Quipper
Ross defines the first version of Proto − Quipper in Reference [49] (see also Section 2.3, where we spend some word about its LL-based type system). Proto − Quipper has been introduced as a "bridge" between quantum lambda calculi Quipper, to isolate a well-typed and safe core of the practical language. The syntax and the type system of Ross' Proto − Quipper are inspired to λ sv , with some important additions. A central feature is a boxing-unboxing mechanism for quantum circuits. Informally, the box function turns a function describing a linear operation into a circuit regarded as a classical data (a dual function unbox performs the reverse operation). A boxed circuit can be used multiple times as a part of a larger circuit. This avoids useless circuit duplication and has a positive impact on resource consumptions. Moreover, the syntax is extended with constant terms to capture useful circuit-level operations, like reversing.
Linear types are extended with a specific type Circ(T, U) (where T and U represents the input-output set of wires) of circuits. Proto − Quipper is type-safe (Subject Reduction and Progress Theorems hold) and allows a notion of subtyping similar to the one defined for λ sv . The operational semantics of Proto − Quipper is defined between configurations, as in λ sv and Q. Proto − Quipper can be considered a quantum circuit description language, as QWIRE, qPCF and IQu we describe in the following Sections. Differently from QWIRE, qPCF and IQu, Proto − Quipper is not Turing complete but expressive enough to be an interesting formal core of Quipper. Another version of Proto − Quipper called Proto − Quipper-M has been introduced by Selinger and Rios in Reference [30]. Proto − Quipper-M mainly focuses on denotational models (an aspect we did not address in this paper), so we remand to the original paper.
Proto − Quipper has been also investigated in Reference [50], where Mahmoud and Felty formalize the semantics of the language by encoding the typing and evaluation rules in linear description logic, to reason about the linear type system of the "father" language Quipper.
For a further insight on Proto − Quipper-like languages denotation see also the Combined Linear/Non Linear calculus (CLNL) by Lindenhovious et al. [51], a version of Benton's LNL calculus enriched with string diagrams, a tool that has found applications across a range of areas in computer science and in particular in quantum circuit description languages. LNL calculus also inspired the language QWIRE we introduce in the following section and the denotational model for a language similar to QWIRE based on enriched categories proposed by Staton and Renella in Reference [52].

QWIRE
QWIRE ("choir") [19,21,24,53] is a powerful and flexible language for writing verifired quantum programs. As Quipper, QWIRE is based on the QRAM. The "quantum core" (called circuit language) of QWIRE can be treated as a "quantum plugin" for a host classical language. In its current version it is embedded in COQ proof assistant [19,24] and is a verified circuit generation language. This is reflected by the type system, inspired to Benton's LNL Logic that partitions the exponential data into a purely linear fragment and a purely non-linear fragment connected via a categorical adjunction (notice that this fully reflects also the QRAM structure). This choice also makes the "quantum core" strongly independent from the host language. The type system of the circuit language essentially controls the well formation of expressions concerning wires, that is, the circuit's inputs/outputs. The type system of the host language also controls the boxing mechanism (similarly to Quipper, a circuit can be "boxed" and then promoted as a classical resource/code). QWIRE supports dinamic lifting, that allows the quantum computer to initialize a residual computation in a continuation-passing style. Dynamic lifting is an integral part of many quantum algorithms, including quantum error correction but it is also inefficient because the quantum computer must remain suspended (and must continuously undergo error correction to prevent degradation), waiting for the remainder of the circuit to be computed.
For this reason, QWIRE also supports static lifting, which models the fact that there is no residual quantum state left on the quantum computer after a run and can be used when dynamic lifting is no essential (as in the quantum teleportation encoding).
Differently from Quipper, QWIRE is type-safe and supports both linear and dependent types. A strong type system guarantees the safety of generated circuits. In some sense, QWIRE design inherit and develop the better of the two perspectives we often pointed out in this paper: on the one hand good properties of quantum lambda calculi/paradigmatic languages are preserved; on the other hand, as Quipper it is designed for realistic computations.
QWIRE is an ongoing project and nowadays the main effort is devoted to efficiency, formal verification and optimization of quantum programs, a research area still underdeveloped. See Reference [19] for a complete account about the use of lifting operations and several techniques (safe semantics, automatic type-checking, circuit denotation. . . ) designed for QWIRE.

qPCF and IQu
In this section we describe two (stand-alone) functional languages called qPCF and IQu respectively. See References [20,41] for the complete study of qPCF and see Reference [22] for the current version of IQu. Both qPCF and IQu follow the QRAM-based approach, support the direct manipulation of quantum circuits and enjoy properties such as Preservation and Progress Theorems. W.r.t. our previous proposals [8], strongly oriented to the characterization of quantum computable functions, qPCF IQu are programming oriented calculi. They have been designed to make quantum programming as easier as possible also for a programmer with low/medium skills in quantum computing theory. This scope is eased by the gate based subtended model of computation, that allows representing the quantum part of the program (the one offloaded to the quantum coprocessor in the QRAM architecture) as a quantum circuit. Both qPCF and IQu can be foundational for concrete languages. In particular, as a medium time goal, we are proceeding with the implementation of the ALGOL-like language IQu.

qPCF
The language qPCF is based on a version of the QRAM model where measurements are all performed at the end of the computation. qPCF is a simple extension of Plotkin's PCF: essentially, it extends PCF with a new kind of classical data, quantum circuits, that can be, thanks to the type system, treated as classical objects (i.e., freely duplicated). In qPCF linear logic-based typing has been completely avoided, in favor of the use of a simple version of dependency, that permits to soundly encode quantum circuits families directly controlling arities of subcircuits, avoiding illegal erasing or duplication of wires. qPCF types includes: the types of quantum circuits circ(E) (where E that morally represents a circuit dimension), the type of indexes (i.e., strongly normalizing expressions) Idx and the (standard) quantification over types Πx.τ.
The syntax of qPCF allows us to easily manipulate circuits through operations such as sequentialization and parallelization of an arbitrary number of sub-circuits. For example, consider the program M seq = λu circ(k) .λx Nat .YWux : circ(k) → Nat → circ(k) : σ → σ where Y is the recursion operation, W = λw σ .λu circ(k) .λy Nat . if y (u) (⦂ (u) (w u (pred y))) and σ = circ(k) → Nat → circ(k). Given a term representing a circuit (of ariety k) C : circ(k), it is easy to observe that M seq applied to C and n concatenates n + 1 copies of C.
Consider the program M par = λx Idx .λu circ(k) λw circ(h) . iter x u w : Πx Idx . circ(k) → circ(h) → circ(k + (x * (h + 1))). When applied to a numeral n and two unitary gates U 1 : circ(k) and U 2 : circ(h), M par generates a circuit built upon a copy of gate U 1 in parallel with n copies of gate U 2 . Notice that the term is driven by an argument of type Idx, to ensure that iteration is strong normalizing and, consequently, that the arity of the generated circuit is always a numeral.
qPCF makes especially convenient the programming of quantum algorithms in deferred form, where measurements are all postponed at the end of the computation. qPCF quantum states are not stored. This is possible since the interaction with the quantum co-processor is neatly decoupled using the operator dmeas. It offloads a quantum circuit to a co-processor for the evaluation which is immediately followed by a (von Neumann) Total Measurement. This means that partial measures are forbidden. Thanks to the deferred measurement principle [9], this restriction does not represent a theoretical limitation. Nevertheless, general measurement is an useful programming tool and we model it in the language IQu described in Section 4.5.2.

IQu
IQu (read "Haiku" as the Japanese poetic form) extends Reynold's Idealized Algol, the core of Algol-like languages [40]. Idealized Algol combines the fundamental features of procedural languages, that is, local stores and assignments, with a fully-fledged higher-order procedure mechanism which, in its turn, conservatively includes PCF. We exploited Idealized Algol features to provide a (as much as possible) minimal extension to capture higher-order circuit generation.
In IQu enjoys a simple type theory: classical types (for natural numbers, command and classical variables) are extended with two new types.
The first one, cırc, is the type of quantum circuits. Quantum circuits are classical data, so their type allows to operate on them without any special care. In IQu all circuits/gates U k , of any dimension k, are typed with the unique circuit type cırc. The second one, qVar, types quantum variables (representing quantum content of registers). Since the manipulation of quantum registers requires care, we adapt Idealized Algol's original de-reference mechanism to access the content of classical and quantum variables. Registers can not be duplicated but we can access their classical content via suitable methods and, if interested in that, we can duplicate that content. On the other and, the type of "quantum variables" prevents to read quantum states but allows to measure them.
This reference mechanism allows modeling the no-cloning property of quantum data therefore in IQu we use neither dependent types or linear typer for describing quantum circuits, to keep it as simple as possible.
As for qPCF, basic circuit manipulations (concatenation and parallelization) are easy encodable thanks to recursion and ad hoc operators denoted as ⦂ and respectively.
Evaluation in IQu, as in Idealized ALGOL, and in quantum languages such as References [3,8], is defined between pairs (s, M), where s is a store, that is, a function that links quantum and classical variables to classical data and quantum registers respectively and M is a term. We possibly represent quantum stores as pairs {r, |φ }, where r is the name of the register and |φ is the related quantum state. A fresh quantum register of an arbitrary dimension k can be easily created and bound in a program M by means of the command qnew N x in M, where N is expected to reduce to k.
The function rsize returns the arity of a quantum register. The expression x N evaluates the application of the circuit N to the quantum state stored in x, then it stores the resulting state in x.
Finally, meas N x measures N qubits of a quantum state which x stores (and, update such state, in accordance with the quantum measurement rules).
Formally, IQu does not extend qPCF. However, such an extension is possible, thus we state that IQu extends qPCF with classical and quantum stores. Moreover, since IQu supports general measurement, the programmer does not necessarily encode algorithms in deferred form as, for qPCF.

Programming Quantum Algorithms: Three Higher-Order Examples
In this section, we use qPCF and IQu to provide three higher-order examples of quantum circuit family encodings. The examples are parametric, whereas the majority of the examples proposed in the literature are linear: this means that a term (the program) represents an entire (infinite) quantum circuit family. When fed with the input dimension, the evaluation of the program morally first yields the description of the circuit of the right size among the whole family and then returns to the user the evaluation of the circuit on the quantum state provided as the input of the computation.
We show the encodings of the well-known Deutsch-Jozsa and Simon's algorithms. We implement the circuit representing the Deutsch-Jozsa procedure in qPCF and IQu, to see at work the main peculiarities of the languages and the different solutions we chose in the definition of the syntax, the type and the reduction systems. Finally, we propose the encoding of the circuit family implementing Simon's quantum subroutine in IQu, exploiting its partial measurement operator and the quantum store.
Example 2 (Deutsch-Jozsa Circuit in qPCF). Figure 2 represents, up to the last phase (measurement of the output state), the circuit implementing the well-known Deutsch-Josza algorithm (the generalization of the Deutsch's algorithm) [9], that considers a function f : {0, 1} n → {0, 1} which acts on many input bits: As for the previous two algorithms, we assume that access to the function f is restricted to queries to a device corresponding to the transformation Bf defined similarly to before: for all x ∈ {0, 1} n and b ∈ {0, 1}.
It turns out that classically this problem is pretty easy given a small number of queries if we allow randomness and accept that there may be a small probability of error. Specifically, we can randomly choose say k inputs x1, . . . , xk ∈ {0, 1} n , evaluate f (xi) for i = 1, . . . , k, and answer "constant" if f (x1) = · · · = f (xk) and "balanced" otherwise. If the function really was constant this method will be correct every time, and if the function was balanced, the algorithm will be wrong (and answer "constant") with probability 2 −(k−1) . Taking k = 11, say, we get that the probability of error is smaller than 1/1000. However, if you demand that the algorithm is correct every time, then 2 n−1 + 1 queries are needed in the worst case.
In the quantum case, 1 query will be sufficient to determine with certainty whether the function is constant or balanced. Here is the algorithm, which is called the Deutsch-Jozsa Algorithm: There are n bits resulting from the measurements. If all n measurement results are 0, we conclude that the function was constant. Otherwise, if at least one of the measurement outcomes is 1, we conclude that the function was balanced.
Before we analyze the algorithm, it will be helpful to think more about Hadamard transforms. We have already observed that for a ∈ {0, 1} we have which we can also write as Given a classical input state of the form |0 . . . 01 , the circuit returns a state that, once measured, reveals in the first n − 1 bits if the function f is constant or balanced. If all n − 1 measurement results are 0, we can conclude that the function is constant. Otherwise, if at least one of the measurement outcomes is 1, we conclude that the function is balanced.
In qPCF, unitary gates of arity k + 1 are typed with the (dependent) type circ(k), where the dependency parameter i in type circ(i) is the numeral representation of the integer i. Moreover, the special type Idx is reserved for strongly normalizing expressions that represent dimensions of operation on circuits, such as sequentialization and parallelization. Sequential composition of two circuits C 1 and C 2 (of th same arity k) is denoted as C 1 ⦂ C 2 . The qPCF term iter put in parallel an arbitrary number of quantum gates of arbitrary ariety: for example, iter kUV create a parallel composition of k copies of the gate V and a copy of the gate U.
Let H : circ(0) and I : circ(0) be the (unary) Hadamard and Identity gates respectively. Suppose M B f : circ(n) is given for some n such that M B f ⇓ ⇓ ⇓ α U f where U f : circ(n) is the qPCF-circuit that represents the the black-box function f having arity n + 1 and ⇓ ⇓ ⇓ α represents the evaluation labelled with its probability (in this case, α = 1).
The term λx Idx . iter xHH : Πx Idx . circ(x) generates x + 1 parallel copies of Hadamard gates H and λx Idx . iter xIH : Πx Idx . circ(x) concatenates in parallel x copies of Hadamard gates H and one copy of the identity gate I. Notice that we abstract on types by means of the standard abstraction Π of dependent types. Thus the parametric measurement-free Deutsch-Jozsa circuit can be defined as The last phase is performed by the operator dMeas, the qPCF function that takes as inputs the representation (as numeral) of a classical state and the description of a circuit, applies the circuit on the state and returns a possible, probabilistic results. dMeas is here suitably fed with the n(0 . . . We can make the term parametric also w.r.t. the sub-circuit represented by M B f . It suffices to replace n with the variable n Idx , to replace the black-box with a variable b circ(n) so that, the resulting term is typed Πn Idx .Πb circ(n) .Nat or more simply Πn Idx . circ(n) → Nat (where Nat is the usual type of integers).
Example 3 (Deutsch-Jozsa Circuit in IQu). We show how an IQu term represents the infinite family of quantum programs that encode the Deutsch-Jozsa algorithm (Figure 2), as we have just done with qPCF.
Let H 1 : circ be the Hadamard gate and Id 1 : circ be the Identity gate. Notice that we "decorate" IQu constants representing unitary operators with their arities and, as described in the previous section, all gates/circuits are typed with the ground type circ. We implement Deutsch-Jozsa in IQu by sequentially composing the terms M 1 , x and M 3 , where x : circ is expected to be substituted by the black-box circuit that implements the function f , while both M 1 and M 3 are defined in the coming lines.

•
Let M par be a term that applied to a circuit C : circ and to a numeral n puts n + 1 copies of C in parallel. It is defined as M par = λu circ .λk Nat .YW 1 uk : circ(→) Nat → circ, where Y is the recursion operator, W 1 is the term λw σ .λu circ .λk Nat . if k (u) (u (w u pred(k))) whose type is σ → σ with The circuit M 1 : circ is obtained by feeding the term M par with two inputs: the (unary) Hadamard gate H 1 and the input dimension rsize (r) where r is a co-processor register with suitable dimension. It should be evident that it generates n + 1 parallel copies of the gate H 1 .

•
The circuit M 3 : circ can be defined as (M par H 1 pred(rsize (r))) Id 1 : circ, that is, it is obtained by the parallel composition of the term M par fed by the gate H 1 and the dimension pred(rsize (r)) (generating n parallel copies of the gate H 1 ) and a single copy Id 1 of the identity gate.
Fixed an arbitrary n, the generalization of Deutsch-Jozsa is obtained by using the quantum variable binder qnew n r in P that makes the quantum variable r available in P. The local variable declaration qnew n r in P creates a quantum register which is fully initialized to 0. Since the expected input state of Deutsch-Jozsa circuit is |0 . . . 0 n 1 , we define and use an initializing circuit M init = (M par Id 1 (pred(rsize (r)))) Not 1 : circ that complements the last qubit, setting it to 1 (pred is the standard predecessor function of PCF and rsize (r) extracts the size, that is, the numeber of quantum bits available in the register). Let DJ + be the circuit M init ⦂ M 1 ⦂ x ⦂ M 3 . The (parametric) IQu encoding of the Deutsch-Jozsa algorithm can be defined as λx circ . qnew n+1 r in ((r DJ + ); meas n r). Given an input dimension n and an encoding of the function f to evaluate, the program solves any instance of the Deutsch-Jozsa algorithm.
Let M B f be a black-box closed circuit implementing the function f that we want to check and let DJ be DJ + [M B f /x] namely the circuit obtained by the substitution of M B f to x in DJ + . By means of the suitable evaluation rule of IQu, we have {(r, |0 . . . 0 n )}, r DJ ⇓ ⇓ ⇓ 1 {(r, |φ )}, skip where |φ is the computational state after the evaluation of DJ . To measure the state |φ we use the operational rule for the constructor meas n r to conclude {r, |φ }, meas n r ⇓ ⇓ ⇓ 1 {r, |φ }, k, where k is the (deterministic) output of the measurement and 1 is the associated probability.
Example 4 (Simon's algorithm in IQu). Simon's quantum algorithm is an important precursor to Shor's algorithm for integer factorization. Simon's algorithm [54] solves in quantum polynomial-time a classically hard problem [55] which can be formulated as follows. Let be f : {0, 1} n → X (X finite) a black-box function. Determine the string s = s 1 s 2 . . . s k such that f (x) = f (y) if and only if x = y or x = y ⊕ s. Simon's algorithm requires an intermediate, partial measure of the quantum state. The measurement is embedded in a quantum subroutine that can be eventually iterated at most n times, where n is the input size. We here focus on the inherently quantum relevant fragment of Simon's algorithm [56]. The circuit in Figure 3 implements the quantum subroutine of Simon's algorithm. The following evaluation respects the IQu semantics: where |φ is the state after the evaluation of the circuit M SP . We can measure the first n quantum bits as follows: {(r, |φ )}, meas n r ⇓ ⇓ ⇓ α {(r, |φ )}, k, where φ is one possible state after the partial measurement and α is the related probability. The classical output k can be used as feedback from the quantum co-processor by the classical program, in this way it can decide how to proceed in the computation. In particular, it can use the measurement as guard-condition in a loop that iterates the subroutine. So we can easily re-use the Simon-circuits above as many times as we want, by arbitrarily reducing the probability error.

Other Quantum Calculi
In literature, several imperative approach to quantum computation have been proposed. The Quantum Computation Language (QCL), designed and implemented by Omer [57], is based on the syntax of C programming language. Its interpreter is implemented using a simulation library for executing quantum programs on a classical computer and it has been used as a code generator for classical machine controlling a quantum circuit. Along with QCL several other imperative quantum programming languages were proposed, see for example, References [58] and [2].
Starting from the seminal paper, Reference [59], some measurement based calculi have been defined. In particular, the so-called measurement calculus [5] has been developed as an efficient rewriting system for measurement-based quantum computation. In Reference [5], the authors defined a calculus of local equations for 1-qubit one-way quantum computing. Roughly speaking, the idea is that a computation is built out of three basic commands, entanglement, measurement and local correction. The authors define a suitable syntax for these primitives, which permits the description of patterns, that is, sequences of basic commands with qubits as input-output. By pattern composition, it is possible to implement quantum gates and quantum protocols. Moreover, a standardization theorem, which has some important consequences, is stated and proved.

Conclusions
Quantum programming theory is a dynamic and vital research field. In the last twenty years, several languages have been introduced and implemented. Quantum lambda calculi provided the basis for quantum computability, establishing the equivalence with other computational models. Foundational languages helped in developing ad hoc type theories for the sound management of data according to quantum mechanics principles. More practical languages showed how to program simulated and real small devices, in the perspective of the availability of a universal, powerful quantum device.
Different design choices bring different benefits and weaknesses. The choice of the QRAM architectural model, which assumes a strong separation between data and control, allows to efficiently manage the restrictions due to programming with quantum data. Moreover, it seems to be the more realistic architecture for physical implementation. Concerning the design of the type system, in this paper, we met several solutions. Linear Logic (LL) perhaps remains the most natural option for quantum type systems, since LL modalities allow to syntactically distinguish between duplicable and non-duplicable resources and reduction strategies can easily preserve the no-cloning properties of quantum data. Nevertheless, different solutions such as the use of dependent types are emerging as valid alternatives. This holds both for "stand-alone" languages (such as qPCF) and for embedded languages, in which the quantum core is purely linear and neatly separated from the "host" part, as happens in QWIRE and Quipper. This classification can be central to the scope of a language. On the one hand, a stand-alone calculus can represent a better solution if one is interested in theoretical studies since good properties (of the type system or the operational semantics) do not depend on the properties of the host language. On the other hand, an embedded language allows more direct control of quantum operations and is suitable for the implementation in automatic verification systems.
Concerning the denotational semantics of quantum languages, an argument we did not address in this paper, many fascinating theoretical results have been shown extending to the quantum setting different techniques and tools (as the Geometry of the Interaction or several categorical frameworks) and various challenging questions remain open [44,45,52,60].
We conclude that the theoretical results of the last decades and the current technological development seem to happily converge in the same direction. The advances of quantum technologists, that year-by-year provide more efficient architectures, also suggest how quantum computers have to be programmed. For example, the NISQ (Noisy Intermediate-Scale Quantum) technology, available shortly, is providing important steps toward bigger and fault-tolerant computers and could early become a concrete reference for realistic software design [61]. Thanks to this parallel effort, today we can design increasingly efficient languages and run quantum algorithms on both simulators and real prototypes [1]. At the same time, formal verification of quantum programs (e.g., based on logic [62,63] or on mechanizable tools [64]) became an urgent and exciting challenge. We are entering the quantum future and we are ready to program it.
Funding: This research received no external funding.
Acknowledgments: I wish to dedicate this paper, that embraces one of the passions of my life, to four very special people that, day-by-day, make me happy: my beloved-hippie-super-mom Franca (the genius of the family), my brother-friend-uncle Franco (the cub of the family), my friend-confidant-maître Andrea Masini (the Don Quixotte of our Department of Computer Science) and my best friend Gionata (who, in the last 20 years, has shared with me secrets, drinks and football-related joys and sorrows). Thanks, dears, for all. Long and prosper life.

Conflicts of Interest:
The author declares no conflict of interest.