Applsci 09 05472 v2
Applsci 09 05472 v2
sciences
Article
Quantum Calculi—From Theory to Language Design
Margherita Zorzi
Department of Computer Science, University of Verona, 37100 Verona, Italy; [email protected]
Received: 31 August 2019; Accepted: 4 December 2019; Published: 12 December 2019
Abstract: 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 qPCFand IQu of the well
known Deutsch-Jozsa and Simon’s algorithms.
Keywords: quantum language design; quantum computing; programming theory
1. 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–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–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].
Classical Quantum
Computer Device
feedback
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 introduced—
oversimplifying 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
Appl. Sci. 2019, 9, 5472 3 of 17
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.
QTM oi / QCF
O
Q Language
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].
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)inhx, xi 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]:
[1, ∅, (λ!x.cnoth x, x i)!(new (1))].
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 7→ |φi).
The the quantum state | p 7→ 1i ⊗ |q 7→ 0i represents the output of the application of the controlled-not on
the state |10i (see Reference [9]).
Appl. Sci. 2019, 9, 5472 5 of 17
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:
[1, ∅, (λ!x.cnoth x, x i)!(new 1)] →new [| p 7→ 1i, { p}, (λ!x.cnoth x, x i)!( p)]
→q β [| p 7→ 1i, { p}, cnoth p, pi)].
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 Section 3 and References [20,41].
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.
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).
4.4. 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.
Appl. Sci. 2019, 9, 5472 9 of 17
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.
4.5.1. 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 Mseq = λucirc(k).λxNat .YWux : circ(k) → Nat → circ(k) : σ → σ where Y is the recursion
operation, W = λwσ .λucirc(k).λyNat . 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 Mseq applied to C
and n concatenates n + 1 copies of C.
The parallel composition of quantum circuit can be achieved by using the operator iter (that has
type ΠxIdx . circ(E0) → circ(E1) → circ(E0 + ((1 + E1 ) ∗ x))).
Consider the program Mpar = λxIdx .λucirc(k)λwcirc(h). iter x u w : ΠxIdx . circ(k) → circ(h) →
circ(k + (x ∗ (h + 1))). When applied to a numeral n and two unitary gates U1 : circ(k) and U2 : circ(h),
Mpar generates a circuit built upon a copy of gate U1 in parallel with n copies of gate U2 . 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.
Appl. Sci. 2019, 9, 5472 10 of 17
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.
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 k 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, |φi}, where r is the name of the register and |φi 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 qnewN x in M, where N is expected to reduce to k.
The function rsize returns the arity of a quantum register. The expression x C N evaluates the
application of the circuit N to the quantum state stored in x, then it stores the resulting state in x.
Finally, measN 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.
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
As for the previous two algorithms, we assume that access to the function f is restricted to
the circuit representing the Deutsch-Jozsa procedure in qPCF and IQu, to see at work the main
queries to a device corresponding to the transformation Bf defined similarly to before:
peculiarities of the languages and the different Bf |x⟩ |b⟩solutions
= |x⟩ |b ⊕ f (x)⟩we chose in the definition of the syntax,
the type and the reductionforsystems.
all x ∈ {0, 1}nFinally,
and b ∈ {0, 1}.we propose the encoding of the circuit family implementing
It turns out that classically this problem is pretty easy given a small number of queries if we
Simon’s quantum subroutine in IQu, exploiting its partial measurement operator and the quantum store.
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
Example 2 (Deutsch-Jozsa Circuit in qPCF). Figure 2 represents, up to the last phase (measurement of
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
the output state), the circuit implementing the well-known Deutsch-Josza algorithm (the generalization of the
probability of error is smaller than 1/1000. However, if you demand that the algorithm is correct
every time, then 2n−1 + 1 queries are needed in the worst n case.
Deutsch’s algorithm) [9], that considers a function f : {0, 1} → {0, 1} which acts on many input bits:
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:
|0⟩ H H M
|0⟩ H H M
Bf
|0⟩ H H M
|1⟩ H
❄
There are n bits resulting from the measurements. If all n measurement results are 0, we
Figure 2. Circuit representation of Deutsch-Jozsa algorithm.
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.
Given a classical inputWestate of the
have already form
observed that|for 011}iwe
0 .a .∈.{0, , the
have circuit returns a state that, once measured, reveals
in the first n − 1 bits if the function f is constant or1balanced. 1
H |a⟩ = √ |0⟩ + √ (−1)a |1⟩ ,
If all n − 1 measurement results are 0, we can
conclude that the function is constant. Otherwise, if at2 least 2one of the measurement outcomes is 1, we conclude
which we can also write as
that the function is balanced. 1 !
H |a⟩ = √ (−1)ab |b⟩ .
2 b∈{0,1}
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
4
for strongly normalizing expressions that represent dimensions of operation on circuits, such as sequentialization
and parallelization. Sequential composition of two circuits C1 and C2 (of th same arity k) is denoted as C1 ⦂ C2 .
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 MB f :
circ(n) is given for some n such that MB 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 λxIdx . iter xHH : ΠxIdx . circ(x) generates x + 1 parallel copies of Hadamard gates H
and λxIdx . iter xIH : ΠxIdx . 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
We can make the term parametric also w.r.t. the sub-circuit represented by MB f . It suffices to replace
n with the variable nIdx , to replace the black-box with a variable bcirc(n) so that, the resulting term is typed
ΠnIdx .Πbcirc(n).Nat or more simply ΠnIdx . 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 M1 , x and M3 , where x : circ is expected to be substituted by the black-box circuit that implements the
function f , while both M1 and M3 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 = λucirc .λkNat .YW1 uk : circ(→) Nat → circ, where Y is the recursion
operator, W1 is the term λwσ .λucirc .λkNat . if k (u) (u k (w u pred(k))) whose type is σ → σ with
σ = circ → Nat → circ.
• The circuit M1 : 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 M3 : circ can be defined as (M par H1 pred(rsize (r))) k Id1 : 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 Id1 of the identity gate.
Fixed an arbitrary n, the generalization of Deutsch-Jozsa is obtained by using the quantum variable binder
qnewn r in P that makes the quantum variable r available in P. The local variable declaration qnewn r in P
creates a quantum register which is fully initialized to 0. Since the expected input state of Deutsch-Jozsa circuit
. . 0} 1i, we define and use an initializing circuit Minit = (M par Id 1 (pred(rsize (r )))) k Not 1 : circ
is |0| .{z
n
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
Minit ⦂ M1 ⦂ x ⦂ M3 . The (parametric) IQu encoding of the Deutsch-Jozsa algorithm can be defined as
λxcirc . qnew n+1 r in ((r C DJ+ ); measn 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 MB f be a black-box closed circuit implementing the function f that we want to check and let DJ? be
DJ [MB f /x] namely the circuit obtained by the substitution of MB f to x in DJ+ . By means of the suitable
+
evaluation rule of IQu, we have {(r, |0 . . . 0i)}, r C DJ? ⇓ 1 {(r, |φi)}, skip where |φi is the computational
| {z }
n
state after the evaluation of DJ? . To measure the state |φi we use the operational rule for the constructor measn r
to conclude {r, |φi}, measn r ⇓ 1 {r, |φ0 i}, 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 = s1 s2 . . . sk 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.
Appl. Sci. 2019, 9, 5472 13 of 17
The whole procedure can be easily encoded in IQu, thanks to the partial measurement operator and the
possibility to store intermediate quantum states.
Simon’s quantum subroutine sequentially composes M1 , x and M3 , where x : cırc is expected to be
substituted by the black-box circuit that implements the function f (denoted as B f in the figure above). M1 and
M3 are defined by letting M1 = M3 = (M par (H 1 ) rsize (r)) k (M par (Id 1 ) rsize (r)) : cırc where: (i) M par
is the term that sequentializes an arbitrary number of copy the same gate (easily definable by the Y operator), (ii)
r is a quantum register; and, (iii) H 1 : cırc, Id 1 : cırc are the unary Hadamard and Identity gates, respectively.
Let MSP + be the circuit M1 ⦂ x ⦂ M3 : cırc . Let n be the arity of f we want to check. The program that
implements Simon’s subroutine can be encoded as λxcırc . qnew 2∗n r in ((r C MSP + ); measn r), where the
abstracted variable x : cırc will be replaced by a suitable encoding of the black-box function that implements f .
Let MB f : cırc be the encoding of the circuit implementing f and let MSP ? be MSP + [MB f /x], namely the
circuit obtained by the substitution of MB f for x in MSP + .
The following evaluation respects the IQu semantics:
where |φi is the state after the evaluation of the circuit MSP ? . We can measure the first n quantum bits as
follows: {(r, |φi)}, measn r ⇓ α {(r, |φ0 i)}, k, where φ0 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.
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.
5. 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.
References
1. LaRose, R. Overview and Comparison of Gate Level Quantum Software Platforms. Quantum 2019, 3, 1–24.
[CrossRef]
2. Sanders, J.W.; Zuliani, P. Quantum Programming. In Proceedings of the 5th International Conference on
Mathematics of Program Construction—MPC 2000, Ponte de Lima, Portugal, 3–5 July 2000; Lecture Notes
in Computer Science; Backhouse, R.C., Oliveira, J.N., Eds.; Springer: Berlin/Heidelberg, Germany, 2000,
Volume 1837, pp. 80–99. doi:10.1007/10722010\_6. [CrossRef]
3. Selinger, P.; Valiron, B. A lambda calculus for quantum computation with classical control. Math. Struct.
Comput. Sci. 2006, 16, 527–552. doi:10.1017/S0960129506005238. [CrossRef]
4. Altenkirch, T.; Grattage, J. A Functional Quantum Programming Language. In Proceedings of the 20th IEEE
Symposium on Logic in Computer Science (LICS 2005), Chicago, IL, USA, 26–29 June 2005; pp. 249–258.
doi:10.1109/LICS.2005.1. [CrossRef]
5. Danos, V.; Kashefi, E.; Panangaden, P. The Measurement Calculus. J. ACM 2007, 54. doi:10.1145/1219092.1219096.
[CrossRef]
6. Díaz-Caro, A.; Arrighi, P.; Gadella, M.; Grattage, J. Measurements and Confluence in Quantum Lambda
Calculi With Explicit Qubits. Electr. Notes Theor. Comput. Sci. 2011, 270, 59–74. doi:10.1016/j.entcs.2011.01.006.
[CrossRef]
7. Green, A.S.; Lumsdaine, P.L.; Ross, N.J.; Selinger, P.; Valiron, B. Quipper: A Scalable Quantum Programming
Language. In Proceedings of the 34th ACM SIGPLAN Conference on Programming Language Design
and Implementation, Seattle, WA, USA, 16–19 June 2013; ACM: New York, NY, USA, 2013; pp. 333–342.
doi:10.1145/2491956.2462177. [CrossRef]
8. Zorzi, M. On quantum lambda calculi: a foundational perspective. Math. Struct. Comput. Sci. 2016,
26, 1107–1195. doi:10.1017/S0960129514000425. [CrossRef]
9. Nielsen, M.A.; Chuang, I.L. Quantum Computation and Quantum Information, 10th Anniversary ed.; Cambridge
University Press: Cambridge, UK, 2010; pp. xxvi+676. doi:10.1017/CBO9780511976667. [CrossRef]
10. Masini, A.; Viganò, L.; Zorzi, M. Modal Deduction Systems for Quantum State Transformations.
Multiple-Valu. Logic Soft Comput. 2011, 17, 475–519.
11. Viganò, L.; Volpe, M.; Zorzi, M. Quantum state transformations and branching distributed temporal logic.
In Logic, Language, Information, and Computation, Proceedings of the 21st International Workshop, WoLLIC 2014,
Valparaíso, Chile, 1–4 September 2014; Lecture Notes in Computer Science 8652; Springer: Berlin/Heidelberg,
Germany, 2014; pp. 1–19. doi:10.1007/978-3-662-44145-9\_1. [CrossRef]
12. Viganò, L.; Volpe, M.; Zorzi, M. A branching distributed temporal logic for reasoning about entanglement-free
quantum state transformations. Inf. Comput. 2017, 255, 311–333. doi:10.1016/j.ic.2017.01.007. [CrossRef]
13. Masini, A.; Zorzi, M. A Logic for Quantum Register Measurements. Axioms 2019, 8, 25.
doi:10.3390/axioms8010025. [CrossRef]
14. Nakahara, M.; Ohmi, T. Quantum Computing—From Linear Algebra to Physical Realizations; CRC Press:
Boca Raton, FL, USA, 2008.
15. Roman, S. Advanced Linear Algebra, 3rd ed.; Graduate Texts in Mathematics; Springer: New York, NY, USA,
2008; Volume 135, pp. xviii+522.
16. Selinger, P. Towards a Quantum Programming Language. Math. Struct. Comput. Sci. 2004, 14, 527–586.
doi:10.1017/S0960129504004256. [CrossRef]
17. Knill, E. Conventions for Quantum Pseudocode; Technical Report; Los Alamos National Laboratory: Los Alamos,
NM, USA, 1996.
18. Nishimura, H.; Ozawa, M. Perfect computational equivalence between quantum Turing machines and finitely
generated uniform quantum circuit families. Quant. Inf. Process. 2009, 8, 13–24. doi:10.1007/s11128-008-0091-8.
[CrossRef]
19. Rand, R. Formally Verified Quantum Programming. Ph.D. Thesis, University of Pennsylvania, Philadelphia,
PA, USA, 2018. Available online: http://www.cis.upenn.edu/~rrand/thesis.pdf (accessed on 1 June 2019).
20. Paolini, L.; Zorzi, M. qPCF: A language for quantum circuit computations. In Theory and Applications of
Models of Computation; Lecture Notes in Computer Science; Springer: Berlin/Heidelberg, Germany, 2017;
Volume 10185, pp. 455–469. doi:10.1007/978-3-319-55911-7\_33. [CrossRef]
Appl. Sci. 2019, 9, 5472 16 of 17
21. Paykin, J.; Rand, R.; Zdancewic, S. QWIRE: A Core Language for Quantum Circuits. In Proceedings of the
44th ACM SIGPLAN Symposium on Principles of Programming Languages, Paris, France, 15–21 January
2017; ACM: New York, NY, USA, 2017; pp. 846–858. doi:10.1145/3009837.3009894. [CrossRef]
22. Paolini, L.; Roversi, L.; Zorzi, M. Quantum programming made easy. In Proceedings of the Joint International
Workshop on Linearity & Trends in Linear Logic and Applications, Linearity-TLLA@FLoC 2018, Oxford,
UK, 7–8 July 2018; EPTCS; Ehrhard, T., Fernández, M., de Paiva, V., de Falco, L.T., Eds.; 2018; Volume 292,
pp. 133–147, Open Publishing Association, Waterloo, Australia . doi:10.4204/EPTCS.292.8. [CrossRef]
23. Valiron, B.; Ross, N.J.; Selinger, P.; Alexander, D.S.; Smith, J.M. Programming the Quantum Future.
Commun. ACM 2015, 58, 52–61. doi:10.1145/2699415. [CrossRef]
24. Rand, R.; Paykin, J.; Zdancewic, S. QWIRE Practice: Formal Verification of Quantum Circuits in
Coq. In Proceedings of the 14th International Conference on Quantum Physics and Logic, Nijmegen,
The Netherlands, 3–7 July 2017; Volume 266, pp. 119–132. doi:10.4204/EPTCS.266.8. [CrossRef]
25. Q# Reference Page, Technical Report, Microsoft. Available online: https://docs.microsoft.com/en-us/
quantum/language/?view=qsharp-preview (accessed on 1st June, 2019).
26. Vaux, L. The algebraic lambda calculus. Math. Struct. Comput. Sci. 2009, 19, 1029–1059.
doi:10.1017/S0960129509990089. [CrossRef]
27. Arrighi, P.; Díaz-Caro, A. Scalar System F for Linear-Algebraic Lambda-Calculus: Towards a Quantum
Physical Logic. Log. Methods Comput. Sci. 2012, 8. doi:10.2168/LMCS-8(1:11)2012. [CrossRef]
28. Ying, M. Foundations of Quantum Programming; Morgan Kaufmann: Burlington, MA, USA, 2016.
29. Sabry, A.; Valiron, B.; Vizzotto, J.K. From Symmetric Pattern-Matching to Quantum Control. In Foundations
of Software Science and Computation Structures; Baier, C., Dal Lago, U., Eds.; Springer International Publishing:
Cham, Switzerland, 2018; pp. 348–364.
30. Rios, F.; Selinger, P. A Categorical Model for a Quantum Circuit Description Language. In Proceedings of the
14th International Conference on Quantum Physics and Logic, Nijmegen, The Netherlands, 3–7 July 2017;
Open Publishing Association, Waterloo, Australia, 2018; Volume 266, pp. 164–178. doi:10.4204/EPTCS.266.11.
[CrossRef]
31. Quipper Reference Page; Technical Report. Available online: https://www.mathstat.dal.ca/~selinger/
quipper/ (accessed on 1 June 2019).
32. Siddiqui, S.; Mohammed Jahirul Islam, O.S. Five Quantum Algorithms Using Quipper; Technical Report;
Shahjalal University of Science and Technology: Sylhet, Bangladesh; University of Maryland: Baltimore
County, MD, USA, 2014.
33. Park, J.L. The concept of transition in quantum mechanics. Found. Phys. 1970, 1, 23–33. doi:10.1007/BF00708652.
[CrossRef]
34. Dal Lago, U.; Masini, A.; Zorzi, M. On a Measurement-free Quantum Lambda Calculus with Classical
Control. Math. Struct. Comput. Sci. 2009, 19, 297–335. doi:10.1017/S096012950800741X. [CrossRef]
35. Dal Lago, U.; Masini, A.; Zorzi, M. Quantum implicit computational complexity. Theor. Comput. Sci. 2010,
411, 377–409. doi:10.1016/j.tcs.2009.07.045. [CrossRef]
36. Dal Lago, U.; Masini, A.; Zorzi, M. Confluence Results for a Quantum Lambda Calculus with Measurements.
Electr. Notes Theor. Comput. Sci. 2011, 270, 251–261. doi:10.1016/j.entcs.2011.01.035. [CrossRef]
37. Pagani, M.; Selinger, P.; Valiron, B. Applying quantitative semantics to higher-order quantum
computing. In Proceedings of the POPL ’14, San Diego, CA, USA, 22–24 January 2014; pp. 647–658.
doi:10.1145/2535838.2535879. [CrossRef]
38. Dal Lago, U.; Zorzi, M. Wave-Style Token Machines and Quantum Lambda Calculi. In Proceedings of the
Third International Workshop on Linearity—LINEARITY 2014, Vienna, Austria, 13 July 2014; Electronic
Proceedings in Theoretical Computer Science 176; Open Publishing Association: Waterloo, Australia, 2014;
pp. 64–78. doi:10.4204/EPTCS.176.6. [CrossRef]
39. Grattage, J. QML: A Functional Quantum Programming Language. Ph.D. Thesis, University of Nottingham,
Nottingham, UK, 2006.
40. O’Hearn, P.W. Algol-like Languages; Progress in Theoretical Computer Science; Birkhäuser: Basel, Switzerland.
41. Paolini, L.; Piccolo, M.; Zorzi, M. QPCF: Higher-Order Languages and Quantum Circuits. J. Automat. Reason.
2019. doi:10.1007/s10817-019-09518-y. [CrossRef]
Appl. Sci. 2019, 9, 5472 17 of 17
42. Green, A.S.; Lumsdaine, P.L.; Ross, N.J.; Selinger, P.; Valiron, B. An Introduction to Quantum Programming in
Quipper. In Proceedings of the 5th International Conference on Reversible Computation, Victoria, BC, Canada,
4–5 July 2013; Springer: Berlin/Heidelberg, Germany, 2013; pp. 110–124. [CrossRef]
43. Selinger, P.; Valiron, B. On a Fully Abstract Model for a Quantum Linear Functional Language: (Extended
Abstract). Electr. Notes Theor. Comput. Sci. 2008, 210, 123–137. doi:10.1016/j.entcs.2008.04.022. [CrossRef]
44. Makie, I.; Gay, S., Eds. Semantic Techniques in Quantum Computation; Cambridge University Press: Cambridge,
UK, 2009. doi:10.1017/CBO9781139193313. [CrossRef]
45. Hasuo, I.; Hoshino, N. Semantics of higher-order quantum computation via geometry of interaction.
In Proceedings of the LICS’11, IEEE Computer Society, Washington, DC, USA, 21–24 June 2011; pp. 237–246.
46. Abramsky, S.; Haghverdi, E.; Scott, P.J. Geometry of Interaction and Linear Combinatory Algebras.
Math. Struct. Comput. Sci. 2002, 12, 625–665. doi:10.1017/S0960129502003730. [CrossRef]
47. Altenkirch, T.; Grattage, J.; Vizzotto, J.K.; Sabry, A. An Algebra of Pure Quantum Programming.
Electron. Notes Theoret. Comput. Sci. 2007, 170, 23–47. [CrossRef]
48. Grattage, J. An Overview of QML With a Concrete Implementation in Haskell. Electr. Notes Theor. Comput. Sci.
2011, 270, 165–174. doi:10.1016/j.entcs.2011.01.015. [CrossRef]
49. Ross, N.J. Algebraic and Logical Methods in Quantum Computation. Ph.D. Thesis, Department of
Mathematics and Statistics, Dalhousie University, Halifax, NS, Camada, 2015.
50. Mahmoud, M.Y.; Felty, A.P. Formalization of Metatheory of the Quipper Quantum Programming Language
in a Linear Logic. J. Autom. Reason. 2019, 63, 967–1002. doi:10.1007/s10817-019-09527-x. [CrossRef]
51. Lindenhovius, B.; Mislove, M.W.; Zamdzhiev, V. Enriching a Linear/Non-linear Lambda Calculus:
A Programming Language for String Diagrams. arXiv 2018, arXiv:1804.09822.
52. Rennela, M.; Staton, S. Classical Control and Quantum Circuits in Enriched Category Theory. Electron. Notes
Theoret. Comput. Sci. 2018, 336, 257–279. doi:10.1016/j.entcs.2018.03.027. [CrossRef]
53. Rand, R.; Paykin, J.; Lee, D.H.; Zdancewic, S. Reqwire: Reasoning about reversible quantum circuits.
In Proceedings of the 15th International Conference on Quantum Physics and Logic—QPL 2018, Dalhousie
University, Halifax, NS, Canada, 3–7 June 2018; Volume 287, pp. 299–312. [CrossRef]
54. Simon, D.R. On the Power of Quantum Computation. SIAM J. Comput. 1994, 26, 116–123. [CrossRef]
55. Arora, S.; Barak, B. Computational Complexity: A Modern Approach, 1st ed.; Cambridge University Press:
New York, NY, USA, 2009. doi:10.1017/CBO9780511804090. [CrossRef]
56. Kaye, P.; Laflamme, R.; Mosca, M. An Introduction to Quantum Computing; Oxford University Press: Oxford,
UK, 2007; p. xii+274.
57. Omer, B. Structured Quantum Programming. Ph.D. Thesis, Vienna University of Technology, Wien,
Austria, 2003.
58. Bettelli, S.; Serafini, L.; Calarco, T. Toward an architecture for quantum programming. arXiv 2001, arXiv:cs/0103009.
59. Nielsen, M. Universal quantum computation using only projective measurement, quantum memory, and
preparation of the 0 state. Phys. Lett. 2003, 308, 96–100. [CrossRef]
60. Clairambault, P.; De Visme, M.; Winskel, G. Game Semantics for Quantum Programming. Proc. ACM
Program. Lang. 2019, 3, 32:1–32:29. doi:10.1145/3290345. [CrossRef]
61. Preskill, J. Quantum Computing in the NISQ era and beyond. Quantum 2018, 79. doi:10.22331/q-2018-08-06-79.
[CrossRef]
62. Baltag, A.; Smets, S. Quantum logic as a dynamic logic. Synthese 2011, 179, 285–306. [CrossRef]
63. Ying, M.; Ying, S.; Wu, X. Invariants of quantum programs: Characterisations and generation. In Proceedings
of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages, POPL 2017, Paris, France,
18–20 January 2017; Castagna, G., Gordon, A.D., Eds.; ACM: New York, NY, USA, 2017; pp. 818–832.
[CrossRef]
64. Amy, M. Towards large-scale functional verification of universal quantum circuits. In Proceedings of the
15th International Conference on Quantum Physics and Logic, QPL 2018, Dalhousie University, Halifax, NS,
Canada, 3–7 June 2018; Volume 287, pp. 1–21. [CrossRef]
c 2019 by the author. Licensee MDPI, Basel, Switzerland. This article is an open access
article distributed under the terms and conditions of the Creative Commons Attribution
(CC BY) license (http://creativecommons.org/licenses/by/4.0/).