SLIDE 1
Quantum Hoare Type Theory
Kartik Singhal John Reppy
Department of Computer Science University of Chicago
Quantum Physics and Logic (QPL) 2020
SLIDE 2 Quantum programming is inherently imperative and difficult to reason about
2 / 12
SLIDE 3 Quantum programming is inherently imperative and difficult to reason about
In classical programming Hoare triples are used to reason about state changes. {P} c {Q} c is the command to be executed; P, Q are pre and postconditions on state.
2 / 12
SLIDE 4 Quantum programming is inherently imperative and difficult to reason about
In classical programming Hoare triples are used to reason about state changes. {P} c {Q} c is the command to be executed; P, Q are pre and postconditions on state. In pure functional settings, monads can encapsulate effects.
2 / 12
SLIDE 5 Quantum programming is inherently imperative and difficult to reason about
In classical programming Hoare triples are used to reason about state changes. {P} c {Q} c is the command to be executed; P, Q are pre and postconditions on state. In pure functional settings, monads can encapsulate effects. Can we combine Hoare triples with monadic types?
2 / 12
SLIDE 6 Quantum programming is inherently imperative and difficult to reason about
In classical programming Hoare triples are used to reason about state changes. {P} c {Q} c is the command to be executed; P, Q are pre and postconditions on state. In pure functional settings, monads can encapsulate effects. Can we combine Hoare triples with monadic types? Yes, thanks to Hoare Type Theory!
2 / 12
SLIDE 7 Quantum programming is inherently imperative and difficult to reason about
In classical programming Hoare triples are used to reason about state changes. {P} c {Q} c is the command to be executed; P, Q are pre and postconditions on state. In pure functional settings, monads can encapsulate effects. Can we combine Hoare triples with monadic types? Yes, thanks to Hoare Type Theory! For quantum programming?
2 / 12
SLIDE 8 Outline
Motivation Background Hoare Type Theory (HTT). Nanevski et al, ’07 Quantum IO Monad (QIO). Altenkirch & Green, ’09 Quantum Hoare Type Theory (QHTT) Examples Typing Rules Verification Ongoing & Future Work Conclusion
3 / 12
SLIDE 9
Outline
Motivation Background Hoare Type Theory (HTT). Nanevski et al, ’07 Quantum IO Monad (QIO). Altenkirch & Green, ’09 Quantum Hoare Type Theory (QHTT) Examples Typing Rules Verification Ongoing & Future Work Conclusion
SLIDE 10 Hoare Types specify pre and postconditions and are very expressive
∆.Ψ.{P} x : A {Q}
4 / 12
SLIDE 11 Hoare Types specify pre and postconditions and are very expressive
∆.Ψ.{P} x : A {Q} P, Q are pre and postconditions (as before)
4 / 12
SLIDE 12 Hoare Types specify pre and postconditions and are very expressive
∆.Ψ.{P} x : A {Q} P, Q are pre and postconditions (as before) x is the return value of type A
4 / 12
SLIDE 13 Hoare Types specify pre and postconditions and are very expressive
∆.Ψ.{P} x : A {Q} P, Q are pre and postconditions (as before) x is the return value of type A ∆ and Ψ are variable and heap contexts
4 / 12
SLIDE 14 Hoare Types specify pre and postconditions and are very expressive
∆.Ψ.{P} x : A {Q} P, Q are pre and postconditions (as before) x is the return value of type A ∆ and Ψ are variable and heap contexts For example, the type of the alloc primitive from HTT: ∀α.Πx : α.{emp} y : nat {y →α x} which is a polymorphic function that takes as input x of any type α and returns a new location y of type nat after initializing it with x.
4 / 12
SLIDE 15
Outline
Motivation Background Hoare Type Theory (HTT). Nanevski et al, ’07 Quantum IO Monad (QIO). Altenkirch & Green, ’09 Quantum Hoare Type Theory (QHTT) Examples Typing Rules Verification Ongoing & Future Work Conclusion
SLIDE 16 QIO is a monadic interface for quantum programming implemented in Haskell
QIO monad is indexed by the type of computational result.
mkQbit :: Bool → QIO Qbit
applyU :: U → QIO ()
measQbit :: Qbit → QIO Bool
5 / 12
SLIDE 17 QIO is a monadic interface for quantum programming implemented in Haskell
QIO monad is indexed by the type of computational result.
mkQbit :: Bool → QIO Qbit
applyU :: U → QIO ()
measQbit :: Qbit → QIO Bool
Arbitrary unitaries can be defined using:
rot :: Qbit → ((Bool, Bool) → C) → U ifQ :: Qbit → U → U
5 / 12
SLIDE 18 QIO is a monadic interface for quantum programming implemented in Haskell
QIO monad is indexed by the type of computational result.
mkQbit :: Bool → QIO Qbit
applyU :: U → QIO ()
measQbit :: Qbit → QIO Bool
Arbitrary unitaries can be defined using:
rot :: Qbit → ((Bool, Bool) → C) → U ifQ :: Qbit → U → U
U is monoid with sequencing as its operation and identity as the neutral element.
5 / 12
SLIDE 19
Outline
Motivation Background Hoare Type Theory (HTT). Nanevski et al, ’07 Quantum IO Monad (QIO). Altenkirch & Green, ’09 Quantum Hoare Type Theory (QHTT) Examples Typing Rules Verification Ongoing & Future Work Conclusion
SLIDE 20 Programming in Quantum Hoare Type Theory
We further index the QIO monad with pre and postconditions to get a Hoare monad.
6 / 12
SLIDE 21 Programming in Quantum Hoare Type Theory
We further index the QIO monad with pre and postconditions to get a Hoare monad. Hello Quantum World:
hqw : {emp} r : Bool {emp ∧ Id(r, false)}
6 / 12
SLIDE 22 Programming in Quantum Hoare Type Theory
We further index the QIO monad with pre and postconditions to get a Hoare monad. Hello Quantum World:
hqw : {emp} r : Bool {emp ∧ Id(r, false)} = do q ⇐ mkQbit false; measQbit q
6 / 12
SLIDE 23 Programming in Quantum Hoare Type Theory
We further index the QIO monad with pre and postconditions to get a Hoare monad. Hello Quantum World:
hqw : {emp} r : Bool {emp ∧ Id(r, false)} = do q ⇐ mkQbit false; measQbit q
Quantum Coin Toss:
rnd : {emp} r : Bool {emp} = do q ⇐ mkQbit false; applyU (H q); measQbit q
6 / 12
SLIDE 24 Programming in Quantum Hoare Type Theory
We further index the QIO monad with pre and postconditions to get a Hoare monad. Hello Quantum World:
hqw : {emp} r : Bool {emp ∧ Id(r, false)} = do q ⇐ mkQbit false; measQbit q
Quantum Coin Toss:
rnd : {emp} r : Bool {emp} = do q ⇐ mkQbit false; applyU (H q); measQbit q
But how do we reason about these programs?
6 / 12
SLIDE 25
Outline
Motivation Background Hoare Type Theory (HTT). Nanevski et al, ’07 Quantum IO Monad (QIO). Altenkirch & Green, ’09 Quantum Hoare Type Theory (QHTT) Examples Typing Rules Verification Ongoing & Future Work Conclusion
SLIDE 26 Strongest Postcondition for Initialization
x ⇐ mkQbit M; E
7 / 12
SLIDE 27 Strongest Postcondition for Initialization
x ⇐ mkQbit M; E HTT uses bidirectional typing for type inference, where
7 / 12
SLIDE 28 Strongest Postcondition for Initialization
x ⇐ mkQbit M; E HTT uses bidirectional typing for type inference, where e ⇐ A means ‘expression e checks against type A’, and,
7 / 12
SLIDE 29 Strongest Postcondition for Initialization
x ⇐ mkQbit M; E HTT uses bidirectional typing for type inference, where e ⇐ A means ‘expression e checks against type A’, and, e ⇒ A means ‘expression e synthesizes the type A’.
7 / 12
SLIDE 30 Strongest Postcondition for Initialization
x ⇐ mkQbit M; E HTT uses bidirectional typing for type inference, where e ⇐ A means ‘expression e checks against type A’, and, e ⇒ A means ‘expression e synthesizes the type A’. x ⇐ mkQbit M; E
7 / 12
SLIDE 31 Strongest Postcondition for Initialization
x ⇐ mkQbit M; E HTT uses bidirectional typing for type inference, where e ⇐ A means ‘expression e checks against type A’, and, e ⇒ A means ‘expression e synthesizes the type A’. ∆; P ⊢ x ⇐ mkQbit M; E
7 / 12
SLIDE 32 Strongest Postcondition for Initialization
x ⇐ mkQbit M; E HTT uses bidirectional typing for type inference, where e ⇐ A means ‘expression e checks against type A’, and, e ⇒ A means ‘expression e synthesizes the type A’. ∆; P ⊢ x ⇐ mkQbit M; E ⇒ y : B.(∃x : Qbit.Q)
7 / 12
SLIDE 33 Strongest Postcondition for Initialization
x ⇐ mkQbit M; E HTT uses bidirectional typing for type inference, where e ⇐ A means ‘expression e checks against type A’, and, e ⇒ A means ‘expression e synthesizes the type A’. ∆ ⊢ M ⇐ Bool ∆; P ⊢ x ⇐ mkQbit M; E ⇒ y : B.(∃x : Qbit.Q)
7 / 12
SLIDE 34 Strongest Postcondition for Initialization
x ⇐ mkQbit M; E HTT uses bidirectional typing for type inference, where e ⇐ A means ‘expression e checks against type A’, and, e ⇒ A means ‘expression e synthesizes the type A’. ∆ ⊢ M ⇐ Bool ∆ P ⊢ E ⇒ y : B.Q ∆; P ⊢ x ⇐ mkQbit M; E ⇒ y : B.(∃x : Qbit.Q)
7 / 12
SLIDE 35 Strongest Postcondition for Initialization
x ⇐ mkQbit M; E HTT uses bidirectional typing for type inference, where e ⇐ A means ‘expression e checks against type A’, and, e ⇒ A means ‘expression e synthesizes the type A’. ∆ ⊢ M ⇐ Bool ∆, x : Qbit; P ⊢ E ⇒ y : B.Q ∆; P ⊢ x ⇐ mkQbit M; E ⇒ y : B.(∃x : Qbit.Q)
7 / 12
SLIDE 36 Strongest Postcondition for Initialization
x ⇐ mkQbit M; E HTT uses bidirectional typing for type inference, where e ⇐ A means ‘expression e checks against type A’, and, e ⇒ A means ‘expression e synthesizes the type A’. ∆ ⊢ M ⇐ Bool ∆, x : Qbit; P ◦ (x → state (M)) ⊢ E ⇒ y : B.Q ∆; P ⊢ x ⇐ mkQbit M; E ⇒ y : B.(∃x : Qbit.Q)
7 / 12
SLIDE 37 Strongest Postcondition for Measurement
x ⇐ measQbit M; E HTT uses bidirectional typing for type inference, where: e ⇐ A means ‘expression e checks against type A’, and, e ⇒ A means ‘expression e synthesizes the type A’. ∆; P ⊢ x ⇐ measQbit M; E ⇒ y : B.(∃x : Bool.Q)
8 / 12
SLIDE 38 Strongest Postcondition for Measurement
x ⇐ measQbit M; E HTT uses bidirectional typing for type inference, where: e ⇐ A means ‘expression e checks against type A’, and, e ⇒ A means ‘expression e synthesizes the type A’. ∆ ⊢ M ⇐ Qbit ∆; P ⊢ x ⇐ measQbit M; E ⇒ y : B.(∃x : Bool.Q)
8 / 12
SLIDE 39 Strongest Postcondition for Measurement
x ⇐ measQbit M; E HTT uses bidirectional typing for type inference, where: e ⇐ A means ‘expression e checks against type A’, and, e ⇒ A means ‘expression e synthesizes the type A’. ∆ ⊢ M ⇐ Qbit ∆, x : Bool; P ⊢ E ⇒ y : B.Q ∆; P ⊢ x ⇐ measQbit M; E ⇒ y : B.(∃x : Bool.Q)
8 / 12
SLIDE 40 Strongest Postcondition for Measurement
x ⇐ measQbit M; E HTT uses bidirectional typing for type inference, where: e ⇐ A means ‘expression e checks against type A’, and, e ⇒ A means ‘expression e synthesizes the type A’. ∆ ⊢ M ⇐ Qbit ∆, x : Bool; P ◦ ((M → −) ⊸ emp ) ⊢ E ⇒ y : B.Q ∆; P ⊢ x ⇐ measQbit M; E ⇒ y : B.(∃x : Bool.Q)
8 / 12
SLIDE 41 Strongest Postcondition for Measurement
x ⇐ measQbit M; E HTT uses bidirectional typing for type inference, where: e ⇐ A means ‘expression e checks against type A’, and, e ⇒ A means ‘expression e synthesizes the type A’. ∆ ⊢ M ⇐ Qbit ∆; Ψ; P = ⇒ (M ֒ → −) ∆, x : Bool; P ◦ ((M → −) ⊸ emp ) ⊢ E ⇒ y : B.Q ∆; P ⊢ x ⇐ measQbit M; E ⇒ y : B.(∃x : Bool.Q)
8 / 12
SLIDE 42
Outline
Motivation Background Hoare Type Theory (HTT). Nanevski et al, ’07 Quantum IO Monad (QIO). Altenkirch & Green, ’09 Quantum Hoare Type Theory (QHTT) Examples Typing Rules Verification Ongoing & Future Work Conclusion
SLIDE 43 Verifying Hello Quantum World
hqw : {emp} r : Bool {emp ∧ Id(r, false)} = do q ⇐ mkQbit false; measQbit q
9 / 12
SLIDE 44 Verifying Hello Quantum World
hqw : {emp} r : Bool {emp ∧ Id(r, false)} = do q ⇐ mkQbit false; measQbit q
At the logic level:
9 / 12
SLIDE 45 Verifying Hello Quantum World
hqw : {emp} r : Bool {emp ∧ Id(r, false)} = do q ⇐ mkQbit false; measQbit q
At the logic level:
hqw : {emp} r : Bool {emp ∧ Id(r, false)}
= do q ⇐ mkQbit false;
9 / 12
SLIDE 46 Verifying Hello Quantum World
hqw : {emp} r : Bool {emp ∧ Id(r, false)} = do q ⇐ mkQbit false; measQbit q
At the logic level:
hqw : {emp} r : Bool {emp ∧ Id(r, false)}
= do q ⇐ mkQbit false;
measQbit q
9 / 12
SLIDE 47 Verifying Hello Quantum World
hqw : {emp} r : Bool {emp ∧ Id(r, false)} = do q ⇐ mkQbit false; measQbit q
At the logic level:
hqw : {emp} r : Bool {emp ∧ Id(r, false)}
= do q ⇐ mkQbit false;
measQbit q
- - P2: P1 ◦ ((q → -) ⊸ emp)
9 / 12
SLIDE 48 Verifying Hello Quantum World
hqw : {emp} r : Bool {emp ∧ Id(r, false)} = do q ⇐ mkQbit false; measQbit q
At the logic level:
hqw : {emp} r : Bool {emp ∧ Id(r, false)}
= do q ⇐ mkQbit false;
measQbit q
- - P2: P1 ◦ ((q → -) ⊸ emp)
Successful type checking implies correctness
- f the program to given specifications.
9 / 12
SLIDE 49 Verifying Quantum Coin Toss
rnd : {emp} r : Bool {emp} = do q ⇐ mkQbit false; applyU (H q); measQbit q
At the logic level:
10 / 12
SLIDE 50 Verifying Quantum Coin Toss
rnd : {emp} r : Bool {emp} = do q ⇐ mkQbit false; applyU (H q); measQbit q
At the logic level:
rnd : {emp} r : Bool {emp}
= do q ⇐ mkQbit false;
10 / 12
SLIDE 51 Verifying Quantum Coin Toss
rnd : {emp} r : Bool {emp} = do q ⇐ mkQbit false; applyU (H q); measQbit q
At the logic level:
rnd : {emp} r : Bool {emp}
= do q ⇐ mkQbit false;
applyU (H q);
10 / 12
SLIDE 52 Verifying Quantum Coin Toss
rnd : {emp} r : Bool {emp} = do q ⇐ mkQbit false; applyU (H q); measQbit q
At the logic level:
rnd : {emp} r : Bool {emp}
= do q ⇐ mkQbit false;
applyU (H q);
- - P2: P1 ◦ ((q → |0) ⊸ (q → |+))
measQbit q
10 / 12
SLIDE 53 Verifying Quantum Coin Toss
rnd : {emp} r : Bool {emp} = do q ⇐ mkQbit false; applyU (H q); measQbit q
At the logic level:
rnd : {emp} r : Bool {emp}
= do q ⇐ mkQbit false;
applyU (H q);
- - P2: P1 ◦ ((q → |0) ⊸ (q → |+))
measQbit q
- - P3: P2 ◦ ((q → -) ⊸ emp)
10 / 12
SLIDE 54 Ongoing & Future Work
11 / 12
SLIDE 55 Ongoing & Future Work
Tractable semantics for unitary application
11 / 12
SLIDE 56 Ongoing & Future Work
Tractable semantics for unitary application
Unitaries as path-sum actions (Amy, QPL ’18) based on Feyman path integrals
11 / 12
SLIDE 57 Ongoing & Future Work
Tractable semantics for unitary application
Unitaries as path-sum actions (Amy, QPL ’18) based on Feyman path integrals
Quantum Assertion Logic
11 / 12
SLIDE 58 Ongoing & Future Work
Tractable semantics for unitary application
Unitaries as path-sum actions (Amy, QPL ’18) based on Feyman path integrals
Quantum Assertion Logic Linear Dependent Type Theory: FKS, LICS ’20
11 / 12
SLIDE 59 Ongoing & Future Work
Tractable semantics for unitary application
Unitaries as path-sum actions (Amy, QPL ’18) based on Feyman path integrals
Quantum Assertion Logic Linear Dependent Type Theory: FKS, LICS ’20 Circuits as Arrows: VAS06, Math. Struct. Comput. Sci. 16(3)
11 / 12
SLIDE 60 Ongoing & Future Work
Tractable semantics for unitary application
Unitaries as path-sum actions (Amy, QPL ’18) based on Feyman path integrals
Quantum Assertion Logic Linear Dependent Type Theory: FKS, LICS ’20 Circuits as Arrows: VAS06, Math. Struct. Comput. Sci. 16(3) Behavioural Types
11 / 12
SLIDE 61 Ongoing & Future Work
Tractable semantics for unitary application
Unitaries as path-sum actions (Amy, QPL ’18) based on Feyman path integrals
Quantum Assertion Logic Linear Dependent Type Theory: FKS, LICS ’20 Circuits as Arrows: VAS06, Math. Struct. Comput. Sci. 16(3) Behavioural Types
Resource Theories: RSSL19 (Draft)
11 / 12
SLIDE 62 Ongoing & Future Work
Tractable semantics for unitary application
Unitaries as path-sum actions (Amy, QPL ’18) based on Feyman path integrals
Quantum Assertion Logic Linear Dependent Type Theory: FKS, LICS ’20 Circuits as Arrows: VAS06, Math. Struct. Comput. Sci. 16(3) Behavioural Types
Resource Theories: RSSL19 (Draft) Heisenberg Representation of QM: RSSL, QPL ’20
11 / 12
SLIDE 63 Conclusion
We combined ideas from Hoare Type Theory and Quantum IO Monad to develop Quantum Hoare Type Theory, a dependently typed functional language with support for quantum computation.
12 / 12
SLIDE 64 Conclusion
We combined ideas from Hoare Type Theory and Quantum IO Monad to develop Quantum Hoare Type Theory, a dependently typed functional language with support for quantum computation. This is ongoing work with potential to be a unified framework for programming, specification, and reasoning about quantum programs.
12 / 12
SLIDE 65 Conclusion
We combined ideas from Hoare Type Theory and Quantum IO Monad to develop Quantum Hoare Type Theory, a dependently typed functional language with support for quantum computation. This is ongoing work with potential to be a unified framework for programming, specification, and reasoning about quantum programs. Many exciting challenges ahead!
12 / 12