You are on page 1of 51

Typing quantum superpositions and

measurement

Alejandro Daz-Caro1 and Gilles Dowek2


1
Universidad Nacional de Quilmes & CONICET, Bernal, Buenos Aires, Argentina
alejandro.diaz-caro@unq.edu.ar
2
Inria, LSV, ENS Paris-Saclay, Cachan, France
gilles.dowek@ens-paris-saclay.fr
arXiv:1601.04294v6 [cs.LO] 6 Aug 2017

Abstract. We propose a way to unify two approaches of non-cloning


in quantum lambda-calculi. The first approach is to forbid duplicating
variables, while the second is to consider all lambda-terms as algebraic-
linear functions. We illustrate this idea by defining a quantum extension
of first-order simply-typed lambda-calculus, where the type is linear on
superposition, while allows cloning base vectors. In addition, we provide
an interpretation of the calculus where superposed types are interpreted
as vector spaces and non-superposed types as their basis.

1 Introduction

In -calculus, applying the term x (x x), that expresses a non-linear function


for some convenient definition of , to a term u yields the term (x (x x))u,
that reduces to u u. But cloning this vector u is forbidden in quantum
computing. Various quantum -calculi address this problem in different ways.
One way is to forbid the construction of the term x (x x) using a typing
system inspired from linear logic [1, 9], leading to logic-linear calculi [2, 10, 13,
15, 17]. Another is to consider all -terms expressing linear functions. The term
x (x x), for instance, expresses the linear function that maps |0i to |0i |0i
and |1i to |1i |1i3 . This leads to restrict beta-reduction to the case where
u is a base vector (in the computational basis) and to add the linearity rule
f (u + v) (f u + f v), leading to algebraic-linear calculi [36, 8].
Each solution has its advantages and drawbacks. For example, let t?uv be
the conditional statement on |0i and |1i. Interpreting -terms as algebraic-
linear functions permits to reduce the term (x x?|0i|1i)(. |0i + . |1i) to
(.(x x?|0i|1i)|0i + .(x x?|0i|1i)|1i) then to (. |1i + . |0i), instead of re-
ducing it to the term (. |0i + . |1i)?|0i|1i that would be blocked. This explains
that this linearity rule, that is systematic in the algebraic-linear languages cited
above, is also present for the condition in [2] (the so-called if operator).

Partially funded by the STIC-AmSud Project 16STIC05 FoQCoSS and PICT 2015
1208.
3
Where |xi is the Dirac notation for vectors, with |0i = 10 C2 and |1i = 01 C2 ,
 

so {|0i , |1i} is an orthonormal basis of C2 , called here the computational basis.


2 Alejandro Daz-Caro and Gilles Dowek

However, interpreting all -terms as linear functions forbids to extend the


calculus with non-linear operators, such as measurement. For instance, the term
(x x)(|0i+|1i), where represents a measurement in the computational basis,
would reduce to ((x x) |0i + (x x) |1i), while it should reduce to |0i with
probability 12 and to |1i with probability 21 .
In this paper, we propose a way to unify the two approaches, distinguishing
duplicable and non-duplicable data by their type, like in the logic-linear calculi;
and interpreting -terms as linear functions, like in the algebraic-linear calculi,
when they expect duplicable data. We illustrate this idea with an example of
such a calculus.
In this calculus, a qubit has type B when it is in the computational basis,
hence duplicable (a non-linear term in the sense of linear logic), and S(B) when
it is a superposition, hence non-duplicable (a linear term in the sense of linear
logic). Hence, the term |0i(|0i+|1i) has type BS(B). Giving this type to this
term and the type S(BB) to the term (|0i |0i+|0i |1i) however jeopardizes
the subject reduction property as, using the bilinearity of the product, the former
should develop to the latter. This dilemma is not specific to quantum computing
as computing is often a non-reversible process where some information is lost.
For instance, if we express, in its type, that the term (X 1)(X 2) is a product
of two polynomials, developing it to X 2 3X + 2 does not preserve this type. A
solution is to introduce, in the language, an explicit cast. For example, from the
type of tensor products to the type of arbitrary vectors. The term |0i (|0i+ |1i)
then has type BS(B) and it cannot be reduced. But the term (|0i(|0i+|1i))
has type S(B B) and can be developed to (|0i |0i + |0i |1i).
This language permits expressing quantum algorithms with a very precise
information about the nature of the data processed by these algorithms.

Outline of the paper In Section 2 we introduce the calculus, without tensor.


In Section 3 we extend the language with a tensor operator for multiple-qubits
systems, and state the Subject Reduction property of the resulting system. In
Section 5 we provide a straightforward interpretation of the calculus considering
base types as sets of vectors, and types S() as vector spaces. In Section 6 we
express two non-trivial example in our calculus: the Deutsch algorithm and the
Teleportation algorithm, demonstrating the expressivity of the proposed lan-
guage. Finally, in Section 7, we conclude. There are also five appendices: Ap-
pendix A gives a quick introduction to quantum computing. Appendix B have
the detailed proofs of Subject Reduction (Section 4), Appendix C have the de-
tailed proofs of the Interpretation (Section 5), Appendices D and E have more
details of the examples given in Section 6.

2 No cloning, superpositions and measurement


The grammar of types and terms is defined as follows, with C.

:= B | S( ) Qubit types ( )
Typing quantum superpositions and measurement 3

A := | A | S(A) Types (T )
b := x | x : t | |0i | |1i Base terms (B)
v := b | (v + v) | ~0S(A) | .v Values (V)
t := v | tt | (t + t) | t | ? | .t Terms ()
Terms are variables, abstractions, applications, two constants for base qubits
(|0i and |1i), linear combinations of terms (built with addition and product by
a scalar, addition being commutative and associative), a family of constants for
the null vectors, one for each type of the form S(A), (~0S(A) ), and an if-then-
else construction (?) deciding on base vectors. We also include a symbol for
measurement in the computational basis.
The grammar is split into base terms (non-superposed values), general values,
and general terms. Types are also split into qubit types and general types.
The set of free variables of a term t is defined as usual in -calculus and
denoted by F V (t). We use [.]t as a notation to refer indistinctly to .t and
to t. We use t as a shorthand notation for 1.t, and (t r) as a shorthand
notation for (t + (r)). The term (t t) has type S(A), and reduces to ~0S(A) ,
which is not a base term.
An important property of this calculus is that types S() are linear types.
Indeed, those correspond to superpositions, and so no duplication is allowed on
them. Instead, at this tensor-free stage, a type without an S() on head posi-
tion is a non-linear type, such as B, which correspond to base terms, i.e. terms
that can be cloned. A non-linear function is allowed to be applied to a lin-
ear argument, for example, x : B (f xx) can be applied to ( 12 . |0i + 12 . |1i),
however, it distributes in the following way: (x : B (f xx)) ( 12 . |0i+ 12 . |1i)
( 12 .(x : B (f xx)) |0i+ 12 .(x : B (f xx)) |1i) ( 12 .(f |0i |0i)+ 12 .(f |1i |1i)).
Hence, the beta reduction occurs only when the type of the argument is the
same as the type expected by the abstraction. Thus, the rewrite system depends
on types. For this reason, we describe first the type system, and only then the
rewrite system.
A type A will be interpreted as a set of vectors and S(A) as the vector space
generated by the span of such a set (cf. Section 5). Hence, we naturally have
A S(A) and S(S(A)) = S(A). Therefore, we also define a subtyping relation
on types. The type system and the subtyping relation are given in Table 1, where
contexts and have a disjoint support.
Remarks: Rule Ax allows typing variables only with qubit types. Hence, the
system is first-order and only qubits can be passed as arguments (more when
the rewrite system is presented). Rule Ax~0 types the null vector as a non-base
term, because the null vector cannot belong to the base of any vector space.
Rules Ax|0i and Ax|1i type the base qubits with the base type B.
Thanks to rule  the term |0i has type B and also the more general type
S(B). Note that ((|0i + |0i) |0i) has type S(B) and reduces to |0i that has the
same type S(B). Reducing this term to |0i of type B would not preserve its type.
Moreover, this type would contain information impossible to compute, because
the value |0i is not the result of a measurement, but of an interference.
4 Alejandro Daz-Caro and Gilles Dowek

AB AB
A  S(A) S(S(A))  S(A) A B S(A)  S(B)
Ax Ax~0 Ax|0i Ax|1i
x: x: ~0S(A) : S(A) |0i : B |1i : B
t:A t:A u:A + t : S(B)
SI S SE
.t : S(A) , (t + u) : S(A) I t : B
t : A (AB) , x : t : A
 If I
t:B ? : B B B B x : t : A
t: A u: t : S( A) u : S( )
E ES
, tu : A , tu : S(A)
t:A , x : B, y : B t : A
W C
, x : B t : A , x : B (x/y)t : A

Table 1. Subtyping relation and type system

Rule SI states that a term multiplied by a scalar is not a base term. Even if
the scalar is just a phase, we must type the term with an S() type, because our
measurement operator removes the scalars, so having the scalar means that it
has not been measured yet. Rule SI+ is the analog for sums to the previous rule.
Rule SE is the elimination of the superposition, which is achieved by measuring
(using the operator).
We use r?st as a notation for (?)rst. Notice that it is typed as a non-linear
function by rule If, and so, the if-then-else linearly distributes over superposi-
tions.
Rule ES is the elimination for superpositions, corresponding to the linear
distribution. Notice that the type of the argument is a superposition of the
argument expected by the abstraction (S( ) vs. ). Also, the abstraction is
allowed to be a superposition. If, for example, we want to apply the sum of
functions (f + g) to the base argument |0i, we would obtain the superposition
(f |0i + g |0i). The typing is as follows:

Ax|0i
f :BA g:BA + |0i : B
SI 
(f + g) : S(B A) |0i : S(B)
ES
(f + g) |0i : S(A)

which reduces to

Ax|0i Ax|0i
f : B A |0i : B g : B A |0i : B
E E
f |0i : A g |0i : A +
SI
(f |0i + g |0i) : S(A)
Typing quantum superpositions and measurement 5

Similarly, a linear function ( f : B A) applied to a superposition (|0i+|1i)


reduces to a superposition (f |0i + f |1i). The typing is as follows:

Ax|0i Ax|1i
f :BA |0i : B |1i : B +
 SI
f : S(B A) (|0i + |1i) : S(B)
ES
f (|0i + |1i) : S(A)

which reduces to
Ax|0i Ax|1i
f : B A |0i : B f : B A |1i : B
E E
f |0i : A f |1i : A +
SI
(f |0i + f |1i) : S(A)

Finally, Rules W and C correspond to weakening and contraction on variables


with base types. The rationale is that base terms can be cloned.
The rewrite
Pn system is given in Table 2, where, in rule (proj), i, bi = |0i or
bi = |1i, i=1 i .bi is normal (so 1 n 2), if an k is absent, |k |2 = 1, and
1 k n.

If b has type B and b B, then (~0S(A) + t) (1) t (neutral)


(x : B t)b (1) (b/x)t (b ) 1.t (1) t (unit)
Beta

Vector space axioms


If u has type S( ), then If t has type A, then
(x : S( ) t)u (1) (u/x)t (n ) 0.t (1) ~0S(A) (zero )
|1i?uv (1) u (if1 ) .0S(A) (1) ~0S(A)
~ (zero)
If

|0i?uv (1) v (if0 ) .(.t) (1) ( ).t (prod)


If t has type B A, then .(t + u) (1) (.t + .u) (dist)
t(u + v) (1) (tu + tv) (lin+ r ) (.t + .t) (1) ( + ).t (fact)
Linear distribution

If t has type B A then (.t + t) (1) ( + 1).t (fact1 )


t(.u) (1) .tu (lin
r ) (t + t) (1) 2.t (fact2 )
If t has type B A, then (u + v) =AC (v + u) (comm)
=

t~0S(B) (1) ~0S(A) (lin0r ) ((u + v) + w) =AC (u + (v + w)) (assoc)


n
(t + u)v (1) (tv + uv) (lin+
Projection

l )
X
(.t)u (1) .tu (lin ) ( [i .]bi ) (p) bk (proj)
l
i=1 2
~0S(BA) t (1) ~0S(A) (lin0l ) with p = Pn|k||
2
i=1 i|
t (p) u t (p) u
tv (p) uv (x : B v)t (p) (x : B v)u
t (p) u t (p) u t (p) u
t + v (p) u + v .t (p) u t (p) u

Table 2. Rewrite system

The relation (p) is a probabilistic relation where p is the probability of


occurrence. Every rewrite rule has a probability 1 of occurrence, except for the
6 Alejandro Daz-Caro and Gilles Dowek

projection ((proj) rule). The rewrite system depends on the typing, in particular
an abstraction can either expect a base term as argument (that is, a non-linear
term) or a superposition, which has to be treated linearly. However, an abstrac-
tion expecting a non-linear argument can be given a superposition (which is lin-
ear), and it is typable, only that the reduction distributes before beta-reduction.
There are two beta rules. Rule (b ) acts only when the argument is a base
term, and the type expected by the abstraction is a base type. Hence, rule (b )
is call-by-base (base terms coincides with values of -calculus, while values
on this calculus also includes superpositions of base terms and the null vector).
Instead, (n ) is the usual call-by-name beta rule. They are distinguished by the
type of the argument. Rule (b ) acts on non-linear functions while (n ) is for
linear functions. The test on the type of the argument is due to the type system
that allows an argument with a type not matching with the type expected by
the abstraction (in such a case, one of the linear distribution rules applies).
Since there are two beta reductions, the contextual rule admitting reducing
the argument on an application is valid only when the abstraction expects an
argument of type B. If the argument is typed with a base type, then it reduces
to a term that can be cloned, and we must reduce it first to ensure that we are
cloning a term that can be cloned. For example, a measure over a superposition
(e.g. (|0i + |1i)) has a base type B, but it cannot be cloned until it is reduced.
Indeed, (x : B (f xx))(|0i + |1i) can reduce either to f |0i |0i or f |1i |1i, but
never to f |0i |1i or f |1i |0i, which would be possible only if the measure happens
after the cloning machine.
The group If-then-else contains the tests over the base qubits |0i and |1i.
The first three of the linear distribution rules (those marked with subindex
r), are the rules that are used when a non-linear abstraction is applied to a
linear argument (that is, when an abstraction expecting a base term is given a
superposition). In these cases the beta reductions cannot be used since the side
conditions on types are not met. Hence, these distributivity rules apply instead.
For example, let us give more details in the reduction sequence on the example
given at the beginning of this Section.
1 1
(x : B (f xx))( . |0i + . |1i)
2 2
+
(linr ) 1 1
(1) ((x : B (f xx)) . |0i + (x : B (f xx)) . |1i)
2 2
(lin
r )
2 1 1
(1) ( .(x : B (f xx)) |0i + .(x : B (f xx)) |1i)
2 2
( ) 2 1 1
b (1) ( .f |0i |0i + .f |1i |1i)
2 2
The remaining rules in this group deal with a superposition of functions. For
example, rule (lin+
l ) is the sum of functions: A superposition is a sum, therefore,
if an argument is given to a sum of functions, it needs to be given to each
function in the sum. We use a weak reduction strategy (i.e. reduction occurs
only on closed terms), hence the argument v on this rule is closed, otherwise, it
Typing quantum superpositions and measurement 7

could not be typed. For example x : S(B), t : B B, u : B B (t + u)x : S(B)


is derivable, but x : S(B), t : B B, u : B B (tx + ux) : S(B) is not.
The vector space axioms rules are the directed axioms of vector spaces [5, 6].
The Modulo AC rules are not proper rewrite rules, but express that we consider
the symbol + to be associative and commutative, and hence our rewrite system
is rewrite modulo AC [14].
Finally, rule (proj) is the projection over weighted associative pairs, that
is, the projection over a generalization of multisets where the multiplicities are
given by complex numbers. This reduction rule is the only one with a probability
different from 1, and it is given by the square of the modulus of the weights4 ,
implementing this way the quantum measurement over the computational basis.
Remark, to conclude, that this calculus can represent only pure states, and
not mixed states. For example, let Z be an encoding for the quantum Z gate
(cf. Section 6), |+i = 12 .(|0i + |1i), and |i = 12 .(|0i |1i). The terms (x :
S(B) (y : B y?(Zx)x)( |+i)) |+i and (x : S(B) (x)) |+i may be considered
equivalent if taking into account the density matrix representation of mixed
states. Indeed, the first reduces either to |+i or |i, with probability 12 each,
while the second reduces to |0i or to |1i, with probability 21 each. The sets of
pure states {( 21 , |+i), ( 12 , |i)} and {( 21 , |0i), ( 21 , |1i)} have both density matrix
I
2 , and hence are indistinguishable. However, once the result of the measure is
known, the pure states can be distinguished.

3 Multi-qubit systems: Tensor products

A multi-qubit system is represented with the tensor product between single-


qubit Hilbert spaces. The tensor product of base terms can be seen as an ordered
list. Hence, we represent the tensor product as a conjunction-like operator. The
distributivity of linear combinations over tensor products is not trivially tracked
in the type system, and so an explicit cast between types is also added.
Each level in the term grammar (base terms, values and general terms) is
extended with the tensor of the terms in such a level. The primitives head and
tail are added to the general terms. The projector is generalized to j , where
the subindex j stands for the number of qubits to be measured, which are those
in the first j positions. Notice that it is always possible to do a swap between
qubits and so place the qubits to be measured at the beginning. For instance,
x : B B (tail x head x).
An explicit type cast of a term t (S(BC)
S(A) t) is included in the general terms.
It is only allowed to cast a superposed type into a superposed tensor product. We
also add the tensor between types, and, as a consequence, a new level. Indeed,
without tensors, the only base qubit type was B. With tensor, we need to put
them in a new level where also tensor of base qubits are considered as base
qubits.
4
We speak about weights and not amplitudes, since the vector may not have norm 1.
The projection rule normalizes the vector while reducing.
8 Alejandro Daz-Caro and Gilles Dowek

B := B | B B Base qubit types (B)


:= B | S( ) | Qubit types ( )
A := | A | S(A) | A A Types (T )
b := x | x : t | |0i | |1i | b b Base terms (B)
v := b | (v + v) | ~0S(A) | .v | v v Values (V)
S(BC)
t := v | tt | (t + t) | j t | ? | .t| t t | head t | tail t | S(A) t Terms ()

The type system includes all the typing rules given in the previous section,
plus the rules for tensor, for cast, and an updated rule SE , for which we introduce
the following notation:
S
Definition 3.1. Let  SS {1, , n}. We define Qn inductively by:
An1 (B) if n
/S
QSn = S\{n}
An1 (S(B)) if n S
A0 (B) = B
 S
Ak (B) B if k + 1
/S
ASk+1 (B) = S\{k+1}
Ak (S(B)) B if k + 1 S
 S
S Ak (B) S(B) if k + 1 /S
Ak+1 (S(B)) = S\{k+1}
Ak (S(B B)) if k + 1 S
where B is any type.
In simple words, notation QSn stands for a tensor of n qubits, where those
indexed by the set S are superposed and typed with the most general type,
{1,2}
for example Q3 stands for S(B B) B and not for S(B) S(B) B. The
following example may be clarifying.
{1,2,4} {1,2,4}
Q5 = A4 (B)
{1,2}
= A3 (S(B)) B
{1,2}
= A2 (B) S(B) B
{1}
= A1 (S(B)) B S(B) B
= A0 (S(B B)) B S(B) B
= S(B B) B S(B) B

In addition, we update the subtyping relation adding the following two rules.
AB AB
and .
AC B C C AC B
The updated type system is given in Table 3.
Rules Ax, Ax~0 , Ax|0i , Ax|1i , , SI , SI+ , If, I , E and ES remain un-
changed. Rule SE types the generalized projection: we force the term to be
measured to be typed with a type of the form QSn , and then, after measuring
S\{1,...,j}
the first j qubits, the new type becomes Qn , that is, we remove the su-
perposition mark S() from the first j types in the tensor product. Rules W and
C are updated only to act on types B instead of just B.
Typing quantum superpositions and measurement 9

Ax Ax~0 Ax|0i Ax|1i


x: x: ~0S(A) : S(A) |0i : B |1i : B
t:A t:A u:A + t : QS n n
SI SI S\{1,...,j}
SE (SN
jn
)
.t : S(A) , (t + u) : S(A) j t : Q n
t : A (AB) , x : t : A
 If I
t:B ? : B B B B x : t : A
t: A u: t : S( A) u : S( )
E ES
, tu : A , tu : S(A)
t:A , x : B, y : B t : A
W C
, x : B t : A , x : B (x/y)t : A
t:A u:B t:BB t:BB
I Er El
, t u : A B head t : B tail t : B
t : S(S(A) B) t : S(A S(B))
S(AB)
r S(AB)
l
S(S(A)B) t : S(A B) S(AS(B)) t : S(A B)
S(A) S(A) S(A)
S(B) t : S(A)
S(B) t : S(A) S(B) r : S(A)
S(A)
S(A)
+
S(B) .t : S(A) , S(B) (t + r) : S(A)

Table 3. Type system of the whole system

Rules I , Er , El are the standard introduction and eliminations for lists.


Rules r and l type the castings. Indeed, S(B) S(A) t indicates that the term t
has type S(A) and will be casted to a term of type S(B). The only valid casts
are S(S(A) B) and S(A S(B)) into S(A B). Rules and + allow
for compositional reasoning. Indeed, casting a linear combination of terms will
rewrite to casting each term in the combination.
The rewrite system is given in Table 4. It includes all the rules from the
previous section plus the rules for tensors: (head) and (tail) to deal with lists,
and the typing casts rules, which normalize superpositions to sums of base terms,
while update the types.
In the rule (proj), j m, P
k n, i n, h m, bhi = |0i or bih = |1i, if an
n
i is absent, it is taken as 1, i=1 [i .](b1i bmi ) is in normal form (hence,
m n
1 n 2 ), and P N , such that i P , h j, bhi = bhk .
The rule (proj) has been updated to account for multiple qubits systems. It
normalizes (as in norm 1) the scalars on the obtained term. The call-by-base
beta rule (b ), and the contextual rule admitting reducing the argument on an
application for the call-by-base abstraction are updated to allow for abstractions
expecting arguments of type B instead of just B (that is, any base qubit type).
The first six rules in the group typing casts(dist+ 0
r ), (distr ), and (distr ),
+ 0
and their analogous (distl ), (distl ), and (distl )deal with the distributivity of
sums, scalar product and null vector respectively. If we ignore the type cast S(B) S(A)
on each rule, these rules are just distributivity rules. For example, rule (dist+ r )
acts on the term (r + s) u, distributing the sum with respect to the tensor
product, producing (r u+ s u) (distribution to the right). However, the term
10 Alejandro Daz-Caro and Gilles Dowek

If b has type B and b B, then (~0S(A) + t) (1) t (neutral)


Beta
(x : B t)b (1) (b/x)t (b ) 1.t (1) t (unit)

Vector space axioms


If u has type S( ), then If t has type A, then
(x : S( ) t)u (1) (u/x)t (n ) 0.t (1) ~0S(A) (zero )
|1i?uv (1) u (if1 ) .0S(A) (1) ~0S(A)
~ (zero)
If

|0i?uv (1) v (if0 ) .(.t) (1) ( ).t (prod)


If t has type B A, then .(t + u) (1) (.t + .u) (dist)
t(u + v) (1) (tu + tv) (lin+r ) (.t + .t) (1) ( + ).t (fact)
Linear distribution

If t has type B A then (.t + t) (1) ( + 1).t (fact1 )


t(.u) (1) .tu (lin r ) (t + t) (1) 2.t (fact2 )
If t has type B A, then (u + v) =AC (v + u) (comm)

=
t~0S(B) (1) ~0S(A) (lin0r ) ((u + v) + w) =AC (u + (v + w)) (assoc)
(t + u)v (1) (tv + uv) (lin+l ) If h 6= u v and h B, then
(.t)u (1) .tu (lin l ) head (h t) (1) h (head)

Lists
~0S(BA) t (1) ~0S(A) (lin0l ) If h 6= u v and h B, then
tail (h t) (1) t (tail)
S(AB)
S(S(A)B) S(AB)
((r + s) u) (1) (S(S(A)B) S(AB)
(r u) + S(S(A)B) (s u)) (dist+ r )
+
S(BA) S(BA) S(BA)
S(BS(A)) (u (r + s)) (1) (S(BS(A)) (u r) + S(BS(A)) (u s)) (distl )
S(AB) S(AB)
S(S(A)B) ((.r) u) (1) . S(S(A)B) (r u) (distr )
Typing casts

S(BA) S(BA)
S(BS(A)) (u (.r)) (1) . S(BS(A)) (u r) (distl )
S(AB)
S(S(A)B) (~0S(A) u) (1) ~0S(AB) (dist0r )
S(BA)
S(BS(A)) (u ~0S(A) ) (1) ~0S(BA) (dist0l )
S(BC)
S(A) S(BC)
(t + u) (1) (S(A) t + S(A) S(BC)
u) (dist+
)
S(BC)
S(A) S(BC)
(.t) (1) . S(A) t (dist)
S(AB)
If u B, then, S(S(A)B) (u v) (1) u v (neut r )
S(AB)
If u B, then, S(AS(B)) (v u) (1) v u (neut l )
j ( n
P
i=1 [i .](b1i bmi )) 
Projection


(p) jh=1 bhk iP P i
N P
2
.(bj+1,i bmi ) (proj)
iP |i |
|i |2
P  
with p = iP Pn | |2
i=1 i
t (p) u t (p) u
tv (p) uv (x : B v)t (p) (x : B v)u
t (p) u t (p) u t (p) u t (p) u
t + v (p) u + v .t (p) u j t (p) j u t v (p) u v
t (p) u t (p) u t (p) u
head t (p) head u tail t (p) tail u S(B) S(B)
S(A) t (p) S(A) u

Table 4. Rewrite rules for the whole system

(r + s) u may have type S(A) B, S(A) S(B) or S(A B), while, among
those, the term (r u + s u) can only have type S(A B). Hence, we cannot
reduce the first term to the second without losing subject reduction. Instead,
we need to cast the term explicitly to the valir type in order to reduce. Notice
S(AB)
that in the previous example it would have been enough to use S(A)B . Indeed,
Typing quantum superpositions and measurement 11

the term (r + s) u can be typed with S(A) B. However, we prefer the more
general S(S(A) B) and hence to use the same rule when, for example, a sum
is given.
The next two rules, (dist+
) and (dist ), distribute the cast over sums and
scalars. For example S(BB)
S(S(B)B) ((. |1i) |0i + (. |0i) |1i) reduces by rule
(dist+ S(BB) S(BB)
) to (S(S(B)B) (. |1i) |0i + S(S(B)B) (. |0i) |1i), and hence, the dis-
tributivity rule can act. The last two rules in the group, (neutr ) and (neutl ), re-
move the cast when it is not needed anymore. For example S(BB)
S(S(B)B) (.. |0i)
(dist
r ) (dist
r ) (neutr )
S(BB)
|1i (1) . S(S(B)B) (. |0i) |1i (1) .. S(BB) S(S(B)B) |0i |1i (1)

.. |0i |1i.
The measurement rule (proj) is updated to measure the first j qubits. Hence,
a n-qubits in normal form (that is, a sum of tensors of qubits with or without
a scalar in front), for example, the term ((2.(|0i |1i |1i) + |0i |1i |0i) +
3.(|1i |1i |1i)) can be measured and will produce a n-qubits where the first
j qubits are the same and the remaining are untouched, with its scalars changed
to have norm 1. In this 3-qubits example, measuring the first two can produce
either |0i |1i ( 25 . |1i + 15 . |0i) or |1i |1i (1. |1i). The probability of
|2|2 |1|2 5
producing the first is (|2|2 +|1|2 +|3|2 ) + (|2|2 +|1|2 +|3|2 ) = 14 and the probability of
|3|2 9
producing the second is (|2|2 +|1| 2 +|3|2 ) = 14 .

Remark, to conclude, that since the calculus presented in this paper is call-
by-base for the functions expecting a non-linear argument, it avoids a well-
known problem in others -calculi with a linear logic type system including
modalities. To illustrate this problem, consider the following typing judgement:
y : S(B) (x : B (x x))(y) : S(B) S(B). If we allow to -reduce this
term, we would obtain (y) (y) which is not typable in the context y : S(B).
A standard solution to this problem is illustrated in [7], where the terms that
can be cloned are distinguished by a mark, and used in a let construction, while
non-clonable terms are used in abstractions.

4 Subject reduction

Thanks to the explicit casts, the resulting system has the Subject Reduction
property (Theorem 4.5), that is, the typing is preserved by weak-reduction
(i.e. reduction on closed terms). The proof of this theorem is not trivial, spe-
cially due to the complexity of the system itself. The detailed proofs with some
additional lemmas are given in the seven-page long Appendix B.
The two main lemmas of the proof, the generation lemma and the substi-
tution lemma, are stated below, together with a few paradigmatic cases of the
proof.

Definition 4.1. We denote by | | to the set of types in . For example, |x :


B, y : S(B)| = {B, S(B)}.

Lemma 4.2 (Generation lemmas).


12 Alejandro Daz-Caro and Gilles Dowek

If x : A, then x : , | | \ { } B, and  A.
If x : t : A, then , x : t : B, with , B  A and
| \ | B.
If |0i : A, then B  A and | | B.
If |1i : A, then B  A and | | B.
If ~0S(B) : A, then S(B)  A and | | B.
If tu : A, then one of the following possibilities happens:
1 t : B and 2 u : , with B  A, or
1 t : S( B) and 2 u : S( ), with S(B)  A.
In both cases, 1 2 and | | \ |1 2 | B.
If (t + u) : A, then 1 t : B and 2 u : B, with S(B)  A and
1 2 , | \ (1 2 )| B.
S\{1,...,j}
If j t : A, then t : QSn , with , | \ | B and Qn 
A.
If ? : A, then B B B B  A and | | B.
If .t : A, then t : B, with , | \ | B and S(B)  A.
If t u : A, then 1 t : B and 2 u : C, with 1 2 ,
| \ (1 2 )| B and B C  A.
If head t : A, then t : B B, with , | \ | B and B  A.
If tail t : A, then t : B B, with , | \ | B and B  A.
If S(B)S(C)
t : A, then t : S(B), with , | \ | B and
S(C)  A. Moreover,
If t 6= .t and t 6= (t1 +t2 ), then a rule R allows typing S(B)
S(C)
t : S(C)

directly from t : S(B).
If t = .t , then t : S(B), and a rule R allows typing S(B) S(C)
t :
S(C) directly from t : S(B).
If t = (t1 + t2 ), then for i = 1, 2, i ti : S(B), with = 1 , 2 , and
S(C)
a rule R allows typing i S(B) ti : S(C) directly from i ti : S(B).
Proof. First notice that if t : A is derivable, then t : B is derivable, with
and | \ | B (because of rule W ) and A  B, (because of rule ).
Notice also that those are the only typing rules changing the sequent without
changing the term on the sequent. Rules E and ES and are straightforward to
check. All the other rules, except for those involving arrows, are syntax directed:
one rule for each term. Therefore, the lemma is proven by a straightforward rule
by rule analysis for all the items but last.
For the last item, let S(B)S(C)
t : A, then it is clear that S(B)
S(C)
t : S(C),

with S(C)  A, and | \ | B. Also, notice that there is always a
S(E) S(E)
Rule allowing typing S(D) u : S(E) if u : S(D), if S(D) is a subterm of a
well-typed term. We finish the proof by induction on t.
Corollary 4.3. If (t + u) : A, then t : A and u : A.
Proof. By Lemma 4.2, t : B and u : B, with B  S(B)  A, then, we
conclude by rule .
Lemma 4.4 (Substitution lemma). Let F V (u) = , then if , x : t : A,
u : , where if = B then u B, we have , (u/x)t : A.
Typing quantum superpositions and measurement 13

Proof. By structural induction on t.

Since the strategy is weak, subject reduction is proven for closed terms.

Theorem 4.5 (Subject reduction on closed terms). For any closed terms
t and u and type A, if t (p) u and t : A, then u : A.

Proof. By induction on the rewrite relation. We only give two cases as example.

(b ) and (n ) Let (x : t)u : A, with u : , where, if = B, then u B.


Then by Lemma 4.2, one of the following possibilities happens:
1. x : t : B and u : , with B  A, or
2. x : t : S( B) and u : S( ), with S(B)  A.
Thus, in any case, by Lemma 4.2 again, x : t : C, with, in case 1,
C  B and in case 2, C  S( B). Hence, = and
in the first case C  B  A, while in the second, C  B  S(B)  A, so, in
general C  A. Since u : , where if = B, then u B, by Lemma 4.4,
(u/x)t : C,P and by rule , (u/x)t : A.
n
(proj) Let Pj ( i=1 [i .](b1i bmi )) : A. Then, by Lemma 4.2, we have
n S S\{1,...,j}
that i=1 [i .](b1i bmi ) : Q , with Q  A. Then, by
Corollary 4.3, we have for everyNi, b1i bmi : QS . By Lemma 4.2, for
every k, bki : Bk , such that k Bk  QS . Since bki are either |0i or |1i,
by Lemma 4.2, for every k, B  Bk . Then,  by rules  , I , , SI+ and I
Nj
again, we can derive t=1 btk iP P i
P
2
.(bj+1,i bmi ) :
iP |i |
S\{1,...,j}
Q , for any k and P such that i P , t j, bti = btk .

5 Interpretation

We consider vector spaces equipped with a canonical base, and subsets of such
spaces.
Let E and F be two vector spaces with canonical bases B = {~bi | i I} and
C = {~cj | j J}. The tensor product E F of E and F is the vector space
of canonical base {~bi ~cj | i I and j J}, where ~bi ~cj is the ordered pair
formed with the vector ~bi and the vector ~cj . The operation is extended to the
vectors of E and F bilinearly: ( i i~bi ) ( j j ~cj ) = ij i j (~bi ~cj ).
P P P
Let E and F be two vector spaces equipped with bases B and C, and S and
T be two subsets of E and F respectively, we define the set S T , subset of the
vector space E F , as follows: S T = {~u ~v |~u S, ~v T }.
Remark that E F differs from E F . For instance, if E and F are C2
equipped with the base {~i, ~j}, then E F contains ~i ~i and ~j ~j but not
~i ~i + ~j ~j, that is not a tensor product of two vectors of C2 .
Let E be a vector space equipped with a base B, and S a subset of E. We
write S(S) for the vector space over C generated by the span of S, that is,
containing all the linear combinations of elements of S.
14 Alejandro Daz-Caro and Gilles Dowek

Hence, if E and F are two vector spaces of bases B and C then E F =


S(B C) = S(E F ).
Let S and T be two sets. We write S T for the vector space of formal
linear combination of functions from S to T . The set S T of the functions
from S to T is a subsetand even a basisof this vector space.
Note that if S and T are two sets , then S T = S(S T ).
To each type we associate the subset of some vector space

JBK = {( 10 ) , ( 01 )}, a subset of C2


JS(A)K = SJAK
J AK = J K JAK
JA BK = JAK JBK

Remark that JS(A B)K = S(JAK JBK) = JAK JBK.


If = x1 : 1 , ..., xn : n is a context, then a -valuation is a function
mapping each xi to Ji K.
We now would associate to each term t of type A an element JtK of JAK. But
as our calculus is probabilistic, due to the presence of a measurement operator,
we must associate to each term a set of elements of JAK.
Let t be a term of type A in and a -valuation. We define the interpre-
tation of t, JtK as follows.

JxK = x
Jx : tK = {f | a J K, f a JtK,x7J K }
J|0iK = {( 10 )}
J|1iK = {( 01 )}
Jt uK = JtK JuK
J(t + u)K = {a + b | a JtK and b JuK }
J.tK = {a | a JtK }
J0S(B) K = {~0}, the null vector of the vector space JS(B)K
~
 
P P
g (a) | g JtK , a JuK If t : A



i i i i
(iI
iI )
JtuK = P P P P

i j gi (cj ) | i gi JtK , j cj JuK
iI jJ

iI jJ
If t : S( A)


j
O X
Jj tK = { bhk r Pi 2 (bj+1,i bmi ) | i P, h, bhi = bhk }
|i |
h=1 iP iP

n
X
where JtK = { i (b1i bmi )} with bih = ( 01 ) or ( 10 )
i=1
Typing quantum superpositions and measurement 15

b If a = ( 01 )

J?K = {f | a, b, c JBK, f abc = }
c If a = ( 10 )
Jhead tK = {a1 | a1 an JtK , a1 JBK}
Jtail tK = {a2 an | a1 an JtK , a1 JBK}
S(BC)
JS(A) tK = JtK

Lemma 5.1. If A  B, then JAK JBK.

Proof. By induction on the relation  (cf. Appendix C).

Lemma 5.2. If t : A and , x 7 S, y 7 S is a -valuation, then JtK,x7S,y7S =


J(x/y)tK,x7S .

Proof. By induction on t (cf. Appendix C).

Theorem 5.3. If t : A, and is a -valuation. Then JtK JAK.

Proof. By induction on the typing derivation (cf. Appendix C).


P
S If t : A, is a -valuation, and t (pi ) ri , with
Theorem 5.4. i pi = 1,
then JtK = i Jri K .

Proof. By induction on the rewrite relation. (cf. Appendix C).

6 Examples

In this section we show that our language is expressive enough to express the
Deutsch algorithm (Section 6.1) and the Teleportation algorithm. (Section 6.2).

6.1 Deutsch algorithm

The Deutsch algorithm tests whether the binary function f implemented by the
oracle Uf is constant (f (0) = f (1)) or balanced (f (0) 6= f (1)). The algorithm
is as follows: it starts with a qubit in state |0i and another in state |1i, and
apply Hadamard gates to both. Then it applies the Uf operator, followed by a
Hadamard and a measurement to the first qubit. When the function is constant,
the first qubit ends in |0i, when it is balanced, it ends in |1i.
The Hadamard gate (H) produces 12 .(|0i + |1i) when applied to |0i and
1 .(|0i |1i) when applied to |1i. Hence, it can be implemented with the if-
2
then-else construction: H = x : B 12 .(|0i + (x?( |1i)|1i)). Notice that the
abstracted variable has a base type (i.e. non-linear). Hence, if H is applied to a
superposition, say (. |0i + . |1i), it reduces, as expected, in the following way:
+
(lin ) (lin )2
H(. |0i + . |1i) r (1) (H. |0i + H. |1i) r (1) (.H |0i + .H |1i)
16 Alejandro Daz-Caro and Gilles Dowek

and then is applied to the base terms. We define H1 as the function taking a
two-qubits system and applying H to the first. H1 = x : B B ((H (head x))
(tail x)). Similarly, Hboth applies H to both qubits.

Hboth = x : B B ((H (head x)) (H (tail x)))

The gate Uf is called oracle, and it is defined by Uf |xyi = |x, y f (x)i where
is the addition modulo 2. In order to implement it, we need the not gate, which
can be implemented similarly to the Hadamard gate:

not = x : B (x?|0i|1i)

Then, the Uf gate is implemented by:

Uf = x : B B ((head x) ((tail x)?(not (f (head x)))(f (head x))))

where f is a given term of type B B.


Finally, the Deutsch algorithm combines all the previous definitions:
S(BB)
Deutschf = 1 (S(S(B)B) H1 (Uf S(BB) S(BS(B)) Hboth (|0i |1i)))
S(BS(B)) S(S(B)S(B))

The casts after the Hadamards are needed to fully develop the qubits and
then be able to use it as an argument of a non-linear abstraction (i.e. an abstrac-
tion expecting for base terms and so linear-distributing over superpositions). The
Deutschf term is typed, as expected, by Deutschf : B S(B).
This term, on the identity function, reduces as follows:
1 1 1 1
Deutschid (1) 1 ( . |1i |0i . |1i |1i) (1) |1i( . |0i . |1i)
(proj)

2 2 2 2
The trace on this reduction and the type derivation are given in Appendix D.

6.2 Teleportation algorithm


The circuit for this algorithm is given in Figure 1.

Alice
|i H

00 Bob
Z b1 notb2 |i

Fig. 1. Teleportation circuit


The cnot gate, which applies not to the second qubit only when the first
qubit is |1i, can be implemented with an if-then-else construction as follows:

cnot = x : B B ((head x) ((head x)?(not (tail x))(tail x)))


Typing quantum superpositions and measurement 17

We define H31 to apply H to the first qubit of a three-qubit system.

H31 = x : B B B ((H (head x)) (tail x))

Remark that the only difference with H1 is the type of the abstracted variable.
In addition, we need to apply cnot to the two first qubits, so we define cnot312 as

cnot312 = x : B B B ((cnot (head x (head tail x))) (tail tail x))

The Z gate returns |0i when it receives |0i, and |1i when it receives |1i.
Hence, it can be implemented by:

Z = x : B (x?( |1i)|0i)

The Bob side of the algorithm will apply Z and/or not according to the bits
it receives from Alice. Hence, for any U : B S(B) or U : B B, we define
U(b) to be the function which depending on the value of a base qubit b applies
the U gate or not:
U(b) = (x : B y : B (x?Uyy)) b
Alice and Bob parts of the algorithm are defined separately:
S(BBB)
Alice = x : S(B)S(BB)(2 (S(S(B)BB) H31 (cnot312 S(BS(BB))
S(BBB)
S(S(B)S(BB))
S(BS(BB))
x)))

Notice that before passing to cnot312 the parameter of type S(B) S(B B),
we need to fully develop the term using the two casts, and again, after the
Hadamard gate. Bob side is implemented by

Bob = x : B B B (Z(head x)
(not(head tail x)
(tail tail x)))

The teleportation is applied to an arbitrary qubit and to the following Bell


state
1 1
00 = ( . |0i |0i + . |1i |1i)
2 2
and it is defined by:
S(BBB)
Teleportation = q : S(B) (Bob(S(BBS(B)) Alice (q 00 )))

This term is typed, as expected, by: Teleportation : S(B) S(B) and


applying the teleportation to any superposition (. |0i + . |1i) will reduce, as
expected, to (. |0i + . |1i). The trace on this reduction and the type derivation
are given in Appendix E.

7 Conclusion

In this paper we have proposed a way to unify logic-linear and algebraic-linear


quantum -calculi, by interpreting -terms as linear functions when they expect
18 Alejandro Daz-Caro and Gilles Dowek

duplicable data and as non-linear ones when they do not, and illustrated this
idea with the definition of a calculus.
This calculus is first-order in the sense that variables do not have functional
types. In a higher-order version we should expect abstractions to be clonable.
But, allowing cloning abstractions allows cloning superpositions, by hiding them
inside. For example, x : B B ( 12 . |0i + 12 . |1i). It has been argued [4, 5]
that what is cloned is not the superposition but a function that creates the
superposition, because we had no way there to create such an abstraction from
an arbitrary superposition. The situation is different in the calculus presented
in this paper as the term x : S(B) y : B x precisely takes any term t of type
S(B) and returns the term y : B t. So, a cloning machine could be constructed
by encapsulating any superposition t under a lambda, which transform it into a
basis term, so a clonable term. Extending this calculus to the higher-order will
require characterizing precisely the abstractions that can be taken as arguments,
not allowing to duplicate functions creating superpositions.

Acknowledgements We would like to thank Eduardo Bonelli, Luca Paolini,


Simona Ronchi della Rocca and Luca Roversi for interesting comments and sug-
gestions.

References

1. Samson Abramsky. Computational interpretations of linear logic. Theoretical Com-


puter Science, 111(1):357, 1993.
2. Thorsten Altenkirch and Jonathan Grattage. A functional quantum programming
language. In Proceedings of LICS 2005, pages 249258. IEEE, 2005.
3. Pablo Arrighi and Alejandro Daz-Caro. A System F accounting for scalars. Logical
Methods in Computer Science, 8(1:11), 2012.
4. Pablo Arrighi, Alejandro Daz-Caro, and Benot Valiron. The vectorial lambda-
calculus. Information and Computation, 254(1):105139, 2017.
5. Pablo Arrighi and Gilles Dowek. Lineal: A linear-algebraic lambda-calculus. Logical
Methods in Computer Science, 13(1:8), 2017.
6. Ali Assaf, Alejandro Daz-Caro, Simon Perdrix, Christine Tasson, and Benot Val-
iron. Call-by-value, call-by-name and the vectorial behaviour of the algebraic -
calculus. Logical Methods in Computer Science, 10(4:8), 2014.
7. Andrew Barber. Dual intuitionistic linear logic. Technical Report ECS-LFCS-96-
347, The Laboratory for Foundations of Computer Science, University of Edin-
burgh, 1996.
8. Alejandro Daz-Caro and Barbara Petit. Linearity in the non-deterministic call-by-
value setting. In Luke Ong and Ruy de Queiroz, editors, Proceedings of WoLLIC
2012, volume 7456 of LNCS, pages 216231, 2012.
9. J.-Y. Girard. Linear logic. Theoretical Compututer Science, 50:1102, 1987.
10. Alexander S. Green, Peter LeFanu Lumsdaine, Neil J. Ross, Peter Selinger, and
Benot Valiron. Quipper: a scalable quantum programming language. ACM SIG-
PLAN Notices (PLDI13), 48(6):333342, 2013.
11. Gregg Jaeger. Quantum information: An overview. Springer, 2007.
Typing quantum superpositions and measurement 19

12. Michael Nielsen and Isaac Chuang. Quantum Computation and Quantum Infor-
mation. Cambridge University Press., 2000.
13. Michele Pagani, Peter Selinger, and Benot Valiron. Applying quantitative seman-
tics to higher-order quantum computing. ACM SIGPLAN Notices (POPL14),
49(1):647658, 2014.
14. Gerald E. Peterson and Mark E. Stickel. Complete sets of reductions for some
equational theories. Journal of the ACM, 28(2):233264, 1981.
15. Peter Selinger and Benot Valiron. Quantum lambda calculus. In Simon Gay and
Ian Mackie, editors, Semantic Techniques in Quantum Computation, chapter 9,
pages 135172. Cambridge University Press, 2009.
16. William K. Wootters and Wojciech H. Zurek. A single quantum cannot be cloned.
Nature, 299:802803, 1982.
17. Margherita Zorzi. On quantum lambda calculi: a foundational perspective. Math-
ematical Structures in Computer Science, 26(7):11071195, 2016.

A Basics notions of quantum computing


This appendix does not pretend to introduce a full description of quantum com-
puting, the interested reader can find actual introductions to this area in many
textbooks, e.g. [11, 12]. This section only pretends to introduce some basic no-
tations and concepts.
In quantum computation, data is expressed by normalised vectors in Hilbert
spaces. For our purpose, this means that the vector spaces are defined over
complex numbers and come with a norm and a notion of orthogonality. The
smallest space usually considered is the space of qubits. This space is the two-
dimensional vector space C2 , and it comes with a chosen orthonormal basis
denoted by {|0i , |1i}. A qubit (or quantum bit) is a normalised vector |0i +
|1i, where ||2 +||2 = 1. To denote an unknown qubit it is common to write
|i. A two-qubits vector is a normalised vector in C2 C2 , that is, a normalised
vector generated by the orthonormal basis {|00i , |01i , |10i , |11i}, where |xyi
stands for |xi |yi. In the same way, a n-qubits vector is a normalised vector in
(C2 )n (or CN with N = 2n ). Also common is the notation h| for the transposed,
conjugate of |i, e.g. if |i = [1 , 2 , . . . , n ]T , then h| = [1 , 2 , . . . , n ] where
for any C, denotes its conjugate.
The operators on qubits that are considered in this paper are the quantum
gates, that is, isometric operators. An isometric operator is a linear function
preserving the norm and the orthogonality of vectors. The adjoint of a given
operator U is denoted by U , and the isometric condition imposes that U U =
Id. These functions are linear, and so it is enough to describe their action on
the base vectors. Another way to describe these functions would be by matrices,
and then the adjoint is just its conjugate transpose. A set of universal quantum
gates is the set cnot, R 4 and had, which can be defined as follows:
The cnot gate. The controlled-not is a two-qubits gate which only changes the
second qubit if the first one is |1i:
cnot |0xi =
|0xi ; cnot |1xi = where not |0i = |1i and not |1i = |0i.
|1i not |xi
20 Alejandro Daz-Caro and Gilles Dowek

The R 4 gate. The R 4 gate is a single-qubit gate that modifies the phase of
the qubit:
R 4 |0i = |0i ; R 4 |1i =
where 4 is the phase shift.
ei 4 |1i
The H gate. The Hadamard gate is a single-qubit gate which produces a basis
change:
H |0i = 12 |0i + 12 |1i ; H |1i = 12 |0i 12 |1i

To make these gates act in higher-dimension qubits, they can be put together
with the bilinear symbol . For example, to make the Hadamard gate act only
in the first qubit of a two-qubits register, it can be taken to H Id, and to apply
a Hadamard gate to both qubits, just H H.
An important restriction, which has to be taken into account if a calculus
pretends to encode quantum computing, is the so called no-cloning theorem [16]:

Theorem A.1 (No cloning). There is no linear operator such that, given any
qubit |i CN , it can clone it. That is, it does not exist any isometric operator
U and fixed |i CN such that U |i = |i.

Proof. Assume there exists such an operator U , so given any |i and |i one has
U |i = |i and also U |i = |i. Then

hU |U i = h|i (1)

where hU | is the conjugate transpose of U |i. However, notice that the left
side of equation (1) can be rewritten as

h| U U |i = h|i = h|i

While the right side of equation (1) can be rewritten as


2
h|ih|i = h|i
2
So h|i = h|i , which implies either h|i = 0 or h|i = 1, none of
which can be assumed in the general case, since |i and |i were picked as
random qubits.

The implication of this theorem in the design choices of a calculus is that it


must be forbidden to allow functions duplicating arbitrary arguments. However,
notice that this does not forbid cloning some specific qubit states. Indeed, for
example the qubits |0i and |1i can be cloned without much effort by using the
cnot gate: cnot |00i = |00i and cnot |10i = |11i. In this sense, the imposed re-
striction is not a resources-aware restriction a la linear logic [9]. It is a restriction
that forbids us from creating a universal cloning machine, but still allows us to
clone any given known term.
Another operation considered on qubits is the measurement. A projector is
an operator of the form |i h|. For example, in the canonical base {|0i , |1i} of
Typing quantum superpositions and measurement 21

C2 , P0 = |0i h0| is a projector and P1 = |1i h1| is another projector, with respect
to such a base. Indeed,

P0 ( |0i + |1i) = P0 |0i + P0 |1i


= |0i h0|0i + |0i h0|1i
= |0i
P1 ( |0i + |1i) = P1 |0i + P1 |1i
= |1i h1|0i + |1i h1|1i
= |1i

With these projectors we can define the measurement operators M0 and M1 as


Pi |i
Mi |i = p
h| Pi |i

For example,
P0 ( |0i + |1i)
M0 ( |0i + |1i) = p
( h0| + h1|)P0 ( |0i + |1i)

|0i
=p
( h0| + h1|)( |0i)
|0i
=p
|| h0|0i + h1|0i
2

|0i
=p = |0i 5 |0i
|| 2 ||

The quantum measurement is defined in terms of sets of measurements op-


erators. For example, in the canonical base {|0i , |1i}, the set {M0 , M1 } is a
quantum measurement. When it acts on a qubit |i, it will apply the operator
Mi , with probability h| Pi |i.

B Omitted proofs in Section 4 (Subject reduction)


Lemma B.1. If S(A)  B, then there exists C such that B = S(C)

Proof. Straightforward analysis of the definition of .

Lemma 4.2 (Generation lemmas).


If x : A, then x : , | | \ { } B, and  A.
If x : t : A, then , x : t : B, with , B  A and
| \ | B.
If |0i : A, then B  A and | | B.
5
The scalar ||
is known as a phase and can be ignored, so only |0i remains.
22 Alejandro Daz-Caro and Gilles Dowek

If |1i : A, then B  A and | | B.


If ~0S(B) : A, then S(B)  A and | | B.
If tu : A, then one of the following possibilities happens:
1 t : B and 2 u : , with B  A, or
1 t : S( B) and 2 u : S( ), with S(B)  A.
In both cases, 1 2 and | | \ |1 2 | B.
If (t + u) : A, then 1 t : B and 2 u : B, with S(B)  A and
1 2 , | \ (1 2 )| B.
S\{1,...,j}
If j t : A, then t : QSn , with , | \ | B and Qn 
A.
If ? : A, then B B B B  A and | | B.
If .t : A, then t : B, with , | \ | B and S(B)  A.
If t u : A, then 1 t : B and 2 u : C, with 1 2 ,
| \ (1 2 )| B and B C  A.
If head t : A, then t : B B, with , | \ | B and B  A.
If tail t : A, then t : B B, with , | \ | B and B  A.
S(C)
If S(B) t : A, then t : S(B), with , | \ | B and
S(C)  A. Moreover,
If t 6= .t and t 6= (t1 +t2 ), then a rule R allows typing S(B)
S(C)
t : S(C)

directly from t : S(B).
If t = .t , then t : S(B), and a rule R allows typing S(B) S(C)
t :

S(C) directly from t : S(B).
If t = (t1 + t2 ), then for i = 1, 2, i ti : S(B), with = 1 , 2 , and
S(C)
a rule R allows typing i S(B) ti : S(C) directly from i ti : S(B).

Proof. First notice that if t : A is derivable, then t : B is derivable, with


and | \ | B (because of rule W ) and A  B, (because of rule ).
Notice also that those are the only typing rules changing the sequent without
changing the term on the sequent. Rules E and ES and are straightforward to
check. All the other rules, except for those involving arrows, are syntax directed:
one rule for each term. Therefore, the lemma is proven by a straightforward rule
by rule analysis for all the items but last.
For the last item, let S(B)S(C)
t : A, then it is clear that S(B)
S(C)
t : S(C),

with S(C)  A, and | \ | B. Also, notice that there is always a
S(E) S(E)
Rule allowing typing S(D) u : S(E) if u : S(D), if S(D) is a subterm of a
well-typed term.
We proceed by induction on t.

If t 6= .t and t 6= (t1 + t2 ), then the only possibility is t : S(B).


If t = .t , then the cases are the following:
.t : S(B), then by a previous item on this Lemma, t : C,
with S(C)  S(B), and | \ | B. Hence, by rules W and
, t : S(B).
S(B)
S(C)
t : S(C). Then, by the induction hypothesis, t : S(B),
with and | \ | B. Hence, by rule W t : S(B).
If t = (t1 + t2 ), then the cases are the following:
Typing quantum superpositions and measurement 23

(t1 + t2 ) : S(B), then by a previous item in this Lemma, for i = 1, 2


i ti : S(C), with S(C)  S(B), 1 2 and | \(1 2 )| B.
Hence, by rules W and , i ti : S(B).
S(C)
i S(B) ti : S(C), for i = 1, 2. Then, by the induction hypothesis,
i ti : S(B), with i i and |i \ i | B. Hence, by rule W

i ti : S(B).

Corollary 4.3.

If (t + u) : A, then t : A and u : A.
If (t + u) : A, then A = S(B).
If .t : A, then t : A.
If .t : A, then .t : A.
If .t : A, then A = S(B).

Proof.

By Lemma 4.2, t : B and u : B, with B  S(B)  A, then, we conclude


by rule .
By Lemma 4.2, t : C and u : C, with C  S(C)  A, but then, by
Lemma B.1, A = S(B) for some type B.
By Lemma 4.2, t : B, with S(B)  A, then, we conclude by rule .
By Lemma 4.2, t : B, with S(B)  A, then we conclude by rules SI and
.
By Lemma 4.2, t : C with S(C)  A, but then, by Lemma B.1, A = S(B)
for some type B.

Corollary B.2. If b B and b : S(A), then b : A.

Proof. We proceed by induction on b.

Let b = x : t. Then, by Lemma 4.2, x : t : B, with B  S(A),


and so B  A, and we conclude by rule .
Let b = |0i. Then, by Lemma 4.2, B  S(A), hence B  A and we conclude
by rule .
Let b = |1i. Analogous to previous case.
Let b = b1 b2 . Then, by Lemma 4.2, b1 : B1 , b2 : B2 , and B1 B2 
S(A). Hence, B1 B2  A and we conclude by rule .

Lemma B.3. If t : A and F V (t) = , then | | B.

Proof. If F V (t) = then t : A. If 6= , the only way to derive t : A is


by using rule W to form , hence | | B.

Lemma 4.4 (Substitution lemma). Let F V (u) = , then if , x : t : A,


u : , where if = B then u B, we have , (u/x)t : A.
24 Alejandro Daz-Caro and Gilles Dowek

Proof. Notice that due to Lemma B.3, || B, hence, it suffices to consider


= . We proceed by structural induction on t.
The set of terms be divided in the following groups:

unclassified := x | x : t
arity0 := ~0S(A) | |0i | |1i | ?
arity1 (r) := j r | .r | head r | tail r | S(CD)
S(B) t
arity2 (r)(s) := rs | (r + s) | r s

Hence, we can consider the terms by groups:


unclassified terms
t = x. By Lemma 4.2, A = , | | B and  A. Since (u/x)x = u, we
have (u/x)x : . Hence, since  A, by rule , (u/x)x : A. Finally,
since | | B, by rule W , we have (u/x)x : A.
t = y 6= x. By Lemma 4.2, y : , (| | { }) \ { } B and  A.
Hence, by rule , y : y : A. Since | | B, by rule W , we have
y : A. Finally, since (u/x)y = y, we have (u/x)y : A.
t = y : v. Without lost of generality, assume y is does not appear free
in u. By Lemma 4.2, , y : v : B, with {x : },
B  A and (| | { }) \ | | B. By the induction hypothesis, , y :
(u/x)v : B, with = \ {x : }. Notice that if x : ,
the induction hypothesis applies directly, in other case, B and so
by rule W the context can be enlarged to include x : , hence the
induction hypothesis applies in any case. Therefore, by rule I ,
y : (u/x)v : B. Since B  A, by rule , y :
(u/x)v : A. Hence, since | |\| | B, by rule W , y : (u/x)v :
A. Since y does not appear free in u, y : (u/x)v = (u/x)(y : v).
Therefore, (u/x)(y : v) : A.
0
arity terms All of these terms are typed by an axiom with a type B which, by
Lemma 4.2, B  A. Also, by the same Lemma, |, x : | B. So, we can
type with the axiom, and empty context, arity0 : B, and so, by rule W ,
arity0 : B. Notice that arity0 = (u/x)arity0 . We conclude by rule .
arity1 (r) terms By Lemma 4.2, r : B, such that by a derivation tree T ,
arity1 (r) : C, where ( {x : }), (| | ) \ | | B and C  A.
If x : / , then = B and so we can extend with x : . Hence,
in any case, by the induction hypothesis, \ {x : } (u/x)r : C. Then,
using the derivation tree T , \ {x : } arity1 ((u/x)r) : C. Notice that
arity1 ((u/x)r) = (u/x)arity1 (r). We conclude by rules W and .
arity2 (r)(s) terms By Lemma 4.2, 1 r : C and 2 s : D, such that by a
typing rule R, 1 , 2 arity2 (r)(s) : E, with E  A, and where (1 2 )
( {x : }) and (| | ) \ (|1 | |2 |) B. Therefore, if x : / i ,
i = 1, 2, we can extend i with x : using rule W . Hence, by the induction
hypothesis, 1 \ {x : } (u/x)r : C and 2 \ {x : } (u/x)s : D. So, by
rule R, 1 \ {x : }, 2 \ {x : } arity2 ((u/x)r)((u/x)s) : E. Notice that
arity2 ((u/x)r)((u/x)s) = (u/x)arity2 (r)(s). We conclude by rules W and .
Typing quantum superpositions and measurement 25

Theorem 4.5 (Subject reduction on closed terms). For any closed terms
t and u and type A, if t (p) u and t : A, then u : A.
Proof. We proceed by induction on the rewrite relation.

(b ) and (n ) Let (x : t)u : A, with u : , where, if = B, then u B.


Then by Lemma 4.2, one of the following possibilities happens:
1. x : t : B and u : , with B  A, or
2. x : t : S( B) and u : S( ), with S(B)  A.
Thus, in any case, by Lemma 4.2 again, x : t : C, with, in case 1,
C  B and in case 2, C  S( B). Hence, = and
in the first case C  B  A, while in the second, C  B  S(B)  A, so, in
general C  A. Since u : , where if = B, then u B, by Lemma 4.4,
(u/x)t : C, and by rule , (u/x)t : A.
(neutral) Let (~0S(A) + t) : A. Then, by Corollary 4.3, t : A.
(unit) Let 1.t : A. Then, by Corollary 4.3, t : A.
(zero ) Let 0.t : A. Then, by Corollary 4.3, A = S(B), and so by rule Ax~0 ,
~0S(A) : A.
(zero) Let .0 : A. By Corollary 4.3, A = S(B), hence, by rule Ax~0 , ~0S(A) :
A.
(prod) Let .(.t) : A. By Corollary 4.3, .t : A. Then, by Corollary 4.3
again, ( ).t : A.
(dist) Let .(t + u) : A. By Lemma 4.2, (t + u) : B, with S(B)  A. Then,
by Corollary 4.3, t : B and u : B. Hence, by rule SI , .t : S(B) and
.u : S(B). We conclude by rules SI+ and .
(fact) Let (.t + .t) : A. By Corollary 4.3, .t : A. Then, by Corollary 4.3
again, ( + ).t : A.
(fact1 ) Let (.t + t) : A. By Corollary 4.3, .t : A. Then, by Corollary 4.3
again, ( + 1).t : A.
(fact2 ) Let (t + t) : A. By Lemma 4.2, t : B, with S(B)  A. Then, by rule
SI , 2.t : S(B). We conclude by rule .
(head) Let head (t u) : A. Hence, by Lemma 4.2, t u : B B, with
B  A. Then, by Lemma 4.2 again, t : B and u : C, with B C  B B.
Hence, B  B  A, and so we conclude by rule .
(tail) Analogous to case (head).
(if1 ) Let |1i?uv : A. Then, by Lemma 4.2, one of the following possibilities
happens:
1. |1i?u : 1 B and v : 1 , with B  A. Then, by Lemma 4.2 again,
one of the following possibilities happens:
(a) |1i? : 2 C, and u : 2 , with C  1 B  1 A. Then,
by Lemma 4.2 again, one of the following possibilities happens:
i. ? : 3 D, and |1i : 3 , with D  2 C  2 2
A. Then, by Lemma 4.2 again, B B B B  3 2
1 A, so 2 = B  A, and hence, by rule , u : A.
ii. ? : S(3 D) and |1i : S(3 ), with S(D)  2 C, but
this case is impossible by Lemma B.1.
26 Alejandro Daz-Caro and Gilles Dowek

(b) |1i? : S(2 C), and u : S(2 ), with S(C)  1 B, but this
case is impossible by Lemma B.1.
2. |1i?u : S(1 B) and v : S(1 ), with S(B)  A. Then, by
Lemma 4.2 again, one of the following possibilities happens:
(a) |1i? : 2 C, and u : 2 , with CE  S(1 B)  S(1 A).
Then, by Lemma 4.2 again, one of the following possibilities happens:
i. ? : 3 D, and |1i : 3 , with D  2 C  2
S(1 A). Then, by Lemma 4.2 again, B B B B 
3 2 S(1 A), so 2 = B  A, and hence, by rule ,
u : A.
ii. ? : S(3 D), and |1i : S(3 ), with S(D)  2 C, but
this case is impossible by Lemma B.1.
(b) |1i? : S(2 C), and u : S(2 ), with S(C)  S(1 B) Then,
by Lemma 4.2 again, one of the following possibilities happens:
i. ? : 3 D, and |1i : 3 , with D  S(2 C)  S(2
S(1 A)). Then, by lemma 4.2 again, B B B B 
3 D  3 S(2 S(1 A)). So, 2 = B  A, hence,
by rule , u : A.
ii. ? : S(3 D), and |1i : S(3 ), with S(D)  S(2 C).
By Lemma 4.2 again, B B B B  S(3 D)  S(3
S(2 S(2 A))), so 2 = B  A, and hence, by rule ,
u : A.
(if0 ) Analogous to case (if1 ).
(lin+r ) Let t(u + v) : A, with t : B B. Then, by Lemma 4.2, one of the
following cases happens:
1. t : C and (u + v) : , with C  A. However, since t : B B,
we have B, which is impossible due to Corollary 4.3.
2. t : S( C) and (u + v) : S( ), with S(C)  A. Then, by
Corollary 4.3, u : S( ) and v : S( ). Hence,
t : S( C) u : S( ) t : S( C) v : S( )
ES ES
tu : S(C) tv : S(C) +
SI
(tu + tv) : S(S(C))

(tu + tv) : A

(lin
r ) Let t(.u) : A, with t : B B. Then, by Lemma 4.2, one of the
following cases happens:
1. t : C and .u : , with C  A. However, since t : B B, we
have B, which is impossible due to Corollary 4.3.
2. t : S( C) and .u : S( ), with S(C)  A. Then, by Corol-
lary 4.3, u : S( ). Hence,

t : S( C) u : S( )
ES
tu : S(C)
S
.tu : S(S(C)) I

.tu : A
Typing quantum superpositions and measurement 27

(lin0r ) Let t~0S(B) : B, with t : B A. Then, by Lemma 4.2, one of the


following cases happens:
1. t : C and ~0S(A) : , with C  A. Then, by Lemma 4.2 again,
S(A)  . However, since t : B B, B, which is impossible by
Lemma B.1.
2. t : S( C) and ~0S(A) : S( ), with S(C)  A. By rule Ax~0 ,
~0S(A) : S(C), hence we conclude by rule .
(lin+
l ) Let (t+u)v : A. Then by Lemma 4.2, one of the following cases happens:
1. (t + u) : B, which is impossible by Corollary 4.3.
2. (t + u) : S( B) and v : S( ), with S(B)  A. Then, by
Corollary 4.3, t : S( B) and u : S( B). Hence,
t : S( B) v : S( ) u : S( B) v : S( )
ES ES
tv : S(B) uv : S(B) +
SI
(tv + uv) : S(S(B))

(tv + uv) : A
(lin
l ) Let (.t)u : A. Then, by Lemma 4.2, one of the following cases happens:
1. .t : B, which is impossible by Corollary 4.3.
2. .t : S( B) and u : S( ), with S(B)  A. Then, by Corol-
lary 4.3, t : S( B). Hence,
t : S( B) u : S( )
ES
tu : S(B)
S
.tu : S(S(B)) I

.tu : A
(lin0l ) Let ~0S(BB) t : A. Then, by Lemma 4.2, one of the following cases
happens:
1. ~0S(BB) : C and t : , with C  A. Then, by Lemma 4.2
again, S(B B)  C, which is impossible by Lemma B.1.
2. ~0S(BB) : S( C) and t : S( ), with S(C)  A. By Lemma 4.2
again, S(B B)  S( C). Hence, B  C, and then S(B) 
S(C)  A. By rule Ax~0 , ~0S(B) : S(B), hence we conclude by rule .
(dist+ S(BC)
r ) Let S(S(B)C) ((r + s) u) : A. By Lemma 4.2, S(B C)  A and
(r + s) u : S(S(B) C). Then, by the same Lemma, (r + s) : D
and u : E, with D E  S(S(B) C), so D  S(B) and E  C, and
hence, (r + s) : S(B) and u : C. Then, by Corollary 4.3, r : S(B) and
s : S(B). Therefore,
r : S(B) u : C s : S(B) u : C
I I
r u : S(B) C s u : S(B) C
 
r u : S(S(B) C) s u : S(S(B) C)
S(BC)
r S(BC)
r
S(S(B)C) (r u) : S(B C) S(S(B)C) (s u) : S(B C)
SI+
(S(BC) S(BC)
S(S(B)C) (r u) + S(S(B)C) (s u)) : S(S(B C))

(S(BC) S(BC)
S(S(B)C) (r u) + S(S(B)C) (s u)) : A
28 Alejandro Daz-Caro and Gilles Dowek

(dist+ +
l ) Analogous to case (distr ).
(dist S(BC)
r ) Let S(S(B)C) ((.r) u) : A. By Lemma 4.2, S(B C)  A, and
((.r) u) : S(S(B) C). Then, by the same Lemma, .r : D and
u : E, with D E  S(S(B) C). Hence, D  S(B) and E  C, so by
rule , .r : S(B) and u : C. By Corollary 4.3, r : S(B). Therefore,

r : S(B) u : C
I
r u : S(B) C

r u : S(S(B) C)
S(BC)
r
S(S(B)C) (r u) : S(B C)
S(BC)
SI
. S(S(B)C) (r u) : S(S(B C))
S(BC)

. S(S(B)C) (r u) : A

(dist
l ) Analogous to case (distr ).
(dist0r ) Let S(S(B)C)
S(BC)
(~0S(B) u) : A. By Lemma 4.2, S(B C)  A. By rule
~
Ax~0 , 0S(BC) : S(B C). Hence, we conclude by rule .
(dist0l ) Analogous to case (dist0r ).
(dist+ S(CD)
) Let S(B) (t + u) : A. Then, by Lemma 4.2, S(C D)  A, S(CD)
S(B)

t : S(C D) and S(CD)


S(B) u : S(C D). We conclude by rules SI+ and .
(dist S(CD)
) Let S(B) (.t) : A. Then, by Lemma 4.2, S(C D)  A, and
S(B) t : S(C D). We conclude by rules SI and .
S(CD)

(neutr ) Let S(S(B)C)


S(BC)
(b r) : A, with b B. Then, by Lemma 4.2, b r :
S(S(B) C) and S(B C)  A. Then, by Lemma 4.2 again, b : D and
r : E, with D E  S(S(B) C), so D  S(B) and E  C, hence,
b : S(B) and r : E. Therefore, by Corollary B.2, b : B, and so, by rule
I , b r : B C, and by rule , b r : S(B C).
(neutl ) Analogous to case (neutr ).
(proj) Let Pj ( ni=1 [i .](b1i bmi )) : A. Then, by Lemma 4.2, we have
P
n S S\{1,...,j}
that i=1 [i .](b1i bmi ) : Q , with Q  A. Then, by
Corollary 4.3, we have for every i, N b1i bmi : QS . By Lemma 4.2 again,
S
for every k, bki : Bk , such that k Bk  Q . Since bki are either |0i or
|1i, by Lemma 4.2, for every k, B  Bk . Then,  by rules, I , , SI+ and I
Nj
again, we can derive t=1 btk iP P i
P
2
.(bj+1,i bmi ) :
iP |i |
S\{1,...,j}
Q , for any k and P such that i P , t j, bti = btk .
(comm) Let (u + v) : A. By Lemma 4.2, u : B and v : B, with S(B)  A.
So,
v:B u:B +
SI
(v + u) : S(B)

(v + u) : A
Typing quantum superpositions and measurement 29

(assoc) Let ((u + v) + w) : A. By Lemma 4.2, (u + v) : B and w : B, with


S(B)  A. Then, by Corollary 4.3, u : B and v : B. Hence,
u:B  v:B w:B +
S
u : S(B) (v + w) : S(B) I+
SI
(u + (v + w)) : S(S(B))

(u + (v + w)) : A
Contextual rules Let t (p) u. Then,
(tv (p) uv) Let tv : A. By Lemma 4.2, one of the following cases hap-
pens:
t : B and v : , with B  A. Then, by the induction
hypothesis, u : B. We conclude by rules E and .
t : S( B) and v : S( ), with S(B)  A. Then, by the
induction hypothesis, u : S( B). We conclude by rules ES
and .
((x : B v)t (p) (x : B v)u) Let (x : B v)t : A. By Lemma 4.2, one
of the following cases happens:
(x : B v) : B and t : , with B  A. Then, by the
induction hypothesis, u : . We conclude by rules E and .
(x : B v) : S( B) and t : S( ), with S(B)  A. Then,
by the induction hypothesis, u : S( ). We conclude by rules ES
and .
{1,...,j}
(j t (p) j u) Let j t : A. By Lemma 4.2, t : QSn , where Qn  A.
Then, by the induction hypothesis, u : QSn . We conclude by rules SE
and .
((t + v) (p) (u + v)) Let (t+v) : A. By Lemma 4.2, t : B and v : B,
with S(B)  A. Then, by the induction hypothesis, u : B. We conclude
by rules SI+ and .
(.t (p) .u) Let .t : A. By Lemma 4.2, t : S(B), with S(B)  A.
Then, by the induction hypothesis, u : S(B). We conclude by rules SI
and .
(t v (p) u v) Let tv : A. By Lemma 4.2, t : B and v : C, with
B C  A. Then, by the induction hypothesis, u : B. We conclude by
rules I and .
(v t (p) v u) Analogous to previous case.
(head t (p) head u) Let head t : A. By Lemma 4.2, t : B B, with
B  A. Then, by the induction hypothesis, u : B B. We conclude by
rules Er and .
(tail t (p) tail u) Let tail t : A. By Lemma 4.2, t : B B, with
B  A. Then, by the induction hypothesis, u : B B. We conclude by
rules Er and .
(S(CD)
S(B) t (p) S(CD)
S(B) u) Let S(CD)
S(B) t : A. By Lemma 4.2, t : S(B),
S(C D)  A, where either:
a rule R allows typing S(CD)
S(B) t : S(CD) starting from t : S(B).
Then, by the induction hypothesis, u : S(B), and using rule R,
S(CD)
S(B) u : S(C D). We conclude by rule .
30 Alejandro Daz-Caro and Gilles Dowek

t = .t and t : S(B). The possible reductions t (p) u are:


u = .u . By the induction hypothesis, u : S(B), and so by
some rule , S(CD)
S(B) u : S(C D). We conclude by rule .

= 1 and u = t , then by some rule , S(CD) S(B) t : S(C D).
~ ~
= 0 and u = 0S(B) . By rule Ax~0 0S(B) : S(B), and by one of
the rules , S(CD)
S(B)
~0S(B) : S(C D).
~
t = u = 0S(B) , then, by one of the rules , S(CD) S(B)
~0S(B) :
S(C D).
t = .t and u = ( ).t . By Corollary 4.3, t : S(B).
Then, by one of the rules , S(CD)
S(B) t : S(C D), and by rule
S(CD)
, S(B) ( ).t : S(C D).
t = (t1 + t2 ) and u = (.t1 + .t2 ). By the induction hypothesis
(.t1 + .t2 ) : S(B), then, by one of the rules , S(CD) S(B)

(.t1 + .t1 ) : S(C D).


In any case, we conclude by rule .
t = (t1 + t2 ) and for i = 1, 2, ti : S(B). The possible reductions
(t1 + t2 ) (p) u are:
u = (u1 + u2 ), with t1 = u1 and t2 (p) u2 or t1 (p) u1
and t2 = u2 . Then, by the induction hypothesis ui : S(B), so
by a rule , S(CD)
S(B) ui : S(C D) and by rule + , S(CD)S(B)

(u1 + u2 ) : S(C D).


t1 = ~0S(B) and u = t2 . By some rule , S(CD)S(B) t2 : S(C D).
t1 = .t , t2 = .t and u = ( + ).t . By Corollary 4.3, t :
S(B). Then, by some rule , S(CD)
S(B) t : S(C D), and by rule
S(CD)
, S(B) ( + ).t : S(C D).
t1 = .t2 and u = ( + 1).t2 . Analogous to previous case.
t1 = t2 and u = 2.t1 . Analogous to previous case.
In any case, we conclude by rule .

C Omitted proofs in Section 5 (Intepretation)

Lemma 5.1. I f A  B, then JAK JBK.

Proof. We proceed by induction on the relation .

JAK SJAK = JS(A)K.


JS(S(A))K = S(SJAK) = SJAK = JS(A)K.
Let A  B and JAK B. Then,
J AK = J K JAK
= {f | a J K, f a JAK}
{f | a J K, f a JBK}
= J K JBK
= J BK
Typing quantum superpositions and measurement 31

JA CK = JAK JCK
= {a c | a JAK, c JCK}
{b c | b JBK, c JCK}
= JBK JCK
= JB CK
JC AK JC BK by an analogous reasoning to the previous one.
JS(A)K = SJAK SJBK = JS(B)K.
Lemma 5.2. I f t : A and , x 7 S, y 7 S is a -valuation, then
JtK,x7S,y7S = J(x/y)tK,x7S .
Proof. We proceed by induction on t.
Independent cases. The cases where t does not includes x nor y and the
denotation does not depends on the valuation, are trivial. Those cases are:
|0i, |1i, ~0S(A) and ?.
Let t = x. Then, JxK,x7S,y7S = S = JxK,x7S .
Let t = y. Then, JyK,x7S,y7S = S = JxK,x7S .
Let t = z. Then, JzK,x7S,y7S = z = JzK,x7S .
Let t = z : r. Then,

Jz : rK,x7S,y7S = {f | a J K, f a JrK,x7S,y7S,z7J K }
(by IH) = {f | a J K, f a J(x/y)rK,x7S,z7J K }
= Jz : (x/y)rK,x7S
= J(x/y)z : rK,x7S
Let t = r s. Then,

Jr sK,x7S,y7S = JrK,x7S,y7S JsK,x7S,y7S


(by IH) = J(x/y)rK,x7S J(x/y)sK,x7S
= J(x/y)r (x/y)sK,x7S
= J(x/y)(r s)K,x7S
Let t = (r + s). Then,

J(r + s)K,x7S,y7S = {a + b | a JrK,x7S,y7S , b JsK,x7S,y7S }


(by IH) = {a + b | a J(x/y)rK,x7S , b J(x/y)sK,x7S }
= J((x/y)r + (x/y)s)K,x7S
= J(x/y)(r + s)K,x7S
Let t = .r. Then,

J.rK,x7S,y7S = {.a | a JrK,x7S,y7S }


(by IH) = {.a | a J(x/y)rK,x7S }
= J.(x/y)rK,x7S
= J(x/y).rK,x7S
32 Alejandro Daz-Caro and Gilles Dowek

Let t = rs. Then,

JrsK,x7S,y7S
P P
{ i gi (a) | i gi JrK,x7S,y7S , a JsK,x7S,y7S } If A = B
iI iI
= P P P P
{ i j gi (cj ) | i gi JrK,x7S,y7S , j cj JsK,x7S,y7S } If A = S( B)
iI jJ iI jJ

(by IH)
P P
{ i gi (a) | i gi J(x/y)rK,x7S , a J(x/y)sK,x7S } If A = B
iI iI
= P P P P
{ i j gi (cj ) | i gi J(x/y)rK,x7S , j cj J(x/y)sK,x7S } If A = S( B)
iI jJ iI jJ

= J(x/y)r(x/y)sK,x7S
= J(x/y)(rs)K,x7S

Let t = j r. Then,
j
!
O X i
Jj rK,x7S,y7S = { bhk pP (bj+1,i bmi) | i P, h, bhi = bhk }
h=1 iP iP |i |2

with JrK,x7S,y7S = { ni=1 i (b1i bmi )} where bih = ( 01 ) or ( 10 ).


P
By the induction hypothesis, J(x/y)rK,x7S = JrK,x7S,y7S , hence,

J(x/y)(j r)K,x7S = Jj ((x/y)r)K,x7S = Jj rK,x7S,y7S

Let t = head r. Then,

Jhead rK,x7S,y7S = {a1 | a1 an JtK,x7S,y7S , a1 JBK}


(by IH) = {a1 | a1 an J(x/y)tK,x7S , a1 JBK}
= Jhead (x/y)rK,x7S
= J(x/y)(head r)K,x7S

Let t = tail r. Then,

Jtail rK,x7S,y7S = {a2 an | a1 an JtK,x7S,y7S , a1 JBK}


(by IH) = {a2 an | a1 an J(x/y)tK,x7S , a1 JBK}
= Jtail (x/y)rK,x7S
= J(x/y)(tail r)K,x7S
S(BC)
Let t =S(A) r Then,

JS(BC)
S(A)
rK,x7S,y7S = JrK,x7S,y7S
(by IH) = J(x/y)rK,x7S
S(BC)
= JS(A) (x/y)rK,x7S
S(BC)
= J(x/y) S(A) rK,x7S
Typing quantum superpositions and measurement 33

Theorem 5.3. I f t : A, and is a -valuation. Then JtK JAK.

Proof. We proceed by induction on the typing derivation.

Let x : x : as a consequence of rule Ax.


Then, JxK = x = J K.
Let ~0S(A) : S(A) as a consequence of rule Ax~0 .
Then, J~0S(A) K = {~0} SJAK = JS(A)K.
Let |0i : B as a consequence of rule Ax|0i .
Then, J|0iK = {( 10 )} {( 10 ) , ( 01 )} = JBK.
Let |1i : B as a consequence of rule Ax|1i .
Then, J|1iK = {( 01 )} {( 10 ) , ( 01 )} = JBK.
Let t : B as a consequence of t : A, A  B and rule .
Then, by the induction hypothesis, JtK JAK and by Lemma 5.1, JAK
JBK, hence, JtK JBK.
Let .t : S(A) as a consequence of t : A and rule SI .
Then, by the induction hypothesis, JtK JAK.
Then, J.tK = {.a | a JtK } {.a | a JAK} SJAK = JS(A)K.
Let ? : B B B B as a consequence of rule If. Then,

b If a = ( 01 )
J?K = {f | a, b, c JBK, f abc = }
c If a = ( 10 )
JBK JBK JBK JBK = JB B B BK.

Let x : t : A as a consequence of , x : t : A and rule I .


Then, by the induction hypothesis, JtK,x7J K JAK. Hence,

Jx : tK = {f | a J K, f a JtK,x7J K }
{f | a J K, f a JAK}
= J K JAK = J AK.

Let , tu : A as a consequence of t : A and u : and rule


E .
Then, by the induction hypothesis JtK J K JAK and JuK J K,
where = , . Then,
X X
JtuK = { i gi (a) | i gi JtK and a JuK }
iI iI
X X
{ i gi (a) | i gi J K JAK and a J K}.
iI iI

Since J K JAK is a set of functions (and not a linear combination of them),


I is a singleton and so this set is equal to {f a | f J K JAK and a
J K} JAK.
34 Alejandro Daz-Caro and Gilles Dowek

Let , tu : S(A) as a consequence of t : S( A), u : S( ) and


rule ES .
Then, by the induction hypothesis JtK S(J K JAK) and JuK SJ K.
Then,

XX X X
JtuK = { i j gi (cj ) | i gi JtK and j cj JuK }
iI jJ iI jJ
XX X X
{ i j gi (cj ) | i gi S(J K JAK) and j cj SJ K}
iI jJ iI jJ
XX
={ i j gi (cj ) | gi J K JAK and cj J K}
iI jJ

SJAK = JS(A)K

Let , (t + u) : S(A) as a consequence of t : A, u : A and rule


SI+ .
Then, by the induction hypothesis JtK JAK and JuK JAK, with
= , . Then,

J(t+u)K = {a+b | a JtK and b JuK } {a+b | a, b JAK} SJAK = JS(A)K


S\{1,...,j}
Let j t : Qn as a consequence of t : QSn and rule SE , with
n S
S N and j n. Then, by the induction  hypothesis,  JtK JQn K.
Nj
By definition, Jj tK = { h=1 bhk iP P i
P
2
(bj+1,i
iP |i |
Pn
bmi ) | i P, h, bhi = bhk }, where JtK = { i=1 i (b1i bmi )}, with
bih JBK, and i P, hbhi = bhk . Then,

Jj tK JBK JBK JQSnj K = JQS\{1,...,j}
n K

where S is a shift of S removing the first j values.


Let , x : Q t : A as a consequence of t : A and rule W . Then, by the
induction hypothesis, JtK JAK, where is a -valuation. Notice that any
that is a (, x : B)-valuation is also a -valuation. Then, JtK JAK.
Let , x : B (x/y)t : A as a consequence of , x : B, y : B t : A and rule
C. Then, by the induction hypothesis, JtK JAK, where is a (, x :
B, y : B)-valuation. Let be a (, x : B)-valuation, then, by Lemma 5.2,
J(x/y)tK JAK.
Let , t u : A B as a consequence of t : A, u : B and rule
I . Then, by the induction hypothesis, JtK JAK and JuK JBK. Then,

Jt, uK , = JtK , JuK ,


= JtK JuK
JAK JBK
= JA BK
Typing quantum superpositions and measurement 35

Let head t : B as a consequence of t : B B and rule Er . Then, by


the induction hypothesis, JtK JB BK = JBK JBK = {a b | a JBK, b
JBK}. So,

Jhead tK = {a | a b JtK , a JBK}


= {a | a b {a b | a JBK, b JBK}}
= {a | a JBK}
= JBK

Let tail t : B as a consequence of t : B B and rule El . Then, by


the induction hypothesis, JtK JB BK = JBK JBK = {a b | a JBK, b
JBK}. So

Jtail tK = {a2 an | a1 an JtK , a1 JBK}


= {a2 an | a1 an {a b | a JBK, b JBK}}
= {b | b JBK}
= JBK
S(AB)
Let S(S(A)B) t : S(A B) as a consequence of t : S(S(A) B) and
rule r . Then,
S(AB)
JS(S(A)B) tK = JtK
(by IH) JS(S(A) B)K
= S(SJAK JBK)
= S(JAK JBK)
= JS(A B)K
S(AB)
Let S(AS(B)) t : S(A B) as a consequence of t : S(A S(B)) and
rule l . This case is analogous to the previous one.
S(A)
Let S(B) S(A)
.t : S(A) as a consequence of S(B) t : S(A) and rule .
S(A)
Then, by the induction hypothesis, JS(B) tK = JtK JS(A)K = SJAK. So,
S(A)
JS(B) .tK = J.tK
= {.a | a JtK }
{.a | a SJAK}
SJAK
= JS(A)K
S(A) S(A) S(A)
Let , S(B) (t + r) : S(A) as a consequence of S(B) t : S(A), S(B)
+ S(A)
r : S(A) and rule . Then, by the induction hypothesis, JS(B) tK =
S(A)
JtK JS(A)K = SJAK and JS(B) rK = JrK JS(A)K = SJAK. So, if
= , ,
S(A)
JS(B) (t + r)K
36 Alejandro Daz-Caro and Gilles Dowek

= J(t + r)K
= {a + b | a JtK and b JrK }
= {a + b | a JtK and b JrK }
{a + b | a, b SJAK}
SJAK
= JS(A)K
P
S I f t : A, is a -valuation, and t (pi ) ri , with
Theorem 5.4. i pi = 1,
then JtK = i Jri K .

Proof. We proceed by induction on the rewrite relation.

(b ) and (n ) Let (x : t)u : A, with u : , where, if = B, then u B.


Then by Lemma 4.2, one of the following possibilities happens:
1. x : t : B and u : , with B  A, or Thus, J(x : t)uK =
{f (a) | a JuK } JtK,x7J K .

2. x : t : S(P B) and Pu : S( ), with S(B)  A. Thus,
J(x : t)uK = { jJ j f (cj ) | jJ j cj JuK } JtK,x7J K .
In any case, by Lemma 5.2, JtK,x7J K = J(u/x)tK .
Other cases All the remaining cases are straightforward by the algebraic na-
ture of the interpretation.

D Trace and typing of the Deutsch algorithm

As usual in quantum computing, we may use |q1 qn i as a shorthand notation


for |q1 i |qn i.
The full trace of Deutschid is given below. 2 stands for S(BB)
S(BS(B)) and 12 for
2

S(BS(B))
S(S(B)S(B)) .

Deutschid
= 1 (S(BB)
S(S(B)B) H1 (Uf 2 212 (Hboth |01i)))
( )
b(1) 1 (S(BB)
S(S(B)B)
H1 (Uid 2 212 ((H(head |01i)) (H(tail |01i)))))
(head) 2
(1) 1 (S(BB)
S(S(B)B) H1 (Uid 2 12 ((H |0i) (H(tail |01i)))))
(tail) 2
(1) 1 S(BB)
S(S(B)B) H1 (Uid 2 12 ((H |0i) (H |1i)))

( )2 1 1
b (1) 1 (S(BB) 2
S(S(B)B) H1 (Uid 2 12 (
.(|0i + (|0i?( |1i)|1i)) .(|0i + (|1i?( |1i)|1i)))))
2 2
(if0 ) 1 1
(1) 1 (S(S(B)B) H1 (Uid 2 12 ( .(|0i + |1i) .(|0i + (|1i?( |1i)|1i)))))
S(BB) 2

2 2
(if1 ) 1 1
(1) 1 (S(BB) 2
S(S(B)B) H1 (Uid 2 12 (
.(|0i + |1i) .(|0i |1i))))
2 2
(dist ) 1 1
r(1) 1 (S(S(B)B) H1 (Uid S(BS(B)) . S(S(B)S(B)) ((|0i + |1i) .(|0i |1i))))
S(BB) S(BB) S(BS(B))

2 2
Typing quantum superpositions and measurement 37

+
(dist ) 1 1
r(1) 1 (S(BB)
S(S(B)B)
H1 (Uid S(BB)
S(BS(B))
. (S(BS(B))
S(S(B)S(B))
|0i .(|0i |1i)
2 2
1
+S(BS(B))
S(S(B)S(B))
|1i .(|0i |1i))))
2

(neutr ) 1 1
(1) 1 (S(S(B)B) H1 (Uid S(BS(B)) . (|0i .(|0i |1i)
S(BB) S(BB)

2 2
1
+|1i .(|0i |1i))))
2
(dist ) 1 1
(1) 1 (S(S(B)B) H1 (Uid . S(BS(B)) (|0i .(|0i |1i)
S(BB) S(BB)

2 2
1
+|1i .(|0i |1i))))
2
+
(dist ) 1 1
(1) 1 (S(BB)
S(S(B)B) H1 (Uid
. ( S(BB)
S(BS(B)) (|0i
.(|0i |1i))
2 2
1
+ S(BS(B)) (|1i .(|0i |1i)))))
S(BB)

2
(dist )2 1 1
l (1) 1 (S(BB)
S(S(B)B) H1 (Uid
. ( . S(BB)S(BS(B)) (|0i (|0i |1i))
2 2
1
+ . S(BB)
S(BS(B))
(|1i (|0i |1i)))))
2
(dist) 1 1
(1) 1 (S(BB)
S(S(B)B)
H1 (Uid ( . . S(BB)S(BS(B))
(|0i (|0i |1i))
2 2
1 1
+ . . S(BB)S(BS(B))
(|1i (|0i |1i)))))
2 2
(prod) 1
(1) 1 (S(S(B)B)
S(BB)
H1 (Uid ( . S(BB) (|0i (|0i |1i))
2 S(BS(B))
1
+ . S(BB) (|1i (|0i |1i)))))
2 S(BS(B))
+
(dist )2 1
l (1) 1 (S(S(B)B)
S(BB)
H1 (Uid ( .(S(BB) |00i + S(BB)
S(BS(B)) |0i ( |1i))
2 S(BS(B))
1
+ .(S(BB) |10i + S(BB)
S(BS(B)) |1i ( |1i)))))
2 S(BS(B))
(dist )2 1
l (1) 1 (S(BB)
S(S(B)B) H1 (Uid ( .(S(BB) |00i S(BB)
S(BS(B)) |01i)
2 S(BS(B))
1
+ .(S(BB) |10i S(BB) |11i))))
2 S(BS(B)) S(BS(B))


(neut )4 1 1
l (1) 1 (S(BB)
S(S(B)B)
H1 (Uid ( .(|00i |01i) + .(|10i |11i))))
2 2
+
(lin ) 1 1
r (1) 1 (S(BB)
S(S(B)B)
H1 (Uid .(|00i |01i) + Uid .(|10i |11i)))
2 2
(lin )2 1 1
S(S(B)B) H1 ( .Uid (|00i |01i) +
r (1) 1 (S(BB) .Uid (|10i |11i)))
2 2
38 Alejandro Daz-Caro and Gilles Dowek

+
(lin )2 1 1
r (1) 1 (S(BB)
S(S(B)B)
H1 ( .(Uid |00i + Uid ( |01i)) + .(Uid |10i + Uid ( |11i))))
2 2
(lin
r )
2 1 1
(1) 1 (S(S(B)B) H1 ( .(Uid |00i Uid |01i) + .(Uid |10i Uid |11i)))
S(BB)

2 2
(b ) 1
(1) 1 (S(S(B)B) H1 ( .((head |00i) ((tail |00i)?(not(id(head |00i)))(id(head |00i)))
S(BB)

2
1
Uid |01i) + .(Uid |10i Uid |11i)))
2
(head)3 S(BB)
1
(1) 1 (S(S(B)B) H1 ( .(|0i ((tail |00i)?(not(id |0i)))(id |0i))
2
1
Uid |01i) + ( .(Uid |10i Uid |11i)))
2
(tail) 1
(1) 1 (S(S(B)B) H1 ( .(|0i (|0i?(not(id |0i)))(id |0i))
S(BB)

2
1
Uid |01i) + ( .(Uid |10i Uid |11i)))
2
(if0 ) 1 1
(1) 1 (S(S(B)B) H1 ( .(|0i (id |0i) Uid |01i) + .(Uid |10i Uid |11i)))
S(BB)

2 2
(b ) S(BB)
1 1
(1) 1 (S(S(B)B) H1 ( .(|00i Uid |01i) + .(Uid |10i Uid |11i)))
2 2
S(BB)
1 1
(1) 1 (S(S(B)B) H1 ( .(|00i |01i) + .(|11i |10i)))
2 2
+
(linr ) 1 1
(1) 1 (S(S(B)B) (H1 .(|00i |01i) + H1 .(|11i |10i)))
S(BB)

2 2
(lin
r )
2 1 1
(1) 1 (S(S(B)B) ( .H1 (|00i |01i) + .H1 (|11i |10i)))
S(BB)

2 2
+
(linr )2 1 1
(1) 1 (S(S(B)B) ( .(H1 |00i + H1 ( |01i)) + .(H1 |11i + H1 ( |10i))))
S(BB)

2 2
(lin
r )
2 1 1
(1) 1 (S(S(B)B) ( .(H1 |00i H1 |01i) + .(H1 |11i H1 |10i)))
S(BB)

2 2
(b ) S(BB)
1 1
(1) 1 (S(S(B)B) ( .((H(head |00i)) (tail |00i) H1 |01i) + .(H1 |11i H1 |10i)))
2 2
(head) 1 1
(1) 1 (S(S(B)B) ( .((H |0i) (tail |00i) H1 |01i) + .(H1 |11i H1 |10i)))
S(BB)

2 2
(tail) 1 1
(1) 1 (S(S(B)B) ( .((H |0i) |0i H1 |01i) + .(H1 |11i H1 |10i)))
S(BB)

2 2
(b ) 1 1 1
(1) 1 (S(S(B)B) ( .(( .(|0i + |0i?( |1i)|1i)) |0i H1 |01i) + .(H1 |11i H1 |10i)))
S(BB)

2 2 2
(if0 ) 1 1 1
(1) 1 (S(BB)
S(S(B)B)
( .(( .(|0i + |1i)) |0i H1 |01i) + .(H1 |11i H1 |10i)))
2 2 2
+
(dist ) 1 1 1 1
(1) 1 (S(BB)
S(S(B)B)
.(( . |0i + . |1i) |0i H1 |01i) + S(BB)
S(S(B)B)
.(H1 |11i H1 |10i))
2 2 2 2
(dist )2 1 1 1 1
(1) 1 ( . S(BB) (( . |0i + . |1i) |0i H1 |01i) + . S(BB) (H1 |11i H1 |10i))
2 S(S(B)B) 2 2 2 S(S(B)B)
Typing quantum superpositions and measurement 39

+
(dist ) 1 1 1
(1) 1 ( .(S(BB)
S(S(B)B)
(( . |0i + . |1i) |0i) + S(BB)S(S(B)B)
(H1 |01i))
2 2 2
1
+ . S(BB) (H1 |11i H1 |10i))
2 S(S(B)B)
(dist ) 1 1 1
(1) 1 ( .(S(BB) (( . |0i + . |1i) |0i) S(BB) H1 |01i)
2 S(S(B)B) 2 2
S(S(B)B)

1
+ . S(BB) (H1 |11i H1 |10i))
2 S(S(B)B)
+
(dist ) 1 1 1
r(1) 1 ( .((S(BB)
S(S(B)B)
( . |0i) |0i + S(BB)
S(S(B)B)
( . |1i) |0i) S(BB)
S(S(B)B)
H1 |01i)
2 2 2
1
+ . S(BB) (H1 |11i H1 |10i))
2 S(S(B)B)
(dist )2 1 1 1
r (1) 1 ( .(( . S(BB)
S(S(B)B)
|00i + . S(BB)
S(S(B)B)
|10i) S(BB)
S(S(B)B)
H1 |01i)
2 2 2
1
+ . S(BB) (H1 |11i H1 |10i))
2 S(S(B)B)

(neut )2 1 1 1 1 S(BB)
r (1) 1 ( .(( . |00i + . |10i) S(BB) S(S(B)B) H1 |01i) + . (H1 |11i H1 |10i))
2 2 2 2 S(S(B)B)
1 1 1 1 1
(1) 1 ( .((( . |00i + . |10i) + ( . |01i . |11i))
2 2 2 2 2
1 1 1 1
+(( . |01i . |11i) + ( . |00i + . |10i))))
2 2 2 2
1 1 1 1 1
=AC 1 ( .((( . |00i . |00i) + ( . |01i + . |01i))
2 2 2 2 2
1 1 1 1
+(( . |11i . |11i) + ( . |10i + . |10i))))
2 2 2 2
(fact)4 1 1 1 1 1
(1) 1 ( .((( ). |00i + ( + ). |01i)
2 2 2 2 2
1 1 1 1
+(( ). |11i + ( + ). |10i)))
2 2 2 2
1 2 2
= 1 ( .((0. |00i + 0. |01i) + ( . |11i + . |10i)))
2 2 2
(zero )2 1 ~ 2 2
(1) 1 ( .((0S(BB) + ~0S(BB) ) + ( . |11i + . |10i)))
2 2 2
(neutral)2 1 2 2
(1) 1 ( .( . |11i + . |10i))
2 2 2
(dist) 1 2 1 2
(1) 1 ( .( ). |11i + . . |10i)
2 2 2 2
(prod) 2 1 1
(1) 1 ( . |11i + . |10i)
2 2
1 1
=AC 1 ( . |10i . |11i)
2 2
40 Alejandro Daz-Caro and Gilles Dowek

(proj) 1 1
(1) |1i ( . |0i . |1i)
2 2
The typing of Deutschf , for any f : B B, is given below:

If Ax
? : B B B B x : B x : B E Ax|1i
x : B x? : B B B  |1i : B
S Ax|1i
x : B x? : S(B B B) |1i : S(B) I |1i : B
Ax|0i ES 
|0i : B x : B x?( |1i) : S(B B) |1i : S(B)
 ES
|0i : S(B) x : B x?( |1i)|1i : S(B) +
SI
x : B |0i + x?( |1i)|1i : S(S(B))
SI
x : B 12 .(|0i + x?( |1i)|1i) : S(S(S(B)))

x : B 12 .(|0i + x?( |1i)|1i) : S(B)
I
H : B S(B)
(2)

(2) Ax
x:BBx:BB
E Ax
H : B S(B) x : B B head x : B r
E y : B B y : B B El
x : B B H (head x) : S(B) y : B B tail y : B
I
x : B B, y : B B (H (head x)) (tail y) : S(B) B
C
x : B B (H (head x)) (tail x) : S(B) B
I
H1 : B B S(B) B (3)

If Ax
? : B B B B x : B x : B E Ax|0i
x : B x? : B B B |0i : B
E Ax|1i
x : B x?|0i : B B |1i : B
E
x : B x?|0i|1i : B
I
not : B B
(4)

Ax
z :BBz :BB
Ax (4) f : B B z : B B head z : B
Er
y :BBy :BB E
If El
? : B B B B A y : B B tail y : B not : B B z : B B f (head z) : B
E E
y : B B (tail y)? : B B B z : B B not (f (head z)) : B Ax
E z :BB z : BB
Er
y : B B, z : B B (tail y)?(not (f (head z))) : B B f : B B z : B B head z : B
C E
y : B B (tail y)?(not (f (head y))) : B B z : B B f (head z) : B
E
y : B B, z : B B (tail y)?(not (f (head y)))(f (head z)) : B
C
y : B B (tail y)?(not (f (head y)))(f (head y)) : B
(5)
Typing quantum superpositions and measurement 41

Ax (5)
x:BBx:BB
Er
x : B B head x : B y : B B (tail y)?(not (f (head y)))(f (head y)) : B
I
x : B B, y : B B (head x) (tail y)?(not (f (head y)))f (head y) : B B
C
x : B B (head x) (tail x)?(not (f (head x)))f (head x) : B B
I
Uf : B B B B
(6)

(2) Ax (2) Ax
x :BB x: BB y :BB y :BB
Er El
H : B S(B) x : B B head x : B H : B S(B) y : B B tail y : B
E E
x : B B H (head x) : S(B) y : B B H (tail y) : S(B)
I
x : B B, y : B B (H (head x)) (H (tail y)) : S(B) S(B)
C Ax|0i Ax|1i
x : B B (H (head x)) (H (tail x)) : S(B) S(B) |0i : B |1i : B
I I
Hboth : B B S(B) S(B) |01i : B B
E
Hboth |01i : S(B) S(B)
(7)

(7)
Hboth |01i : S(B) S(B)

(6) Hboth |01i : S(S(B) S(B))
r
(3) Uf : B B B B 212 B S(B)Hboth |01i : S(B S(B))
 l
H1 : B B S(B) B Uf : S(B B B B) 2 212 Hboth |01i : S(B B)
 ES
H1 : S(B B S(B) B) Uf (2 212 Hboth |01i) : S(B B)
ES
H1 (Uf 2 212 Hboth |01i) : S(S(B) B)
r
S(BB)
S(S(B)B) H1 (Uf 2 12 Hboth |01i) : S(B B)
2

SE
Deutschf : B S(B)

E Trace and typing of the Teleportation algorithm

The full trace of Teleportation (. |0i + . |1i) is given below.


Let 3 =S(BBB)
S(BBS(B)) , 23 S(BS(BB))
123 =S(S(B)S(BB)) , 23 =S(BBB)
S(BS(BB))
S(BBB)
and 1 =S(S(B)BB) .

Teleportation (. |0i + . |1i)


= (q : S(B) (Bob 3 (Alice (q 00 )))) (. |0i + . |1i)
(n )
(1) Bob 3 (Alice ((. |0i + . |1i) 00 ))
( )
n(1) Bob 3 (2 (1 H31 (cnot312 23 23
123
(. |0i + . |1i) 00 )))
+
r(1) Bob 3 (2 (1 H31 (cnot312 23 (23
(dist ) 23
123 (. |0i 00) + 123 (. |1i 00 )))))
42 Alejandro Daz-Caro and Gilles Dowek
+
(1) Bob 3 (2 (1 H31 (cnot312 (23 23
(dist ) 23
123 (. |0i 00 ) + 23 123 (. |1i 00 )))))
(dist 2
r )
(1) Bob 3 (2 (1 H31 (cnot312 (23 . 23 23
123 (|0i 00 ) + 23 . 123 (|1i 00 )))))

(neut )2
r (1) Bob 3 (2 (1 H31 (cnot312 (23 .(|0i 00 ) + 23 .(|1i 00 )))))
(dist )2
(1) Bob 3 (2 (1 H31 (cnot312 (. 23 (|0i 00 ) + . 23 (|1i 00 )))))
+
(dist )2 1
l (1) Bob 3 (2 (1 H31 (cnot312 (.(23 (|0i ( . |00i))
2
1
+(23 (|0i . |11i)))
2
1
+.(23 (|1i ( . |00i))
2
1
+(23 (|1i . |11i)))))))
2
4 1 1
l (1) Bob 3 (2 (1 H31 (cnot312 (.( . 23 |000i + . 23 |011i)
(dist )

2 2
1 1
+.( . 23 |100i + . 23 |111i)))))
2 2

(neut )4 3 3 1 1
l (1) Bob 3 (2 (1 H1 (cnot12 (.( . |000i + . |011i)
2 2
1 1
+.( . |100i + . |111i)))))
2 2
(dist)2 3 3 1 1
(1) Bob 3 (2 (1 H1 (cnot12 ((. . |000i + . . |011i)
2 2
1 1
+(. . |100i + . . |111i)))))
2 2
(prod)4 3 3
(1) Bob 3 (2 (1 H1 (cnot12 (( . |000i + . |011i)
2 2

+( . |100i + . |111i)))))
2 2
+
(linr )3
(1) Bob 3 (2 (1 H1 ((cnot12 . |000i + cnot312 . |011i)
3 3
2 2

+(cnot312 . |100i + cnot312 . |111i))))
2 2
(lin
r )
4
3 3 3
(1) Bob 3 (2 (1 H1 (( .cnot12 |000i + .cnot12 |011i)
2 2

+( .cnot12 |100i + .cnot312 |111i))))
3
2 2
Typing quantum superpositions and measurement 43

( )4
b (1) Bob 3 (2 (1 H31 (( .((cnot (head |000i (head tail |000i))) (tail tail |000i))
2

+ .((cnot (head |011i (head tail |011i))) (tail tail |011i)))
2

+( .((cnot (head |100i (head tail |100i))) (tail tail |100i))
2

+ .((cnot (head |111i (head tail |111i))) (tail tail |111i))))))
2
(tail)12 3
(1) Bob 3 (2 (1 H1 (( .((cnot (head |000i (head |00i))) (|0i))
2

+ .((cnot (head |011i (head |11i))) (|1i)))
2

+( .((cnot (head |100i (head |00i))) (|0i))
2

+ .((cnot (head |111i (head |11i))) (|1i))))))
2
(head)8 3
(1) Bob 3 (2 (1 H1 (( .((cnot |00i) (|0i))
2

+ .((cnot |01i) (|1i)))
2

+( .((cnot |10i) (|0i))
2

+ .((cnot |11i) (|1i))))))
2
(b )4 3
(1) Bob 3 (2 (1 H1 ((( .(((head |00i) ((head |00i)?(not(tail |00i))(tail |00i))) |0i)
2

+ .(((head |01i) ((head |01i)?(not(tail |01i))(tail |01i))) |1i))
2

+( .(((head |10i) ((head |10i)?(not(tail |10i))(tail |10i))) |0i)
2

+ .(((head |11i) ((head |11i)?(not(tail |11i))(tail |11i))) |1i))))))
2
(head)8 3
(1) Bob 3 (2 (1 H1 ((( .((|0i (|0i?(not(tail |00i))(tail |00i))) |0i)
2

+ .((|0i (|0i?(not(tail |01i))(tail |01i))) |1i))
2

+( .((|1i (|1i?(not(tail |10i))(tail |10i))) |0i)
2

+ .((|1i (|1i?(not(tail |11i))(tail |11i))) |1i))))))
2
44 Alejandro Daz-Caro and Gilles Dowek

(if )2
1 (1) Bob 3 (2 (1 H31 ((( .((|0i (|0i?(not(tail |00i))(tail |00i))) |0i)
2

+ .((|0i (|0i?(not(tail |01i))(tail |01i))) |1i))
2

+( .((|1i (not(tail |10i))) |0i)
2

+ .((|1i (not(tail |11i))) |1i))))))
2
(if0 )2 3
(1) Bob 3 (2 (1 H1 ((( .((|0i (tail |00i)) |0i)
2

+ .((|0i (tail |01i)) |1i))
2

+( .((|1i (not(tail |10i))) |0i)
2

+ .((|1i (not(tail |11i))) |1i))))))
2
(tail)4 3
(1) Bob 3 (2 (1 H1 ((( .((|0i |0i) |0i)
2

+ .((|0i |1i) |1i))
2

+( .((|1i (not |0i)) |0i)
2

+ .((|1i (not |1i)) |1i))))))
2
(b )2 3
(1) Bob 3 (2 (1 H1 ((( .(|0i |0i |0i)
2

+ .(|0i |1i |1i))
2

+( .(|1i (|0i?|0i|1i) |0i)
2

+ .(|1i (|1i?|0i|1i) |1i))))))
2
(if0 ) 3
(1) Bob 3 (2 (1 H1 ((( .(|0i |0i |0i)
2

+ .(|0i |1i |1i))
2

+( .(|1i |1i |1i)
2

+ .(|1i (|1i?|0i|1i) |1i))))))
2
(if )
1(1) Bob 3 (2 (1 H31 ((( . |000i + . |011i) + ( . |110i + . |101i)))))
2 2 2 2
Typing quantum superpositions and measurement 45

+
(lin )3
r (1) Bob 3 (2 (1 ((H31 ( . |000i) + H31 ( . |011i)) + (H31 ( . |110i) + H31 ( . |101i)))))
2 2 2 2
(lin 4
r (1) Bob 3 (2 (1 (( .H31 |000i + .H31 |011i) + ( .H31 |110i + .H31 |101i))))
)

2 2 2 2
(b )4
(1) Bob 3 (2 (1 (( .((H(head |000i)) (tail |000i)) + .((H(head |011i)) (tail |011i)))
2 2

+( .((H(head |110i)) (tail |110i)) + .((H(head |101i)) (tail |101i))))))
2 2
(head)4
(1) Bob 3 (2 (1 (( .((H |0i) (tail |000i)) + .((H |0i) (tail |011i)))
2 2

+( .((H |1i) (tail |110i)) + .((H |1i) (tail |101i))))))
2 2
(tail)4
(1) Bob 3 (2 (1 (( .((H |0i) |00i) + .((H |0i) |11i))
2 2

+( .((H |1i) |10i) + .((H |1i) |01i)))))
2 2
(b )4 1
(1) Bob 3 (2 (1 ( .( .(|0i + (|0i?( |1i)|1i)) |00i)
2 2
1
+ .( .(|0i + (|0i?( |1i)|1i)) |11i)
2 2
1
+( .( .(|0i + (|1i?( |1i)|1i)) |10i)
2 2
1
+ .( .(|0i + (|1i?( |1i)|1i)) |01i)))))
2 2
(if0 )2 1
(1) Bob 3 (2 (1 (( .( .(|0i + |1i) |00i)
2 2
1
+ .( .(|0i + |1i) |11i))
2 2
1
+( .( .(|0i + (|1i?( |1i)|1i)) |10i)
2 2
1
+ .( .(|0i + (|1i?( |1i)|1i)) |01i)))))
2 2
(if1 )2 1 1
(1) Bob 3 (2 (1 (( .( .(|0i + |1i) |00i) + .( .(|0i + |1i) |11i))
2 2 2 2
1 1
+( .( .(|0i |1i) |10i) + .( .(|0i |1i) |01i)))))
2 2 2 2
+
(dist )3 1 1
(1) Bob 3 (2 ((1 .( .(|0i + |1i) |00i) + 1 .( .(|0i + |1i) |11i))
2 2 2 2
1 1
+(1 .( .(|0i |1i) |10i) + 1 .( .(|0i |1i) |01i))))
2 2 2 2
46 Alejandro Daz-Caro and Gilles Dowek

(dist )4 1 1
(1) Bob 3 (2 (( . 1 ( .(|0i + |1i) |00i) + . 1 ( .(|0i + |1i) |11i))
2 2 2 2
1 1
+( . 1 ( .(|0i |1i) |10i) + . 1 ( .(|0i |1i) |01i))))
2 2 2 2
(dist
r )
4 1 1
(1) Bob 3 (2 (( . . 1 (|0i + |1i) |00i + . . 1 (|0i + |1i) |11i)
2 2 2 2
1 1
+( . . 1 (|0i |1i) |10i + . . 1 (|0i |1i) |01i)))
2 2 2 2
(prod)4
(1) Bob 3 (2 (( . 1 (|0i + |1i) |00i + . 1 (|0i + |1i) |11i)
2 2

+( . 1 (|0i |1i) |10i + . 1 (|0i |1i) |01i)))
2 2
+
(distr )4
(1) Bob 3 (2 (( .(1 |000i + 1 |100i) + .(1 |011i + 1 |111i))
2 2

+( .(1 |010i + 1 ( |110i)) + .(1 |001i + 1 ( |101i)))))
2 2
(dist )2
r (1) Bob 3 (2 (( .(1 |000i + 1 |100i) + .(1 |011i + 1 |111i))
2 2

+( .(1 |010i 1 |110i) + .(1 |001i 1 |101i))))
2 2

(neutr )8
(1) Bob 3 (2 (( .(|000i + |100i) + .(|011i + |111i))
2 2

+( .(|010i |110i) + .(|001i |101i))))
2 2
(dist)4
(1) Bob 3 (2 ((( . |000i + . |100i) + ( . |011i + . |111i))
2 2 2 2

+(( . |010i + .( |110i)) + ( . |001i + .( |101i)))))
2 2 2 2
(prod)2
(1) Bob 3 (2 ((( . |000i + . |100i) + ( . |011i + . |111i))
2 2 2 2

+(( . |010i . |110i) + ( . |001i . |101i))))
2 2 2 2

=AC Bob 3 (2 ((( . |000i + . |001i) + ( . |011i + . |010i))
2 2 2 2

+(( . |100i . |101i) + ( . |111i . |110i))))
2 2 2 2
The next rewrite step following rule (proj), may produce one of the following
four results probability 41 each:
(00) Bob 3 |00i (. |0i + . |1i)
(01) Bob 3 |01i (. |1i + . |0i)
(10) Bob 3 |01i (. |0i . |1i)
(11) Bob 3 |11i (. |1i . |0i)
So, in general, Bob 3 |xyi (. |zi + []. |wi). Then,
Bob 3 |xyi (. |zi + []. |wi)
Typing quantum superpositions and measurement 47
+
(dist )
l(1) Bob(3 |xyi . |zi + 3 |xyi []. |wi)
(dist 2
l )
(1) Bob (. 3 |xyzi + []. 3 |xywi)

(neut )2
l (1) Bob (. |xyzi + []. |xywi)
+
(lin )
r (1) (Bob . |xyzi + Bob []. |xywi)
(lin )
r (1) (.Bob |xyzi + [].Bob |xywi)
( )2
b (1) (.Zhead|xyzi (nothead tail|xyzi
(tail tail |xyzi))
head|xywi head tail|xywi
+ [].Z (not (tail tail |xywi)))
(tail)6 head|xyzi head|yzi
(1) (.Z (not (|zi)) + [].Zhead|xywi (nothead|ywi (|wi)))
(head)4
(1) (.Z|xi (not|yi |zi) + [].Z|xi (not|yi |wi))
( )4
b (1) (.Z|xi (|yi?not |zi|zi) + [].Z|xi (|yi?not |wi|wi))

Cases:

(00) (.Z|0i (|0i?not |0i|0i) + .Z|0i (|0i?not |1i|1i))


(if )2
0 (1) (.Z|0i |0i + .Z|0i |1i)
( )4
b (1) (.|0i?(Z |0i)|0i + .|0i?(Z |1i)|1i)
(if )2
0 (1) (. |0i + . |1i)

(01) (.Z|0i (|1i?not |1i|1i) + .Z|0i (|1i?not |0i|0i))


(if )2
1 (1) (.Z|0i (not |1i) + .Z|0i (not |0i))
( )2
b (1) (.Z|0i (|1i?|0i|1i) + .Z|0i (|0i?|0i|1i))
1(1) (.Z|0i |0i + .Z|0i (|0i?|0i|1i))
(if )

0(1) (.Z|0i |0i + .Z|0i |1i)


(if )

( )4
b (1) (.|0i?(Z |0i)|0i + .|0i?(Z |1i)|1i)
(if )2
0 (1) (. |0i + . |1i)
(10) (.Z|1i (|0i?not |0i|0i) .Z|1i (|0i?not |1i|1i))
(if )2
0 (1) (.Z|1i |0i .Z|1i |1i)
( )4
b (1) (.|1i?(Z |0i)|0i .|1i?(Z |1i)|1i)
(if )2
1 (1) (.Z |0i .Z |1i)
( )2
b (1) (.|0i?( |1i)|0i .|1i?( |1i)|0i)
(if )
0(1) (. |0i .|1i?( |1i)|0i)
(if )
1(1) (. |0i .( |1i))
(prod)
(1) (. |0i + . |1i)
48 Alejandro Daz-Caro and Gilles Dowek

(11) (.Z|1i (|1i?not |1i|1i) .Z|1i (|1i?not |0i|0i))


(if )2
1 (1) (.Z|1i (not |1i) .Z|1i (not |0i))
( )2
b (1) (.Z|1i (|1i?|0i|1i) .Z|1i (|0i?|0i|1i))
1(1) (.Z|1i |0i .Z|1i (|0i?|0i|1i))
(if )

0(1) (.Z|1i |0i .Z|1i |1i)


(if )

( )4
b (1) (.|1i?(Z |0i)|0i .|1i?(Z |1i)|1i)
(if )2
1 (1) (.Z |0i + .Z |1i)
( )2
b (1) (.|0i?( |1i)|0i .|1i?( |1i)|0i)
(if )
0(1) (. |0i .|1i?( |1i)|0i)
(if )
1(1) (. |0i .( |1i))
(prod)
(1) (. |0i + . |1i)

Hence, in every case, Teleportation (. |0i + . |1i) (1) (. |0i + . |1i) as


expected.

The typing of Teleportation is given below:

If Ax
? : B B B B y:By:B Ax|1i
E
y : B y? : B B B |1i : B
 S Ax|0i
y : B y? : S(B B B) |1i : S(B) I |0i : B
ES 
y : B y?( |1i) : S(B B) |0i : S(B)
ES
y : B y?( |1i)|0i : S(B)
I Ax
Z : B S(B) x:Bx:B
E
x : B Zx : S(B)
(8)

If Ax
? : B B B B y:By:B
E
y : B y? : B B B (8)
 Ax
y : B y? : S(B B B) w : B Zw : S(B) v:Bv:B 
ES
y : B, w : B y?Zw : S(B B) v : B v : S(B)
ES
y : B, w : B, v : B y?Zwv : S(B)
C
y : B, w : B y?Zww : S(B)
I
y : B w : B y?Zww : B S(B) Ax
I x:BBBx:BBB
Er
y : B w : B y?Zww : B B S(B) x : B B B head x : B
E
x : B B B Z(head x) : B S(B)
(9)
Typing quantum superpositions and measurement 49

(4)
If Ax Ax
? : B B B B y:By:B
E not : B B z : B z : B E
y : B y? : B B B z : B not z : B
E Ax
y : B, z : B y?not z : B B w:Bw:B
E
y : B, z : B, w : B y?not zw : B
C Ax
y : B, z : B y?not zz : B x :BBB x:BBB
I E
y : B z : B y?not zz : B B x : B B B tail x : B B l
I Er
y : B z : B y?not zz : B B B x : B B B head tail x : B
E
x : B B B not(head tail x) : B B
(10)

Ax
x:BBB x :BBB
(10) E
x : B B B tail x : B B l
(tail y) El
y : B B B not : B B x : B B B tail tail x : B
E
(9) x : B B B, y : B B B not(tail y) (tail tail x) : B
C
y : B B B Zhead y) : B S(B) x : B B B not(tail x) (tail tail x) : B
E
x : B B B, y : B B B Zhead y) (not(head tail x) (tail tail x)) : S(B)
C
x : B B B Zhead x) (not(head tail x) (tail tail x)) : S(B)
I
Bob : B B B S(B)
(11)

(2) Ax
x:BBB x :BBB
H : B S(B) x : B B B head x : B
Er Ax
E y :BBB y :BBB
El
x : B B B H(head x) : S(B) y : B B B tail y : B B
I
x : B B B, y : B B B (H(head x)) (tail y) : S(B) B B
C
x : B B B (H(head x)) (tail x) : S(B) B B
I
H31 : B B B S(B) B B
(12)
50 Alejandro Daz-Caro and Gilles Dowek

Ax Ax
x:BBx:BB (4) y :BBy :BB
If Er El
? : B B B B x : B B head x : B not : B B y : B B tail y : B
E E
x : B B (head x)? : B B B y : B B not(tail y) : B
E Ax
x : B B, y : B B (head x)?not(tail y) : B B y :BB y : BB
C El
x : B B (head x)?not(tail x) : B B y : B B tail y : B
Ax E
y :BB y :BB x : B B, y : B B (head x)?not(tail x)(tail y) :B
Er C
y : B B head y : B x : B B (head x)?not(tail x)(tail x) : B
I
x : B B, y : B B (heady) ((head x)?not(tail x)(tail x)) : B B
C
x : B B (headx) ((head x)?not(tail x)(tail x)) : B B
I
cnot : B B B B
(13)

Ax
y :BBBy :BBB
Ax El
x:BBB x :BBB y : B B B tail y : B B
Er Er
x : B B B head x : B y : B B B head tail y : B
I Ax
(13) x : B B B, y : B B B (head x) (head tail y) : B B y :BBBy :BBB
C El
cnot : B B B B x : B B B (head x) (head tail x) : B B y : B B B tail y : B B
E El
x : B B B cnot((head x) (head tail x)) : B B y : B B B tail tail y : B
I
x : B B B, y : B B B (cnot((head x) (head tail x))) (tail tail x) : B B B
C
x : B B B (cnot((head x) (head tail x))) (tail tail x) : B B B
I
cnot312 : B B B B B B
(14)

Ax
x : S(B) S(B B) x : S(B) S(B B)

(14) x : S(B) S(B B) x : S(S(B) S(B B))
r
cnot312 : B B B B B B x : S(B) S(B B) 23 123
x : S(B S(B B))
 l
cnot312 : S(B B B B B B) x : S(B) S(B B) 23 23 123 x : S(B B B)
ES
x : S(B) S(B B) cnot312 23 23
123 x : S(B B B)
(15)

(12)
H31 : B B B S(B) B B (15)

H31 : S(B B B S(B) B B) x : S(B) S(B B) cnot312 23 23
123 x : S(B B B)
ES
x : S(B) S(B B) H31 (cnot312 23 23
123 x) : S(S(B) B B)
r
x : S(B) S(B B) 1 H31 (cnot312 23 23
123 x) : S(B B B)
SE
x : S(B) S(B B) 2 (1 H31 (cnot312 23 23 x)) : B B S(B)
123
I
Alice : S(B) S(B B) B B S(B)
(16)
Typing quantum superpositions and measurement 51

Ax|0i Ax|0i Ax|1i Ax|1i


|0i : B |0i : B |1i : B |1i : B
I I
|0i |0i : B B |1i |1i : B B
1
SI 1
SI
2 . |0i |0i : S(B B) 2 . |1i |1i : S(B B)
SI+
00 : S(S(B B))

00 : S(B B) (17)

(17)
Ax
(16) q : S(B) q : S(B) 00 : S(B B)
I
Alice : S(B) S(B B) B B S(B) q : S(B) q 00 : S(B) S(B B)
E
(11) q : S(B) Alice (q 00 ) : B B S(B)

Bob : B B B S(B) q : S(B) Alice (q 00 ) : S(B B S(B))
 l
Bob : S(B B B S(B)) q : S(B) 1 Alice (q 00 ) : S(B B B)
ES
q : S(B) Bob (1 Alice (q 00 )) : S(S(B))

q : S(B) Bob (1 Alice (q 00 )) : S(B)
I
T eleportation : S(B) S(B)

You might also like