Sunteți pe pagina 1din 36

Semantics of a Quantum Programming Language Peter Selinger Dalhousie University Halifax, Canada

Why Quantum Programming Languages? For certain problems, quantum algorithms have an exponential speedup over best known classical algorithms. Most research in quantum computing has focused on algorithms and complexity theory. Quantum algorithms are traditionally described in terms of hardware: quantum circuits or quantum Turing machines. Want compositionality. Also, how do quantum features interact with other language features such as structured data, recursion, i/o, higher-order.

Part I: Quantum Computation

The QRAM abstract machine [Knill96] Classical device: master (general purpose) control results Quantum device: slave

General-purpose classical computer controls a special quantum hardware device Quantum device provides a bank of individually addressable qubits. Left-to-right: instructions. Right-to-left: results.

Linear Algebra Review Scalars C, column vectors u Cn, matrices A Cnm . Adjoint A = (aji)ij, trace tr A = A 2 = ij |aij|2.
i aii, norm

Unitary matrix S Cnn if SS = I. Change of basis: B = SAS tr B = tr A, B = A .

Hermitian matrix A Cnn : if A = A. Hermitian positive: uAu 0 for all u Cn . Diagonalization: A = SDS, S unitary, D real diagonal. Tensor product A B, e.g.

0 1 1 0

B=

0 B B 0

Quantum computation: States

state of one qubit: |0 + |1 (superposition of |0 and |1 ). state of two qubits: |00 + |01 + |10 + |11 . independent: (a|0 + b|1 ) (c|0 + d|1 ) = ac|00 + ad|01 + bc|10 + bd|11 . otherwise entangled.

Lexicographic convention Identify the basis states |00 , basis vectors 1 0 0 1 , 0 0 0 0 in the lexicographic order.

|01 , |10 , |11 with the standard


,

0 0 1 0

0 0 0 1

Note: we use column vectors for states.


= |00 + |01 + |10 + |11 .

Quantum computation: Operations

unitary transformation measurement

Some standard unitary gates

Unary:

Binary:

N=
1 H=

0 1 1 0

Nc =

I 0 0 N I 0 0 H I 0 0 V I 0 0 W

1 1 1 1 ,

Hc =

V=

1 0 0 i 1 0 i 0

Vc =

W=

Wc =

X=

1 0 0 0

0 0 1 0

0 1 0 0

0 0 0 1

.
9

Measurement

|0 + |1
||2
0 1

||2

|0

|1

10

Two Measurements

|00 + |01 + |10 + |11


0 1

||2+||2

||2+||2

|00 + |01
||2 ||2+||2
0 1

|10 + |11
||2 ||2+||2 ||2 ||2+||2
0 1

||2 ||2+||2

|00

|01

|10

|11

Note: Normalization convention.


11

Pure vs. mixed states A mixed state is a (classical) probability distribution on quantum states. Ad hoc notation:

1 2

1 2

Note: A mixed state is a description of our knowledge of a state. An actual closed quantum system is always in a (possibly unknown) pure state.

12

Density matrices (von Neumann) Represent the pure state v =

C2 by the matrix C22.

vv

Represent the mixed state 1 {v1} + . . . + n {vn } by

1 v 1 v + . . . + n v n v . n 1
This representation is not one-to-one, e.g.

1 2 1 2 1 2

1 0 1 1

+ 1 2

1 2 1 2

0 1 1 1

1 2 =

1 0 0 0 1 2

1 2

0 0 0 1 + 1 2

.5 0 0 .5 = .5 0 0 .5

.5 .5 .5 .5

.5 .5 .5 .5

But these two mixed states are indistinguishable.


13

Quantum operations on density matrices Unitary:

Measurement:

v Uv
0 1

vv UvvU

0 1

A UAU a b c d
0 1

||2

||2

0 0 0

0 0 0

a 0 0 0

0 0 0 d

14

A complete partial order of density matrices Let Dn = {A Cnn | A is positive hermitian and tr A 1}. Denition. We write A

B if B A is positive.

Theorem. The density matrices form a complete partial order under .

A A A B and B A A = B A B and B C A C every increasing sequence A1 bound

A2

. . . has a least upper

15

Part II: The Flow Chart Language

16

Earlier Quantum Programming Languages

Knill (1996): conventions for writing pseudo-code Omer (1998): scratch space management, user dened operators

Sanders and Zuliani (2000): specication language, stepwise renement

Bettelli, Calarco, and Serani (2001): based on C++ Imperative languages, run-time checks and errors, no formal semantics.
17

A simple classical ow chart input b, c : bit

b, c : bit
branch b
0 1

b, c : bit b := c b, c : bit b, c : bit c := 0 b, c : bit

b, c : bit
output b, c : bit
18

Classical ow chart, with boolean variables expanded input b, c : bit

00 01 10

11

( branch b ) ( b := c ) ( c := 0 ) ( merge )

output b, c : bit

00 01 10

11
19

Classical ow chart, with boolean variables expanded input b, c : bit

00 01 10 11 A B C D
0 0 C D 0 D

( branch b ) ( b := c ) ( c := 0 ) ( merge )

C 0 C 0

D 0

output b, c : bit

A+C 00

B D 0 01 10 11

19-a

A simple classical ow chart input b, c : bit

b, c : bit
branch b
0 1

b, c : bit b := c b, c : bit b, c : bit c := 0 b, c : bit

b, c : bit
output b, c : bit
20

A simple classical ow chart input b, c : bit

b, c : bit = (A, B, C, D)
branch b
0 1

b, c : bit = (0, 0, C, D) b := c b, c : bit = (A, B, 0, 0) b, c : bit = (C, 0, 0, D) c := 0 b, c : bit = (C, 0, D, 0)

b, c : bit = (A + C, B, D, 0)

output b, c : bit
20-a

Summary of classical ow chart components


Allocate bit: Discard bit:

=A
new bit b := 0

b : bit, = (A, B)
discard b

b : bit, = (A, 0)

=A+B

Assignment:

Branching:

b : bit, = (A, B) b := 0 b : bit, = (A + B, 0)

b : bit, = (A, B) b := 1 b : bit, = (0, A + B)

b : bit, = (A, B)
branch b 0 1 b : bit, = (A, 0) b : bit, = (0, B)

Merge:

Initial:

Permutation:

=A

=B

b1 , . . . , bn : bit = A0 , . . . , A2n 1
permute

=A+B

=0

b(1) , . . . , b(n) : bit = A2 (0) , . . . , A2 (2n 1)


21

A simple quantum ow chart

input p, q : qbit

p, q : qbit
measure p
0 1

p, q : qbit q = N p, q : qbit

p, q : qbit p = N p, q : qbit p, q : qbit

output p, q : qbit
22

A simple quantum ow chart

input p, q : qbit

p, q : qbit =
measure p

A B C D

p, q : qbit =

A 0 0 0 0 q = N

p, q : qbit = p = N p, q : qbit = p, q : qbit =

0 0 0 D D 0 0 0

p, q : qbit =

NAN 0 0 0

NAN + D 0 0 0

output p, q : qbit
22-a

Summary of quantum ow chart components


Allocate qbit: Discard qbit:

=A
new qbit q := 0

q : qbit, =
discard q

A C

B D

q : qbit, =

A 0

0 0

=A+D

Unitary transformation:

Measurement:

q : qbit, = A q = S q : qbit, = (S I)A(S


Merge:

q : qbit, = A 0

A C

B D 0 0 0 D

I)

q : qbit, =

measure q 0 0 1 q : qbit, = 0

Initial:

Permutation:

=A

=B

q1 , . . . , qn : qbit = (aij )ij


permute

=A+B

=0

q(1) , . . . , q(n) : qbit = (a2 (i),2 (j) )ij

23

Combining classical data with quantum data Consider typing contexts of the form

b1 : bit, . . . , bn : bit, q1 : qbit, . . . , qm : qbit.

Denition. A state for the above typing context is a (A0, . . . , A2n1) of density matrices, each of dimension

2n-tuple 2 m 2m .

tr (A0, . . . , A2n1) (A0, . . . , A2n1 ) S(A0, . . . , A2n1 )S |(A0, . . . , A2n1)|2

:= i tr Ai, := (A, . . . , An1), 0 2 , . . . , SA n S), := (SA0S 2 1 2 := i |Ai| .


24

Summary of language features:

our language is functional (no side eects) and statically typed (no run-time errors).

it combines quantum and classical features (the compiler can separate them again).

it has high-level features (such as loops, recursion, and structured data types) [not shown in this talk]

there is a compositional denotational semantics.


25

The denotation of a quantum ow chart The denotation of a ow chart is a function which maps (tuples of) matrices to (tuples of) matrices. Example: the denotation of the quantum ow chart from previous slide is the function

A B C D

NAN + D 0 0 0

Question: Which functions can occur?

26

Superoperators

1) linear

2) positive: A positive F(A) positive 3) trace non-increasing: A positive tr F(A) tr(A) 4) completely positive: F idn positive for all n Theorem: The above conditions are necessary and sucient.
27

The category Q of superoperators Objects: signatures = n1, . . . , nk Morphisms: f : is a superoperator Structure:

f : C n 1 n 1 . . . C n k n k C m 1 m 1 . . . C m k m k

symmetric monoidal category (horiz.+vert. composition) coproducts (merge, initial) CPO-enriched (xpoints, recursion) traced monoidal (loops)

28

Structural and denotational equivalence Denition. An elementary quantum ow chart category is a symmetric monoidal category with traced nite coproducts, such that A () is a traced monoidal functor for every object A, together with a distinguished object qbit and morphisms : I I qbit and : qbit I I, such that = id. Denition. Two quantum ow charts X, Y are structurally equivalent if for every elementary quantum ow chart category C and every interpretation of basic operator symbols, [[X]] = [[Y]].

We say X and Y are denotationally equivalent if [[X]] = [[Y]] for the canonical interpretation in the category Q of signatures and superoperators.
29

Higher-order quantum computation Consider functions of higher-order types such as (qbit bit) qbit etc. let q = new qbit() in (x.H(x, x))q. Bits are always duplicable, qubits are never duplicable. What about functions? Consider

Quantum data is subject to linearity constraints. Need to avoid terms that lead to runtime errors such as

q:qbit q:qbit

Both closures have type qbit qbit, but only the rst one is duplicable.
30

p.p : qbit qbit p.q : qbit qbit

Linear type system [Selinger,Valiron04] Types: A, B ::= Subtyping: !A <: A. Typing rules: If FV(M) | | = :

!A

A B

A B.

x:A, M : B ( ) x.M : A B 1

, ! , x:A M : B ( ) , ! x.M : !(A B) 2

(Operational semantics, subject reduction, progress, safety, type inference).


31

Example: quantum teleportation / dense coding It is possible to write a function

such that for any application

TPPair : 1 (qbit bit bit) (bit bit qbit) (f, g) = TPPair(),

one obtains a pair of functions (f, g) with the properties:

f : qbit bit bit g : bit bit qbit f g = idbitbit g f = idqbit Thus, are the types qbit and bit bit isomorphic?
Answer: No, because each such pair f, g can only be used once. Thus we have a single-use type isomorphism. This is a curious phenomenon.
32

Overview of some recent research Quantum process calculi. Lalire-Jorrand (2004), Gay-Nagarajan (2004), Ado-Mateus (2005) a Higher-order quantum computation. Van Tonder (2003, 2004), Selinger-Valiron (2004), Altenkirch-Grattage (2004) Categorical quantum computation. Abramsky-Coecke (2004), Selinger (2005) Measurement based quantum computation. Danos-DHondt-Kashe-Panangaden (2004, 2005) Quantum specication. Zuliani (2001-2004), DHondt-Panangaden (2004), Taiovich (2004) Quantum coherent spaces. Girard (2003), Selinger (2004)
33

S-ar putea să vă placă și