4.1. 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
, 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
is based on linear logic (linearity is extended to higher types), by distinguishing between duplicable and non-duplicable resources. The type system of
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: 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. 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
well-typed term, encoding the EPR circuit is
as
and has type
where
is the base type of qubits. The
constant behaves like the
constant used in
Section 2.3.
’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
. 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
.
The pure quantum lambda calculus
we employ in Example 1 is morally an heir of
, 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
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
(see Example 1); finally, subterms of the shape
, where
U is a constant representing a unitary operator and
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
two other sibling systems have been defined:
[
35], a sub-calculus of
intrinsically quantum polytime (where
soft linear logic is used as a basis for the w.f.r. set) and for
[
36] and extension of
with a partial measurement operator. Differently from
, in
, 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 (
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.
4.2. 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
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
, where
Q is the type of the qubits for a given
. The syntax allows building expressions such as
, where
is an amplitude and
t is a term or expressions like
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,
holds when
t and
u are “distinguishable in some way” [
39]: in other words, one can derive the judgement
from
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 ; the quantum conditional 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
and
. 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
and
below).
4.3.
Ross defines the first version of
in Reference [
49] (see also
Section 2.3, where we spend some word about its LL-based type system).
has been introduced as a ”bridge” between quantum lambda calculi
, to isolate a well-typed and safe core of the practical language. The syntax and the type system of Ross’
are inspired to
, 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
(where
T and
U represents the input-output set of wires) of circuits.
is type-safe (Subject Reduction and Progress Theorems hold) and allows a notion of subtyping similar to the one defined for
. The operational semantics of
is defined between configurations, as in
and
.
can be considered a quantum circuit description language, as
,
and
we describe in the following Sections. Differently from
,
and
,
is not Turing complete but expressive enough to be an interesting formal core of
. Another version of
called
-M has been introduced by Selinger and Rios in Reference [
30].
-M mainly focuses on denotational models (an aspect we did not address in this paper), so we remand to the original paper.
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
.
For a further insight on
-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
we introduce in the following section and the denotational model for a language similar to
based on enriched categories proposed by Staton and Renella in Reference [
52].
4.4.
(
“choir”) [
19,
21,
24,
53] is a powerful and flexible language for writing
verifired quantum programs. As
,
is based on the QRAM. The “quantum core” (called
circuit language) of
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
, a circuit can be “boxed” and then promoted as a classical resource/code).
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,
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 , is type-safe and supports both linear and dependent types. A strong type system guarantees the safety of generated circuits. In some sense, 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 it is designed for realistic computations.
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
.
4.5. and
In this section we describe two (stand-alone) functional languages called
and
respectively. See References [
20,
41] for the complete study of
and see Reference [
22] for the current version of
. Both
and
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,
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
and
can be foundational for concrete languages. In particular, as a medium time goal, we are proceeding with the implementation of the ALGOL-like language
.
4.5.1.
The language is based on a version of the QRAM model where measurements are all performed at the end of the computation. 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 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. types includes: the types of quantum circuits (where E that morally represents a circuit dimension), the type of indexes (i.e., strongly normalizing expressions) and the (standard) quantification over types .
The syntax of 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 where Y is the recursion operation, and . Given a term representing a circuit (of ariety ) , it is easy to observe that applied to and concatenates copies of .
The parallel composition of quantum circuit can be achieved by using the operator (that has type ).
Consider the program . When applied to a numeral and two unitary gates and , generates a circuit built upon a copy of gate in parallel with n copies of gate . Notice that the term is driven by an argument of type , to ensure that iteration is strong normalizing and, consequently, that the arity of the generated circuit is always a numeral.
makes especially convenient the programming of quantum algorithms in
deferred form, where measurements are all postponed at the end of the computation.
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
described in
Section 4.5.2.
4.5.2.
(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
. We exploited Idealized Algol features to provide a (as much as possible) minimal extension to capture higher-order circuit generation.
In enjoys a simple type theory: classical types (for natural numbers, command and classical variables) are extended with two new types.
The first one, , is the type of quantum circuits. Quantum circuits are classical data, so their type allows to operate on them without any special care. In all circuits/gates , of any dimension k, are typed with the unique circuit type . The second one, , 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 we use neither dependent types or linear typer for describing quantum circuits, to keep it as simple as possible.
As for , basic circuit manipulations (concatenation and parallelization) are easy encodable thanks to recursion and ad hoc operators denoted as ⦂ and ‖ respectively.
Evaluation in
, as in Idealized ALGOL, and in quantum languages such as References [
3,
8], is defined between pairs
, 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
, 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
, where
is expected to reduce to
.
The function returns the arity of a quantum register. The expression evaluates the application of the circuit to the quantum state stored in , then it stores the resulting state in .
Finally, measures qubits of a quantum state which stores (and, update such state, in accordance with the quantum measurement rules).
Formally, does not extend . However, such an extension is possible, thus we state that extends with classical and quantum stores. Moreover, since supports general measurement, the programmer does not necessarily encode algorithms in deferred form as, for .
4.5.3. Programming Quantum Algorithms: Three Higher-Order Examples
In this section, we use and 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 and , 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 , exploiting its partial measurement operator and the quantum store.
Example 2 (Deutsch-Jozsa Circuit in
)
. 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 which acts on many input bits: Given a classical input state of the form , the circuit returns a state that, once measured, reveals in the first bits if the function f is constant or balanced. If all 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 , unitary gates of arity are typed with the (dependent) type , where the dependency parameter in type is the numeral representation of the integer i. Moreover, the special type is reserved for strongly normalizing expressions that represent dimensions of operation on circuits, such as sequentialization and parallelization. Sequential composition of two circuits and (of th same arity k) is denoted as . The term put in parallel an arbitrary number of quantum gates of arbitrary ariety: for example, create a parallel composition of k copies of the gate V and a copy of the gate U.
Let and be the (unary) Hadamard and Identity gates respectively. Suppose is given for some n such that where is the -circuit that represents the the black-box function f having arity and represents the evaluation labelled with its probability (in this case, ).
The term generates parallel copies of Hadamard gates and concatenates in parallel x copies of Hadamard gates and one copy of the identity gate . 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 aswhere . The last phase is performed by the operator , the 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. is here suitably fed with the and . Notice that returns the Deutsch-Jozsa circuit of dimension for the function f among the infinite family.
The evaluation yields where is the result (with probability ).
We can make the term parametric also w.r.t. the sub-circuit represented by . It suffices to replace with the variable , to replace the black-box with a variable so that, the resulting term is typed or more simply (where is the usual type of integers).
Example 3 (Deutsch-Jozsa Circuit in
)
. We show how an)
term represents the infinite family of quantum programs that encode the Deutsch-Jozsa algorithm (Figure 2), as we have just done with . Let be the Hadamard gate and be the Identity gate. Notice that we “decorate”IQuconstants representing unitary operators with their arities and, as described in the previous section, all gates/circuits are typed with the ground type . We implement Deutsch-Jozsa in by sequentially composing the terms , and , where is expected to be substituted by the black-box circuit that implements the function f, while both and are defined in the coming lines.
Let be a term that applied to a circuit and to a numeral puts copies of in parallel. It is defined as where Y is the recursion operator, is the term whose type is with .
The circuit is obtained by feeding the term with two inputs: the (unary) Hadamard gate and the input dimension where r is a co-processor register with suitable dimension. It should be evident that it generates parallel copies of the gate .
The circuit can be defined as , that is, it is obtained by the parallel composition of the term fed by the gate and the dimension (generating n parallel copies of the gate ) and a single copy of the identity gate.
Fixed an arbitrary n, the generalization of Deutsch-Jozsa is obtained by using the quantum variable binder that makes the quantum variableravailable in P. The local variable declaration creates a quantum register which is fully initialized to 0. Since the expected input state of Deutsch-Jozsa circuit is , we define and use an initializing circuit that complements the last qubit, setting it to 1 ( is the standard predecessor function of PCF and extracts the size, that is, the numeber of quantum bits available in the register). Let be the circuit . The (parametric) encoding of the Deutsch-Jozsa algorithm can be defined as . 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 be a black-box closed circuit implementing the function f that we want to check and let be namely the circuit obtained by the substitution of to in . By means of the suitable evaluation rule of, we have where is the computational state after the evaluation of . To measure the state we use the operational rule for the constructor to conclude , where is the (deterministic) output of the measurement and 1 is the associated probability.
Example 4 (Simon’s algorithm in
)
. 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 (X finite) a black-box function. Determine the string such that if and only if or . 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 whole procedure can be easily encoded in , thanks to the partial measurement operator and the possibility to store intermediate quantum states.
Simon’s quantum subroutine sequentially composes , and , where is expected to be substituted by the black-box circuit that implements the function f (denoted as in the figure above). and are defined by letting where: (i) is the term that sequentializes an arbitrary number of copy the same gate (easily definable by the Y operator), (ii) is a quantum register; and, (iii) , are the unary Hadamard and Identity gates, respectively.
Let be the circuit . Let n be the arity of f we want to check. The program that implements Simon’s subroutine can be encoded as , where the abstracted variable will be replaced by a suitable encoding of the black-box function that implements f.
Let be the encoding of the circuit implementing f and let be , namely the circuit obtained by the substitution of for in .
The following evaluation respects the semantics:where is the state after the evaluation of the circuit . We can measure the first quantum bits as follows:, where
is one possible state after the partial measurement and α is the related probability. The classical output 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.
4.6. 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.