Types for Quantum Computing Peter Selinger Dalhousie University Halifax, Canada 1
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. 2
Part I: Quantum Computation 3
Linear Algebra Review • Scalars λ ∈ C , column vectors u ∈ C n , matrices A ∈ C n × m . • Adjoint A ∗ = ( a ji ) ij , trace tr A = � i a ii , norm � A � 2 = � ij | a ij | 2 . • Unitary matrix S ∈ C n × n if S ∗ S = I . Change of basis: B = SAS ∗ ⇒ tr B = tr A , � B � = � A � . • Hermitian matrix A ∈ C n × n : if A = A ∗ . Hermitian positive: u ∗ Au ≥ 0 for all u ∈ C n . Diagonalization: A = SDS ∗ , S unitary, D real diagonal. � � � � 0 1 0 B • Tensor product A ⊗ B , e.g. ⊗ B = . − 1 − B 0 0 4
The QRAM abstract machine [Knill96] Classical device: control Quantum device: master slave (general purpose) results • 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. 5
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 . 6
Lexicographic convention Identify the basis states | 00 � , | 01 � , | 10 � , | 11 � with the standard basis vectors 1 0 0 0 0 1 0 0 , , , , 0 0 1 0 0 0 0 1 in the lexicographic order. Note: we use column vectors for states. α β = α | 00 � + β | 01 � + γ | 10 � + δ | 11 � . γ δ 7
Quantum computation: Operations • unitary transformation • measurement 8
Some standard unitary gates Unary: Binary: � � � � I 0 0 1 N = N c = , , 1 0 0 N � � � � 1 1 I 0 1 √ H = , H c = , 1 − 1 0 H 2 � � � � 1 0 I 0 V = V c = , , 0 i 0 V 1 0 0 0 � � � � 1 0 I 0 0 0 1 0 √ W = , W c = , X = . 0 1 0 0 0 i 0 W 0 0 0 1 9
Measurement α | 0 � + β | 1 � 0 1 | α | 2 | β | 2 α | 0 � β | 1 � 10
Two Measurements α | 00 � + β | 01 � + γ | 10 � + δ | 11 � 0 1 | α | 2 + | β | 2 | γ | 2 + | δ | 2 α | 00 � + β | 01 � γ | 10 � + δ | 11 � 0 1 0 1 | α | 2 | β | 2 | γ | 2 | δ | 2 | α | 2 + | β | 2 | α | 2 + | β | 2 | γ | 2 + | δ | 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 + 1 α β ′ β 2 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) � � α ∈ C 2 by the matrix Represent the pure state v = β � α ¯ � α ¯ α β vv ∗ = ∈ C 2 × 2 . β ¯ β ¯ α β Represent the mixed state λ 1 { v 1 } + . . . + λ n { v n } by λ 1 v 1 v ∗ 1 + . . . + λ n v n v ∗ n . This representation is not one-to-one, e.g. � � � � � � � � � � � � � � 1 + 1 = 1 + 1 1 0 1 0 0 0 .5 0 = 0 1 0 0 0 1 0 .5 2 2 2 2 � 1 � 1 � � � � � � � � � � � � 1 + 1 = 1 + 1 1 1 .5 .5 .5 − .5 .5 0 √ √ = − 1 − .5 1 .5 .5 .5 0 .5 2 2 2 2 2 2 But these two mixed states are indistinguishable. 13
Quantum operations on density matrices Unitary: vv ∗ � → Uvv ∗ U ∗ A � → UAU ∗ v � → Uv Measurement: � � � α ¯ � � � α ¯ α α β a b β ¯ β ¯ β α β c d 0 1 0 1 0 1 | α | 2 | β | 2 β ¯ α ¯ β a α d � � � � � � � � � � � � α ¯ α 0 α 0 0 0 a 0 0 0 β ¯ 0 β 0 0 0 β 0 0 0 d 14
A complete partial order of density matrices Let D n = { A ∈ C n × n | A is positive hermitian and tr A ≤ 1 } . Definition. 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 A 1 ⊑ A 2 ⊑ . . . has a least upper bound 15
Part II: The Flow Chart Language 16
First: the classical case. A simple classical flow 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 17
Classical flow 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 18
Classical flow chart, with boolean variables expanded input b, c : bit 00 01 10 11 A B C D ◦ ◦ ◦ ◦ ( ∗ branch b ∗ ) ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ 0 0 C D ◦ ◦ ◦ ◦ ( ∗ b := c ∗ ) ◦ ◦ ◦ ◦ A B 0 0 C 0 0 D ◦ ◦ ◦ ◦ ( ∗ c := 0 ∗ ) ◦ ◦ ◦ ◦ C 0 D 0 ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ( ∗ merge ∗ ) ◦ ◦ ◦ ◦ A + C B D 0 output b, c : bit 00 01 10 11 18-a
A simple classical flow 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 19
A simple classical flow 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 19-a
Summary of classical flow chart components Allocate bit: Discard bit: b : bit , Γ = ( A, B ) Γ = A new bit b := 0 discard b b : bit , Γ = ( A, 0 ) Γ = A + B Assignment: Branching: b : bit , Γ = ( A, B ) b : bit , Γ = ( A, B ) b : bit , Γ = ( A, B ) branch b b := 0 b := 1 0 1 b : bit , Γ = ( 0, B ) b : bit , Γ = ( A, 0 ) b : bit , Γ = ( A + B, 0 ) b : bit , Γ = ( 0, A + B ) Merge: Initial: Permutation: b 1 , . . . , b n : bit = A 0 , . . . , A 2 n − 1 Γ = A Γ = B ◦ ◦ permute φ Γ = A + B Γ = 0 b φ ( 1 ) , . . . , b φ ( n ) : bit = A 2 φ ( 0 ) , . . . , A 2 φ ( 2 n − 1 ) 20
The quantum case: A simple quantum flow chart input p, q : qbit p, q : qbit measure p 0 1 p, q : qbit p, q : qbit q ∗ = N p ∗ = N p, q : qbit p, q : qbit ◦ p, q : qbit output p, q : qbit 21
A simple quantum flow chart input p, q : qbit � � A B p, q : qbit = C D measure p 0 1 � � � � A 0 0 0 p, q : qbit = p, q : qbit = 0 0 0 D q ∗ = N p ∗ = N � � D 0 NAN ∗ � � 0 p, q : qbit = p, q : qbit = 0 0 0 0 ◦ NAN ∗ + D � � 0 p, q : qbit = 0 0 output p, q : qbit 21-a
Summary of quantum flow chart components Allocate qbit: Discard qbit: � A � B q : qbit , Γ = Γ = A C D new qbit q := 0 discard q � A � 0 q : qbit , Γ = Γ = A + D 0 0 Unitary transformation: Measurement: � A � B q : qbit , Γ = ¯ q : qbit , Γ = A C D measure q ¯ q ∗ = S � A � 0 � � 0 0 1 q : qbit , Γ = 0 q : qbit , Γ = q : qbit , Γ = ( S ⊗ I ) A ( S ⊗ I ) ∗ ¯ 0 0 0 D Merge: Initial: Permutation: q 1 , . . . , q n : qbit = ( a ij ) ij Γ = A Γ = B ◦ permute φ ◦ Γ = 0 q φ ( 1 ) , . . . , q φ ( n ) : qbit = ( a 2 φ ( i ) ,2 φ ( j ) ) ij Γ = A + B 22
Part III: Quantum Lambda Calculus With Beno ˆ ıt Valiron. 23
A quantum lambda calculus [Selinger,Valiron04] • Quantum data is subject to linearity constraints . Need to avoid terms that lead to runtime errors such as let q = new qbit () in ( λx.H ( x, x )) q. • Bits are always duplicable, qubits are never duplicable. What about functions? • Consider q : qbit ⊢ qbit → qbit λp.p : q : qbit ⊢ qbit → qbit λp.q : Both closures have type qbit → qbit , but only the first one is duplicable. • Solution: type system based on linear logic. 24
Linear type system [Selinger,Valiron04] Types: A, B ::= qbit ! A A − ◦ B A ⊗ B A ⊕ B . 1 Convention bit := 1 ⊕ 1 . Subtyping: ! A < : A . 25
Main typing rules: ∆, x : A ⊲ M : B ∆ ⊲ λx.M : A ⊸ B ! ∆, x : A ⊲ M : B ! ∆ ⊲ λx.M : !( A ⊸ B ) 26
Recommend
More recommend