Quantum Hoare Type Theory John Reppy Kartik Singhal Department of - - PowerPoint PPT Presentation

quantum hoare type theory
SMART_READER_LITE
LIVE PREVIEW

Quantum Hoare Type Theory John Reppy Kartik Singhal Department of - - PowerPoint PPT Presentation

Quantum Hoare Type Theory John Reppy Kartik Singhal Department of Computer Science University of Chicago Quantum Physics and Logic (QPL) 2020 Quantum programming is inherently imperative and difficult to reason about 2 / 12 Quantum


slide-1
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
SLIDE 2

Quantum programming is inherently imperative and difficult to reason about

2 / 12

slide-3
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
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
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
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
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
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
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
SLIDE 10

Hoare Types specify pre and postconditions and are very expressive

∆.Ψ.{P} x : A {Q}

4 / 12

slide-11
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
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
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
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
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
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

  • - initialization

applyU :: U → QIO ()

  • - apply a unitary

measQbit :: Qbit → QIO Bool

  • - measurement

5 / 12

slide-17
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

  • - initialization

applyU :: U → QIO ()

  • - apply a unitary

measQbit :: Qbit → QIO Bool

  • - measurement

Arbitrary unitaries can be defined using:

rot :: Qbit → ((Bool, Bool) → C) → U ifQ :: Qbit → U → U

5 / 12

slide-18
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

  • - initialization

applyU :: U → QIO ()

  • - apply a unitary

measQbit :: Qbit → QIO Bool

  • - measurement

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
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
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
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
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
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
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
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
SLIDE 26

Strongest Postcondition for Initialization

x ⇐ mkQbit M; E

7 / 12

slide-27
SLIDE 27

Strongest Postcondition for Initialization

x ⇐ mkQbit M; E HTT uses bidirectional typing for type inference, where

7 / 12

slide-28
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
SLIDE 43

Verifying Hello Quantum World

hqw : {emp} r : Bool {emp ∧ Id(r, false)} = do q ⇐ mkQbit false; measQbit q

9 / 12

slide-44
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
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)}

  • - P0: emp

= do q ⇐ mkQbit false;

9 / 12

slide-46
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)}

  • - P0: emp

= do q ⇐ mkQbit false;

  • - P1: P0 ◦ (q → |0)

measQbit q

9 / 12

slide-47
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)}

  • - P0: emp

= do q ⇐ mkQbit false;

  • - P1: P0 ◦ (q → |0)

measQbit q

  • - P2: P1 ◦ ((q → -) ⊸ emp)

9 / 12

slide-48
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)}

  • - P0: emp

= do q ⇐ mkQbit false;

  • - P1: P0 ◦ (q → |0)

measQbit q

  • - P2: P1 ◦ ((q → -) ⊸ emp)

Successful type checking implies correctness

  • f the program to given specifications.

9 / 12

slide-49
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
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}

  • - P0: emp

= do q ⇐ mkQbit false;

10 / 12

slide-51
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}

  • - P0: emp

= do q ⇐ mkQbit false;

  • - P1: P0 ◦ (q → |0)

applyU (H q);

10 / 12

slide-52
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}

  • - P0: emp

= do q ⇐ mkQbit false;

  • - P1: P0 ◦ (q → |0)

applyU (H q);

  • - P2: P1 ◦ ((q → |0) ⊸ (q → |+))

measQbit q

10 / 12

slide-53
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}

  • - P0: emp

= do q ⇐ mkQbit false;

  • - P1: P0 ◦ (q → |0)

applyU (H q);

  • - P2: P1 ◦ ((q → |0) ⊸ (q → |+))

measQbit q

  • - P3: P2 ◦ ((q → -) ⊸ emp)

10 / 12

slide-54
SLIDE 54

Ongoing & Future Work

11 / 12

slide-55
SLIDE 55

Ongoing & Future Work

Tractable semantics for unitary application

11 / 12

slide-56
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
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
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
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
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
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
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
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
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
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