foundations of quantum programming - tsinghua...

121
Foundations of Quantum Programming Mingsheng Ying University of Technology Sydney, Australia Institute of Software, Chinese Academy of Sciences Tsinghua University, China

Upload: tranhanh

Post on 01-May-2019

226 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Foundations of Quantum Programming

Mingsheng Ying

University of Technology Sydney, AustraliaInstitute of Software, Chinese Academy of Sciences

Tsinghua University, China

Page 2: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Outline

Introduction

Syntax of Quantum Programs

Operational Semantics

Denotational Semantics

(Floyd-)Hoare Logic for Quantum Programs

Research Problems

Page 3: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Outline

Introduction

Syntax of Quantum Programs

Operational Semantics

Denotational Semantics

(Floyd-)Hoare Logic for Quantum Programs

Research Problems

Page 4: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

How to program quantum computers?

I Quantum algorithms:

Deutsch-Josza, Grover, Shor, HHL, ...

Quantum algorithm zoo (http://math.nist.gov/quantum/zoo/)

I Quantum computers:

IBM Q (20 qubits — Nov 2017; 50 qubits — 2018)

Google (49 qubits — 2018)

Intel (17 qubits — Oct 2017)

Page 5: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

How to program quantum computers?

I Quantum algorithms:

Deutsch-Josza, Grover, Shor, HHL, ...

Quantum algorithm zoo (http://math.nist.gov/quantum/zoo/)I Quantum computers:

IBM Q (20 qubits — Nov 2017; 50 qubits — 2018)

Google (49 qubits — 2018)

Intel (17 qubits — Oct 2017)

Page 6: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Quantum programming languages

I Q# @Microsoft

I Open Fermion @GoogleI Quil @RiggetiI Quipper @DalhousieI Scaffold @PrincetonI Project Q @ETHI QWire @UPennI Q|SI> @UTS

Page 7: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Quantum programming languages

I Q# @MicrosoftI Open Fermion @Google

I Quil @RiggetiI Quipper @DalhousieI Scaffold @PrincetonI Project Q @ETHI QWire @UPennI Q|SI> @UTS

Page 8: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Quantum programming languages

I Q# @MicrosoftI Open Fermion @GoogleI Quil @Riggeti

I Quipper @DalhousieI Scaffold @PrincetonI Project Q @ETHI QWire @UPennI Q|SI> @UTS

Page 9: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Quantum programming languages

I Q# @MicrosoftI Open Fermion @GoogleI Quil @RiggetiI Quipper @Dalhousie

I Scaffold @PrincetonI Project Q @ETHI QWire @UPennI Q|SI> @UTS

Page 10: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Quantum programming languages

I Q# @MicrosoftI Open Fermion @GoogleI Quil @RiggetiI Quipper @DalhousieI Scaffold @Princeton

I Project Q @ETHI QWire @UPennI Q|SI> @UTS

Page 11: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Quantum programming languages

I Q# @MicrosoftI Open Fermion @GoogleI Quil @RiggetiI Quipper @DalhousieI Scaffold @PrincetonI Project Q @ETH

I QWire @UPennI Q|SI> @UTS

Page 12: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Quantum programming languages

I Q# @MicrosoftI Open Fermion @GoogleI Quil @RiggetiI Quipper @DalhousieI Scaffold @PrincetonI Project Q @ETHI QWire @UPenn

I Q|SI> @UTS

Page 13: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Quantum programming languages

I Q# @MicrosoftI Open Fermion @GoogleI Quil @RiggetiI Quipper @DalhousieI Scaffold @PrincetonI Project Q @ETHI QWire @UPennI Q|SI> @UTS

Page 14: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

This lectureI Principles underlying all of the quantum programming

languages

I Not the languages themselves.

I Reference:M. S. Ying, Foundations of Quantum Programming, MorganKaufmann 2016, Chapters 3 and 4.

Page 15: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

This lectureI Principles underlying all of the quantum programming

languagesI Not the languages themselves.

I Reference:M. S. Ying, Foundations of Quantum Programming, MorganKaufmann 2016, Chapters 3 and 4.

Page 16: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

This lectureI Principles underlying all of the quantum programming

languagesI Not the languages themselves.

I Reference:M. S. Ying, Foundations of Quantum Programming, MorganKaufmann 2016, Chapters 3 and 4.

Page 17: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Programming languages and tools

Programming languages are notations used for specifying, organisingand reasoning about computations.

[R. Sethi, Programming languages: Concepts and Constructs]

I Semantics

I Turing-complete?I ComiplersI Program analysis: Termination, ...I How to verify correctness of your programs?I ......

Page 18: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Programming languages and tools

Programming languages are notations used for specifying, organisingand reasoning about computations.

[R. Sethi, Programming languages: Concepts and Constructs]

I SemanticsI Turing-complete?

I ComiplersI Program analysis: Termination, ...I How to verify correctness of your programs?I ......

Page 19: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Programming languages and tools

Programming languages are notations used for specifying, organisingand reasoning about computations.

[R. Sethi, Programming languages: Concepts and Constructs]

I SemanticsI Turing-complete?I Comiplers

I Program analysis: Termination, ...I How to verify correctness of your programs?I ......

Page 20: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Programming languages and tools

Programming languages are notations used for specifying, organisingand reasoning about computations.

[R. Sethi, Programming languages: Concepts and Constructs]

I SemanticsI Turing-complete?I ComiplersI Program analysis: Termination, ...

I How to verify correctness of your programs?I ......

Page 21: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Programming languages and tools

Programming languages are notations used for specifying, organisingand reasoning about computations.

[R. Sethi, Programming languages: Concepts and Constructs]

I SemanticsI Turing-complete?I ComiplersI Program analysis: Termination, ...I How to verify correctness of your programs?

I ......

Page 22: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Programming languages and tools

Programming languages are notations used for specifying, organisingand reasoning about computations.

[R. Sethi, Programming languages: Concepts and Constructs]

I SemanticsI Turing-complete?I ComiplersI Program analysis: Termination, ...I How to verify correctness of your programs?I ......

Page 23: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Quantum circuit vs Quantum programs

Example: Quantum walk on a circle with an absorbing boundary.I Hd = span{|L〉, |R〉}— the direction space, |L〉 and |R〉 indicate

directions left and right, respectively.

I Hp = span{|0〉, |1〉, ..., |n− 1〉}— the position space withorthonormal basis states, the vector |i〉 denotes position i for each0 ≤ i ≤ n− 1.

I The state space of the walk — H = Hp ⊗Hd.I The initial state — |0〉p|L〉d.

Page 24: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Quantum circuit vs Quantum programs

Example: Quantum walk on a circle with an absorbing boundary.I Hd = span{|L〉, |R〉}— the direction space, |L〉 and |R〉 indicate

directions left and right, respectively.I Hp = span{|0〉, |1〉, ..., |n− 1〉}— the position space with

orthonormal basis states, the vector |i〉 denotes position i for each0 ≤ i ≤ n− 1.

I The state space of the walk — H = Hp ⊗Hd.I The initial state — |0〉p|L〉d.

Page 25: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Quantum circuit vs Quantum programs

Example: Quantum walk on a circle with an absorbing boundary.I Hd = span{|L〉, |R〉}— the direction space, |L〉 and |R〉 indicate

directions left and right, respectively.I Hp = span{|0〉, |1〉, ..., |n− 1〉}— the position space with

orthonormal basis states, the vector |i〉 denotes position i for each0 ≤ i ≤ n− 1.

I The state space of the walk — H = Hp ⊗Hd.

I The initial state — |0〉p|L〉d.

Page 26: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Quantum circuit vs Quantum programs

Example: Quantum walk on a circle with an absorbing boundary.I Hd = span{|L〉, |R〉}— the direction space, |L〉 and |R〉 indicate

directions left and right, respectively.I Hp = span{|0〉, |1〉, ..., |n− 1〉}— the position space with

orthonormal basis states, the vector |i〉 denotes position i for each0 ≤ i ≤ n− 1.

I The state space of the walk — H = Hp ⊗Hd.I The initial state — |0〉p|L〉d.

Page 27: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Quantum circuit vs Quantum programsI Each step of the walk:

1. Measure the system to see whether the current position is 1(absorbing boundary). If “yes”, terminates; otherwise, continues:

M = {Myes = |1〉〈1| ⊗ Id, Mno = I−Myes};

2. A “coin-tossing”operator C = 1√2

(1 11 −1

)is applied on the

direction space;3. A shift operator

S =n−1

∑i=0|i 1〉〈i| ⊗ |L〉〈L|+

n−1

∑i=0|i⊕ 1〉〈i| ⊗ |R〉〈R|

is performed on the state space H.

I Question: How to specify it in the circuit language?

Page 28: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Quantum circuit vs Quantum programsI Each step of the walk:

1. Measure the system to see whether the current position is 1(absorbing boundary). If “yes”, terminates; otherwise, continues:

M = {Myes = |1〉〈1| ⊗ Id, Mno = I−Myes};

2. A “coin-tossing”operator C = 1√2

(1 11 −1

)is applied on the

direction space;3. A shift operator

S =n−1

∑i=0|i 1〉〈i| ⊗ |L〉〈L|+

n−1

∑i=0|i⊕ 1〉〈i| ⊗ |R〉〈R|

is performed on the state space H.

I Question: How to specify it in the circuit language?

Page 29: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Quantum circuit vs Quantum programsI Each step of the walk:

1. Measure the system to see whether the current position is 1(absorbing boundary). If “yes”, terminates; otherwise, continues:

M = {Myes = |1〉〈1| ⊗ Id, Mno = I−Myes};

2. A “coin-tossing”operator C = 1√2

(1 11 −1

)is applied on the

direction space;

3. A shift operator

S =n−1

∑i=0|i 1〉〈i| ⊗ |L〉〈L|+

n−1

∑i=0|i⊕ 1〉〈i| ⊗ |R〉〈R|

is performed on the state space H.

I Question: How to specify it in the circuit language?

Page 30: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Quantum circuit vs Quantum programsI Each step of the walk:

1. Measure the system to see whether the current position is 1(absorbing boundary). If “yes”, terminates; otherwise, continues:

M = {Myes = |1〉〈1| ⊗ Id, Mno = I−Myes};

2. A “coin-tossing”operator C = 1√2

(1 11 −1

)is applied on the

direction space;3. A shift operator

S =n−1

∑i=0|i 1〉〈i| ⊗ |L〉〈L|+

n−1

∑i=0|i⊕ 1〉〈i| ⊗ |R〉〈R|

is performed on the state space H.

I Question: How to specify it in the circuit language?

Page 31: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Quantum circuit vs Quantum programsI Each step of the walk:

1. Measure the system to see whether the current position is 1(absorbing boundary). If “yes”, terminates; otherwise, continues:

M = {Myes = |1〉〈1| ⊗ Id, Mno = I−Myes};

2. A “coin-tossing”operator C = 1√2

(1 11 −1

)is applied on the

direction space;3. A shift operator

S =n−1

∑i=0|i 1〉〈i| ⊗ |L〉〈L|+

n−1

∑i=0|i⊕ 1〉〈i| ⊗ |R〉〈R|

is performed on the state space H.

I Question: How to specify it in the circuit language?

Page 32: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Outline

Introduction

Syntax of Quantum Programs

Operational Semantics

Denotational Semantics

(Floyd-)Hoare Logic for Quantum Programs

Research Problems

Page 33: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Classical while-Language

S ::= skip | u := t |S1; S2 | if b then S1 else S2 fi| while b do S od.

I Conditional statement can be generalised to case statement:

if G1 → S1

� G2 → S2

......� Gn → Sn

fi

or more compactly:

if (�i ·Gi → Si) fi

Page 34: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Quantum while-Language

I Alphabet: a countably infinite set Var of quantum variablesq, q′, q0, q1, q2, ....

I Each quantum variable q ∈ Var has a typeHq (a Hilbert space),e.g.

Boolean = H2, integer = H∞.

I A quantum register is a finite sequence q = q1, ..., qn of distinctquantum variables. State Hilbert space:

Hq =n⊗

i=1

Hqi .

Page 35: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Quantum while-Language

I Alphabet: a countably infinite set Var of quantum variablesq, q′, q0, q1, q2, ....

I Each quantum variable q ∈ Var has a typeHq (a Hilbert space),e.g.

Boolean = H2, integer = H∞.

I A quantum register is a finite sequence q = q1, ..., qn of distinctquantum variables. State Hilbert space:

Hq =n⊗

i=1

Hqi .

Page 36: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Quantum while-Language

I Alphabet: a countably infinite set Var of quantum variablesq, q′, q0, q1, q2, ....

I Each quantum variable q ∈ Var has a typeHq (a Hilbert space),e.g.

Boolean = H2, integer = H∞.

I A quantum register is a finite sequence q = q1, ..., qn of distinctquantum variables. State Hilbert space:

Hq =n⊗

i=1

Hqi .

Page 37: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Syntax of Quantum Programs

S ::= skip | q := |0〉 | q := U[q] | S1; S2

| if (�m ·M[q] = m→ Sm) fi| while M[q] = 1 do S od.

Exercise 1Write quantum walk as a program in quantum while-language.

Page 38: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Syntax of Quantum Programs

S ::= skip | q := |0〉 | q := U[q] | S1; S2

| if (�m ·M[q] = m→ Sm) fi| while M[q] = 1 do S od.

Exercise 1Write quantum walk as a program in quantum while-language.

Page 39: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Outline

Introduction

Syntax of Quantum Programs

Operational Semantics

Denotational Semantics

(Floyd-)Hoare Logic for Quantum Programs

Research Problems

Page 40: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

NotationsI partial density operator: positive operator ρ, tr(ρ) ≤ 1.

I D(H) — the set of partial density operators inH.I State Hilbert space of all quantum variables:

Hall =⊗

q∈VarHq.

I E — empty program; i.e. termination.I Configuration: pair 〈S, ρ〉, where:

1. S is a quantum program or the empty program E;2. ρ ∈ D(Hall), denoting the (global) state of quantum variables.

I Transition:〈S, ρ〉 → 〈S′, ρ′〉

Page 41: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

NotationsI partial density operator: positive operator ρ, tr(ρ) ≤ 1.I D(H) — the set of partial density operators inH.

I State Hilbert space of all quantum variables:

Hall =⊗

q∈VarHq.

I E — empty program; i.e. termination.I Configuration: pair 〈S, ρ〉, where:

1. S is a quantum program or the empty program E;2. ρ ∈ D(Hall), denoting the (global) state of quantum variables.

I Transition:〈S, ρ〉 → 〈S′, ρ′〉

Page 42: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

NotationsI partial density operator: positive operator ρ, tr(ρ) ≤ 1.I D(H) — the set of partial density operators inH.I State Hilbert space of all quantum variables:

Hall =⊗

q∈VarHq.

I E — empty program; i.e. termination.I Configuration: pair 〈S, ρ〉, where:

1. S is a quantum program or the empty program E;2. ρ ∈ D(Hall), denoting the (global) state of quantum variables.

I Transition:〈S, ρ〉 → 〈S′, ρ′〉

Page 43: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

NotationsI partial density operator: positive operator ρ, tr(ρ) ≤ 1.I D(H) — the set of partial density operators inH.I State Hilbert space of all quantum variables:

Hall =⊗

q∈VarHq.

I E — empty program; i.e. termination.

I Configuration: pair 〈S, ρ〉, where:

1. S is a quantum program or the empty program E;2. ρ ∈ D(Hall), denoting the (global) state of quantum variables.

I Transition:〈S, ρ〉 → 〈S′, ρ′〉

Page 44: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

NotationsI partial density operator: positive operator ρ, tr(ρ) ≤ 1.I D(H) — the set of partial density operators inH.I State Hilbert space of all quantum variables:

Hall =⊗

q∈VarHq.

I E — empty program; i.e. termination.I Configuration: pair 〈S, ρ〉, where:

1. S is a quantum program or the empty program E;2. ρ ∈ D(Hall), denoting the (global) state of quantum variables.

I Transition:〈S, ρ〉 → 〈S′, ρ′〉

Page 45: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

NotationsI partial density operator: positive operator ρ, tr(ρ) ≤ 1.I D(H) — the set of partial density operators inH.I State Hilbert space of all quantum variables:

Hall =⊗

q∈VarHq.

I E — empty program; i.e. termination.I Configuration: pair 〈S, ρ〉, where:

1. S is a quantum program or the empty program E;

2. ρ ∈ D(Hall), denoting the (global) state of quantum variables.I Transition:

〈S, ρ〉 → 〈S′, ρ′〉

Page 46: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

NotationsI partial density operator: positive operator ρ, tr(ρ) ≤ 1.I D(H) — the set of partial density operators inH.I State Hilbert space of all quantum variables:

Hall =⊗

q∈VarHq.

I E — empty program; i.e. termination.I Configuration: pair 〈S, ρ〉, where:

1. S is a quantum program or the empty program E;2. ρ ∈ D(Hall), denoting the (global) state of quantum variables.

I Transition:〈S, ρ〉 → 〈S′, ρ′〉

Page 47: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

NotationsI partial density operator: positive operator ρ, tr(ρ) ≤ 1.I D(H) — the set of partial density operators inH.I State Hilbert space of all quantum variables:

Hall =⊗

q∈VarHq.

I E — empty program; i.e. termination.I Configuration: pair 〈S, ρ〉, where:

1. S is a quantum program or the empty program E;2. ρ ∈ D(Hall), denoting the (global) state of quantum variables.

I Transition:〈S, ρ〉 → 〈S′, ρ′〉

Page 48: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Operational Semantics

(SK) 〈skip, ρ〉 → 〈E, ρ〉

(IN)〈q := |0〉, ρ〉 → 〈E, ρ

q0〉

where : ρq0 = ∑

i|0〉q〈i|ρ|i〉q〈0|

(UT) 〈q := U[q], ρ〉 → 〈E, UρU†〉

(SC)〈S1, ρ〉 → 〈S′1, ρ′〉

〈S1; S2, ρ〉 → 〈S′1; S2, ρ′〉

where : E; S2 = S2.

Page 49: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Operational Semantics

(IF)〈if (�m ·M[q] = m→ Sm) fi, ρ〉 → 〈Sm, MmρM†

m〉

for each possible outcome m of measurement M = {Mm}.

(L0)〈while M[q] = 1 do S od, ρ〉 → 〈E, M0ρM†

0〉

(L1)〈while M[q] = 1 do S od, ρ〉 → 〈S; while M[q] = 1 do S od, M1ρM†

1〉

Page 50: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Computation of Programs

1. A (finite or infinite) transition sequence of program S with inputρ ∈ D(Hall):

〈S, ρ〉 → 〈S1, ρ1〉 → ...→ 〈Sn, ρn〉 → 〈Sn+1, ρn+1〉 → ...

such that ρn , 0 for all n (except the last n in the case of a finitesequence).

2. If this sequence cannot be extended, it is called a computation.

I If it is finite and its last configuration is 〈E, ρ′〉, we say it terminatesin ρ′.

I If it is infinite, we say it diverges.

Page 51: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Computation of Programs

1. A (finite or infinite) transition sequence of program S with inputρ ∈ D(Hall):

〈S, ρ〉 → 〈S1, ρ1〉 → ...→ 〈Sn, ρn〉 → 〈Sn+1, ρn+1〉 → ...

such that ρn , 0 for all n (except the last n in the case of a finitesequence).

2. If this sequence cannot be extended, it is called a computation.

I If it is finite and its last configuration is 〈E, ρ′〉, we say it terminatesin ρ′.

I If it is infinite, we say it diverges.

Page 52: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Computation of Programs

1. A (finite or infinite) transition sequence of program S with inputρ ∈ D(Hall):

〈S, ρ〉 → 〈S1, ρ1〉 → ...→ 〈Sn, ρn〉 → 〈Sn+1, ρn+1〉 → ...

such that ρn , 0 for all n (except the last n in the case of a finitesequence).

2. If this sequence cannot be extended, it is called a computation.I If it is finite and its last configuration is 〈E, ρ′〉, we say it terminates

in ρ′.

I If it is infinite, we say it diverges.

Page 53: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Computation of Programs

1. A (finite or infinite) transition sequence of program S with inputρ ∈ D(Hall):

〈S, ρ〉 → 〈S1, ρ1〉 → ...→ 〈Sn, ρn〉 → 〈Sn+1, ρn+1〉 → ...

such that ρn , 0 for all n (except the last n in the case of a finitesequence).

2. If this sequence cannot be extended, it is called a computation.I If it is finite and its last configuration is 〈E, ρ′〉, we say it terminates

in ρ′.I If it is infinite, we say it diverges.

Page 54: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

NotationI Write:

〈S, ρ〉 →n 〈S′, ρ′〉

if there are configurations 〈S1, ρ1〉, ..., 〈Sn−1, ρn−1〉 such that

〈S, ρ〉 → 〈S1, ρ1〉 → ...→ 〈Sn−1, ρn−1〉 → 〈S′, ρ′〉,

I Write→∗ for the reflexive and transitive closures of→:

〈S, ρ〉 →∗ 〈S′, ρ′〉

if and only if 〈S, ρ〉 →n 〈S′, ρ′〉 for some n ≥ 0.

Page 55: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

NotationI Write:

〈S, ρ〉 →n 〈S′, ρ′〉

if there are configurations 〈S1, ρ1〉, ..., 〈Sn−1, ρn−1〉 such that

〈S, ρ〉 → 〈S1, ρ1〉 → ...→ 〈Sn−1, ρn−1〉 → 〈S′, ρ′〉,

I Write→∗ for the reflexive and transitive closures of→:

〈S, ρ〉 →∗ 〈S′, ρ′〉

if and only if 〈S, ρ〉 →n 〈S′, ρ′〉 for some n ≥ 0.

Page 56: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Outline

Introduction

Syntax of Quantum Programs

Operational Semantics

Denotational Semantics

(Floyd-)Hoare Logic for Quantum Programs

Research Problems

Page 57: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Semantic FunctionSemantic function of program S:

~S� : D(Hall)→ D(Hall)

~S�(ρ) = ∑{|ρ′ : 〈S, ρ〉 →∗ 〈E, ρ′〉|

}

Exercise 2Try to compute semantic function of your quantum walk program.

Page 58: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Semantic FunctionSemantic function of program S:

~S� : D(Hall)→ D(Hall)

~S�(ρ) = ∑{|ρ′ : 〈S, ρ〉 →∗ 〈E, ρ′〉|

}Exercise 2Try to compute semantic function of your quantum walk program.

Page 59: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Structural Representation

1. ~skip�(ρ) = ρ.

2. ~q := |0〉�(ρ) = ∑i |0〉q〈i|ρ|i〉q〈0|.3. ~q := U[q]�(ρ) = UρU†.4. ~S1; S2�(ρ) = ~S2�(~S1�(ρ)).5. ~if (�m ·M[q] = m→ Sm) fi�(ρ) = ∑m~Sm�(MmρM†

m).6. ~while M[q] = 1 do S od�(ρ) = ???

Page 60: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Structural Representation

1. ~skip�(ρ) = ρ.2. ~q := |0〉�(ρ) = ∑i |0〉q〈i|ρ|i〉q〈0|.

3. ~q := U[q]�(ρ) = UρU†.4. ~S1; S2�(ρ) = ~S2�(~S1�(ρ)).5. ~if (�m ·M[q] = m→ Sm) fi�(ρ) = ∑m~Sm�(MmρM†

m).6. ~while M[q] = 1 do S od�(ρ) = ???

Page 61: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Structural Representation

1. ~skip�(ρ) = ρ.2. ~q := |0〉�(ρ) = ∑i |0〉q〈i|ρ|i〉q〈0|.3. ~q := U[q]�(ρ) = UρU†.

4. ~S1; S2�(ρ) = ~S2�(~S1�(ρ)).5. ~if (�m ·M[q] = m→ Sm) fi�(ρ) = ∑m~Sm�(MmρM†

m).6. ~while M[q] = 1 do S od�(ρ) = ???

Page 62: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Structural Representation

1. ~skip�(ρ) = ρ.2. ~q := |0〉�(ρ) = ∑i |0〉q〈i|ρ|i〉q〈0|.3. ~q := U[q]�(ρ) = UρU†.4. ~S1; S2�(ρ) = ~S2�(~S1�(ρ)).

5. ~if (�m ·M[q] = m→ Sm) fi�(ρ) = ∑m~Sm�(MmρM†m).

6. ~while M[q] = 1 do S od�(ρ) = ???

Page 63: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Structural Representation

1. ~skip�(ρ) = ρ.2. ~q := |0〉�(ρ) = ∑i |0〉q〈i|ρ|i〉q〈0|.3. ~q := U[q]�(ρ) = UρU†.4. ~S1; S2�(ρ) = ~S2�(~S1�(ρ)).5. ~if (�m ·M[q] = m→ Sm) fi�(ρ) = ∑m~Sm�(MmρM†

m).

6. ~while M[q] = 1 do S od�(ρ) = ???

Page 64: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Structural Representation

1. ~skip�(ρ) = ρ.2. ~q := |0〉�(ρ) = ∑i |0〉q〈i|ρ|i〉q〈0|.3. ~q := U[q]�(ρ) = UρU†.4. ~S1; S2�(ρ) = ~S2�(~S1�(ρ)).5. ~if (�m ·M[q] = m→ Sm) fi�(ρ) = ∑m~Sm�(MmρM†

m).6. ~while M[q] = 1 do S od�(ρ) = ???

Page 65: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Basic Lattice TheoryI A partial order (L,v): L is a nonempty set, v is a binary relation

on L satisfying:

1. Reflexivity: x v x for all x ∈ L;2. Antisymmetry: x v y and y v x imply x = y for all x, y ∈ L;3. Transitivity: x v y and y v z imply x v z for all x, y, z ∈ L.

I x ∈ L is called the least element when x v y for all y ∈ L.I x ∈ L is called an upper bound of a subset X ⊆ L if y v x for all

x ∈ X.I x is called the least upper bound of X, written x =

⊔X, if

I x is an upper bound of X;I for any upper bound y of X, x v y.

Page 66: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Basic Lattice TheoryI A partial order (L,v): L is a nonempty set, v is a binary relation

on L satisfying:1. Reflexivity: x v x for all x ∈ L;

2. Antisymmetry: x v y and y v x imply x = y for all x, y ∈ L;3. Transitivity: x v y and y v z imply x v z for all x, y, z ∈ L.

I x ∈ L is called the least element when x v y for all y ∈ L.I x ∈ L is called an upper bound of a subset X ⊆ L if y v x for all

x ∈ X.I x is called the least upper bound of X, written x =

⊔X, if

I x is an upper bound of X;I for any upper bound y of X, x v y.

Page 67: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Basic Lattice TheoryI A partial order (L,v): L is a nonempty set, v is a binary relation

on L satisfying:1. Reflexivity: x v x for all x ∈ L;2. Antisymmetry: x v y and y v x imply x = y for all x, y ∈ L;

3. Transitivity: x v y and y v z imply x v z for all x, y, z ∈ L.I x ∈ L is called the least element when x v y for all y ∈ L.I x ∈ L is called an upper bound of a subset X ⊆ L if y v x for all

x ∈ X.I x is called the least upper bound of X, written x =

⊔X, if

I x is an upper bound of X;I for any upper bound y of X, x v y.

Page 68: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Basic Lattice TheoryI A partial order (L,v): L is a nonempty set, v is a binary relation

on L satisfying:1. Reflexivity: x v x for all x ∈ L;2. Antisymmetry: x v y and y v x imply x = y for all x, y ∈ L;3. Transitivity: x v y and y v z imply x v z for all x, y, z ∈ L.

I x ∈ L is called the least element when x v y for all y ∈ L.I x ∈ L is called an upper bound of a subset X ⊆ L if y v x for all

x ∈ X.I x is called the least upper bound of X, written x =

⊔X, if

I x is an upper bound of X;I for any upper bound y of X, x v y.

Page 69: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Basic Lattice TheoryI A partial order (L,v): L is a nonempty set, v is a binary relation

on L satisfying:1. Reflexivity: x v x for all x ∈ L;2. Antisymmetry: x v y and y v x imply x = y for all x, y ∈ L;3. Transitivity: x v y and y v z imply x v z for all x, y, z ∈ L.

I x ∈ L is called the least element when x v y for all y ∈ L.

I x ∈ L is called an upper bound of a subset X ⊆ L if y v x for allx ∈ X.

I x is called the least upper bound of X, written x =⊔

X, if

I x is an upper bound of X;I for any upper bound y of X, x v y.

Page 70: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Basic Lattice TheoryI A partial order (L,v): L is a nonempty set, v is a binary relation

on L satisfying:1. Reflexivity: x v x for all x ∈ L;2. Antisymmetry: x v y and y v x imply x = y for all x, y ∈ L;3. Transitivity: x v y and y v z imply x v z for all x, y, z ∈ L.

I x ∈ L is called the least element when x v y for all y ∈ L.I x ∈ L is called an upper bound of a subset X ⊆ L if y v x for all

x ∈ X.

I x is called the least upper bound of X, written x =⊔

X, if

I x is an upper bound of X;I for any upper bound y of X, x v y.

Page 71: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Basic Lattice TheoryI A partial order (L,v): L is a nonempty set, v is a binary relation

on L satisfying:1. Reflexivity: x v x for all x ∈ L;2. Antisymmetry: x v y and y v x imply x = y for all x, y ∈ L;3. Transitivity: x v y and y v z imply x v z for all x, y, z ∈ L.

I x ∈ L is called the least element when x v y for all y ∈ L.I x ∈ L is called an upper bound of a subset X ⊆ L if y v x for all

x ∈ X.I x is called the least upper bound of X, written x =

⊔X, if

I x is an upper bound of X;I for any upper bound y of X, x v y.

Page 72: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Basic Lattice TheoryI A partial order (L,v): L is a nonempty set, v is a binary relation

on L satisfying:1. Reflexivity: x v x for all x ∈ L;2. Antisymmetry: x v y and y v x imply x = y for all x, y ∈ L;3. Transitivity: x v y and y v z imply x v z for all x, y, z ∈ L.

I x ∈ L is called the least element when x v y for all y ∈ L.I x ∈ L is called an upper bound of a subset X ⊆ L if y v x for all

x ∈ X.I x is called the least upper bound of X, written x =

⊔X, if

I x is an upper bound of X;

I for any upper bound y of X, x v y.

Page 73: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Basic Lattice TheoryI A partial order (L,v): L is a nonempty set, v is a binary relation

on L satisfying:1. Reflexivity: x v x for all x ∈ L;2. Antisymmetry: x v y and y v x imply x = y for all x, y ∈ L;3. Transitivity: x v y and y v z imply x v z for all x, y, z ∈ L.

I x ∈ L is called the least element when x v y for all y ∈ L.I x ∈ L is called an upper bound of a subset X ⊆ L if y v x for all

x ∈ X.I x is called the least upper bound of X, written x =

⊔X, if

I x is an upper bound of X;I for any upper bound y of X, x v y.

Page 74: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Basic Lattice TheoryI A complete partial order (CPO) is a partial order (L,v):

1. it has the least element 0;2.⊔∞

n=0 xn exists for any increasing sequence {xn}:

x0 v ... v xn v xn+1 v ....

I A function f from L into itself is continuous if

f

(⊔n

xn

)=⊔n

f (xn)

for any increasing sequence {xn} in L.

Page 75: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Basic Lattice TheoryI A complete partial order (CPO) is a partial order (L,v):

1. it has the least element 0;

2.⊔∞

n=0 xn exists for any increasing sequence {xn}:

x0 v ... v xn v xn+1 v ....

I A function f from L into itself is continuous if

f

(⊔n

xn

)=⊔n

f (xn)

for any increasing sequence {xn} in L.

Page 76: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Basic Lattice TheoryI A complete partial order (CPO) is a partial order (L,v):

1. it has the least element 0;2.⊔∞

n=0 xn exists for any increasing sequence {xn}:

x0 v ... v xn v xn+1 v ....

I A function f from L into itself is continuous if

f

(⊔n

xn

)=⊔n

f (xn)

for any increasing sequence {xn} in L.

Page 77: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Basic Lattice TheoryI A complete partial order (CPO) is a partial order (L,v):

1. it has the least element 0;2.⊔∞

n=0 xn exists for any increasing sequence {xn}:

x0 v ... v xn v xn+1 v ....

I A function f from L into itself is continuous if

f

(⊔n

xn

)=⊔n

f (xn)

for any increasing sequence {xn} in L.

Page 78: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Knaster-Tarski Theorem

Let (L,v) be a CPO and function f : L→ L continuous. Then f hasthe least fixed point

µf =∞⊔

n=0f (n)(0)

where {f (0)(0) = 0,f (n+1)(0) = f (f (n)(0)) for n ≥ 0.

Page 79: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

CPO of Partial Density Operators

I Löwner order: operators A v B⇔ B−A is positive.

I (D(H),v) is a CPO with the zero operator 0H as its leastelement.

Exercise 3Prove the above statement for finite-dimensionalH.

Page 80: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

CPO of Partial Density Operators

I Löwner order: operators A v B⇔ B−A is positive.I (D(H),v) is a CPO with the zero operator 0H as its least

element.

Exercise 3Prove the above statement for finite-dimensionalH.

Page 81: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

CPO of Super-operators

I Each super-operator inH is a continuous function from(D(H),v) into itself.

I QO(H) — the set of superoperators in Hilbert spaceH.I Löwner order between operators can be lifted to a partial order

between super-operators:

E v F ⇔ E(ρ) v F (ρ) for all ρ ∈ D(H)

I (QO(H),v) is a CPO.

Page 82: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

CPO of Super-operators

I Each super-operator inH is a continuous function from(D(H),v) into itself.

I QO(H) — the set of superoperators in Hilbert spaceH.

I Löwner order between operators can be lifted to a partial orderbetween super-operators:

E v F ⇔ E(ρ) v F (ρ) for all ρ ∈ D(H)

I (QO(H),v) is a CPO.

Page 83: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

CPO of Super-operators

I Each super-operator inH is a continuous function from(D(H),v) into itself.

I QO(H) — the set of superoperators in Hilbert spaceH.I Löwner order between operators can be lifted to a partial order

between super-operators:

E v F ⇔ E(ρ) v F (ρ) for all ρ ∈ D(H)

I (QO(H),v) is a CPO.

Page 84: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

CPO of Super-operators

I Each super-operator inH is a continuous function from(D(H),v) into itself.

I QO(H) — the set of superoperators in Hilbert spaceH.I Löwner order between operators can be lifted to a partial order

between super-operators:

E v F ⇔ E(ρ) v F (ρ) for all ρ ∈ D(H)

I (QO(H),v) is a CPO.

Page 85: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Syntactic Approximation

I abort denotes a program such that

~abort�(ρ) = 0Hallfor all ρ ∈ D(H).

I Write:while ≡ while M[q] = 1 do S od.

I For integer k ≥ 0, the kth syntactic approximation while(k) ofwhile:

while(0) ≡ abort,while(k+1) ≡ if M[q] = 0→ skip

� 1→ S; while(k)

fi

Page 86: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Syntactic Approximation

I abort denotes a program such that

~abort�(ρ) = 0Hallfor all ρ ∈ D(H).

I Write:while ≡ while M[q] = 1 do S od.

I For integer k ≥ 0, the kth syntactic approximation while(k) ofwhile:

while(0) ≡ abort,while(k+1) ≡ if M[q] = 0→ skip

� 1→ S; while(k)

fi

Page 87: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Syntactic Approximation

I abort denotes a program such that

~abort�(ρ) = 0Hallfor all ρ ∈ D(H).

I Write:while ≡ while M[q] = 1 do S od.

I For integer k ≥ 0, the kth syntactic approximation while(k) ofwhile:

while(0) ≡ abort,while(k+1) ≡ if M[q] = 0→ skip

� 1→ S; while(k)

fi

Page 88: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Semantic Function of Loops

�while

�=

∞⊔k=0

�while(k)

�,

where⊔

stands for the least upper bound in CPO (QO (Hall) ,v).

Fixed Point CharacterisationFor any ρ ∈ D(Hall):

~while�(ρ) = M0ρM†0 + ~while�

(~S�

(M1ρM†

1

)).

Exercise 4Prove the above equality.

Page 89: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Semantic Function of Loops

�while

�=

∞⊔k=0

�while(k)

�,

where⊔

stands for the least upper bound in CPO (QO (Hall) ,v).

Fixed Point CharacterisationFor any ρ ∈ D(Hall):

~while�(ρ) = M0ρM†0 + ~while�

(~S�

(M1ρM†

1

)).

Exercise 4Prove the above equality.

Page 90: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Semantic Function of Loops

�while

�=

∞⊔k=0

�while(k)

�,

where⊔

stands for the least upper bound in CPO (QO (Hall) ,v).

Fixed Point CharacterisationFor any ρ ∈ D(Hall):

~while�(ρ) = M0ρM†0 + ~while�

(~S�

(M1ρM†

1

)).

Exercise 4Prove the above equality.

Page 91: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Termination and Divergence Probabilities

I For any quantum program S and ρ ∈ D(Hall):

tr(~S�(ρ)) ≤ tr(ρ).

I tr(~S�(ρ)) is the probability that program S with input ρterminates.

Page 92: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Termination and Divergence Probabilities

I For any quantum program S and ρ ∈ D(Hall):

tr(~S�(ρ)) ≤ tr(ρ).

I tr(~S�(ρ)) is the probability that program S with input ρterminates.

Page 93: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Outline

Introduction

Syntax of Quantum Programs

Operational Semantics

Denotational Semantics

(Floyd-)Hoare Logic for Quantum Programs

Research Problems

Page 94: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Quantum predicates = Quantum effects

I A quantum effect is a (Hermitian) operator 0 v M v I; that is,0 ≤ tr(Mρ) ≤ 1 for all density operators.

I tr(Mρ) may be interpreted as the expected degree to whichquantum state ρ satisfies quantum predicate M.

Page 95: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Quantum predicates = Quantum effects

I A quantum effect is a (Hermitian) operator 0 v M v I; that is,0 ≤ tr(Mρ) ≤ 1 for all density operators.

I tr(Mρ) may be interpreted as the expected degree to whichquantum state ρ satisfies quantum predicate M.

Page 96: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Correctness FormulasI A correctness formula (Hoare triple) is a statement of the form:

{P}S{Q}

where:

I S is a quantum program;I P, Q are quantum predicates inHall.I P is called the precondition, Q the postcondition.

Partial Correctness, Total Correctness

I Partial correctness: If an input to program S satisfies preconditionP, then either S does not terminate, or it terminates in a statesatisfying postcondition Q.

I Total correctness: If an input to program S satisfies precondition P,then S must terminate and it terminates in a state satisfyingpostcondition Q.

Page 97: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Correctness FormulasI A correctness formula (Hoare triple) is a statement of the form:

{P}S{Q}

where:I S is a quantum program;

I P, Q are quantum predicates inHall.I P is called the precondition, Q the postcondition.

Partial Correctness, Total Correctness

I Partial correctness: If an input to program S satisfies preconditionP, then either S does not terminate, or it terminates in a statesatisfying postcondition Q.

I Total correctness: If an input to program S satisfies precondition P,then S must terminate and it terminates in a state satisfyingpostcondition Q.

Page 98: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Correctness FormulasI A correctness formula (Hoare triple) is a statement of the form:

{P}S{Q}

where:I S is a quantum program;I P, Q are quantum predicates inHall.

I P is called the precondition, Q the postcondition.

Partial Correctness, Total Correctness

I Partial correctness: If an input to program S satisfies preconditionP, then either S does not terminate, or it terminates in a statesatisfying postcondition Q.

I Total correctness: If an input to program S satisfies precondition P,then S must terminate and it terminates in a state satisfyingpostcondition Q.

Page 99: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Correctness FormulasI A correctness formula (Hoare triple) is a statement of the form:

{P}S{Q}

where:I S is a quantum program;I P, Q are quantum predicates inHall.I P is called the precondition, Q the postcondition.

Partial Correctness, Total Correctness

I Partial correctness: If an input to program S satisfies preconditionP, then either S does not terminate, or it terminates in a statesatisfying postcondition Q.

I Total correctness: If an input to program S satisfies precondition P,then S must terminate and it terminates in a state satisfyingpostcondition Q.

Page 100: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Correctness FormulasI A correctness formula (Hoare triple) is a statement of the form:

{P}S{Q}

where:I S is a quantum program;I P, Q are quantum predicates inHall.I P is called the precondition, Q the postcondition.

Partial Correctness, Total CorrectnessI Partial correctness: If an input to program S satisfies precondition

P, then either S does not terminate, or it terminates in a statesatisfying postcondition Q.

I Total correctness: If an input to program S satisfies precondition P,then S must terminate and it terminates in a state satisfyingpostcondition Q.

Page 101: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Correctness FormulasI A correctness formula (Hoare triple) is a statement of the form:

{P}S{Q}

where:I S is a quantum program;I P, Q are quantum predicates inHall.I P is called the precondition, Q the postcondition.

Partial Correctness, Total CorrectnessI Partial correctness: If an input to program S satisfies precondition

P, then either S does not terminate, or it terminates in a statesatisfying postcondition Q.

I Total correctness: If an input to program S satisfies precondition P,then S must terminate and it terminates in a state satisfyingpostcondition Q.

Page 102: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Partial Correctness, Total Correctness (Continued)I The correctness formula {P}S{Q} is true in the sense of total

correctness, written|=tot {P}S{Q},

if:tr(Pρ) ≤ tr(Q~S�(ρ))

for all ρ ∈ D(Hall), where ~S� is the semantic function of S.

I The correctness formula {P}S{Q} is true in the sense of partialcorrectness, written

|=par {P}S{Q},

if:tr(Pρ) ≤ tr(Q~S�(ρ)) + [tr(ρ)− tr(~S�(ρ))]

for all ρ ∈ D(Hall).

Page 103: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Partial Correctness, Total Correctness (Continued)I The correctness formula {P}S{Q} is true in the sense of total

correctness, written|=tot {P}S{Q},

if:tr(Pρ) ≤ tr(Q~S�(ρ))

for all ρ ∈ D(Hall), where ~S� is the semantic function of S.I The correctness formula {P}S{Q} is true in the sense of partial

correctness, written|=par {P}S{Q},

if:tr(Pρ) ≤ tr(Q~S�(ρ)) + [tr(ρ)− tr(~S�(ρ))]

for all ρ ∈ D(Hall).

Page 104: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Proof System for Partial Correctness

(Ax− Sk) {P}Skip{P}

(Ax− In) If type(q) = Boolean, then

{|0〉q〈0|P|0〉q〈0|+ |1〉q〈0|P|0〉q〈1|}q := |0〉{P}

If type(q) = integer, then

{∞

∑n=−∞

|n〉q〈0|P|0〉q〈n|}

q := |0〉{P}

(Ax−UT) {U†PU}q := Uq{P}

Page 105: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Proof System for Partial Correctness (Continued)

(R− SC){P}S1{Q} {Q}S2{R}

{P}S1; S2{R}

(R− IF){Pm}Sm{Q} for all m{

∑m M†mPmMm

}if (�m ·M[q] = m→ Sm) fi{Q}

(R− LP){Q}S

{M†

0PM0 + M†1QM1

}{M†

0PM0 + M†1QM1}while M[q] = 1 do S od{P}

(R−Or)P v P′ {P′}S{Q′} Q′ v Q

{P}S{Q}

Page 106: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Soundness TheoremFor any quantum while-program S and quantum predicatesP, Q ∈ P(Hall):

`qPD {P}S{Q} implies |=par {P}S{Q}.

Exercise 5Prove soundness theorem.

(Relative) Completeness TheoremFor any quantum while-program S and quantum predicatesP, Q ∈ P(Hall):

|=par {P}S{Q} implies `qPD {P}S{Q}.

Page 107: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Soundness TheoremFor any quantum while-program S and quantum predicatesP, Q ∈ P(Hall):

`qPD {P}S{Q} implies |=par {P}S{Q}.

Exercise 5Prove soundness theorem.

(Relative) Completeness TheoremFor any quantum while-program S and quantum predicatesP, Q ∈ P(Hall):

|=par {P}S{Q} implies `qPD {P}S{Q}.

Page 108: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Soundness TheoremFor any quantum while-program S and quantum predicatesP, Q ∈ P(Hall):

`qPD {P}S{Q} implies |=par {P}S{Q}.

Exercise 5Prove soundness theorem.

(Relative) Completeness TheoremFor any quantum while-program S and quantum predicatesP, Q ∈ P(Hall):

|=par {P}S{Q} implies `qPD {P}S{Q}.

Page 109: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Bound (Ranking) Functions

I Let P ∈ P(Hall) be a quantum predicate, real number ε > 0.

I A functiont : D(Hall)→ ω

is a (P, ε)-bound function of quantum loop

while M[q] = 1 do S od

if for all ρ ∈ D(Hall):

1. t(~S�

(M1ρM†

1))≤ t(ρ);

2. tr(Pρ) ≥ ε implies

t(~S�

(M1ρM†

1

))< t(ρ)

Page 110: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Bound (Ranking) Functions

I Let P ∈ P(Hall) be a quantum predicate, real number ε > 0.I A function

t : D(Hall)→ ω

is a (P, ε)-bound function of quantum loop

while M[q] = 1 do S od

if for all ρ ∈ D(Hall):

1. t(~S�

(M1ρM†

1))≤ t(ρ);

2. tr(Pρ) ≥ ε implies

t(~S�

(M1ρM†

1

))< t(ρ)

Page 111: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Bound (Ranking) Functions

I Let P ∈ P(Hall) be a quantum predicate, real number ε > 0.I A function

t : D(Hall)→ ω

is a (P, ε)-bound function of quantum loop

while M[q] = 1 do S od

if for all ρ ∈ D(Hall):1. t

(~S�

(M1ρM†

1))≤ t(ρ);

2. tr(Pρ) ≥ ε implies

t(~S�

(M1ρM†

1

))< t(ρ)

Page 112: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Bound (Ranking) Functions

I Let P ∈ P(Hall) be a quantum predicate, real number ε > 0.I A function

t : D(Hall)→ ω

is a (P, ε)-bound function of quantum loop

while M[q] = 1 do S od

if for all ρ ∈ D(Hall):1. t

(~S�

(M1ρM†

1))≤ t(ρ);

2. tr(Pρ) ≥ ε implies

t(~S�

(M1ρM†

1

))< t(ρ)

Page 113: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Proof System for Total Correctness

(R− LT)

• {Q}S{M†0PM0 + M†

1QM1}• for any ε > 0, tε is a (M†

1QM1, ε)− bound functionof loop while M[q] = 1 do S od{M†

0PM0 + M†1QM1}while M[q] = 1 do S od{P}

Page 114: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Soundness TheoremFor any quantum program S and quantum predicates P, Q ∈ P(Hall):

`qTD {P}S{Q} implies |=tot {P}S{Q}.

(Relative) Completeness TheoremFor any quantum program S and quantum predicates P, Q ∈ P(Hall):

|=tot {P}S{Q} implies `qTD {P}S{Q}.

Page 115: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Soundness TheoremFor any quantum program S and quantum predicates P, Q ∈ P(Hall):

`qTD {P}S{Q} implies |=tot {P}S{Q}.

(Relative) Completeness TheoremFor any quantum program S and quantum predicates P, Q ∈ P(Hall):

|=tot {P}S{Q} implies `qTD {P}S{Q}.

Page 116: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Outline

Introduction

Syntax of Quantum Programs

Operational Semantics

Denotational Semantics

(Floyd-)Hoare Logic for Quantum Programs

Research Problems

Page 117: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Research problems

1. Compute the expected running time of the quantum walk.

2. Develop a logic for recursive quantum programs.3. Parallel or distributed quantum programs?4. Improve the invariant generation and termination analysis

algorithms for quantum programs.

Further reading

[1] M. S. Ying, S. G. Ying and X. D. Wu, Invariants of quantumprograms: characterisations and generation, POPL 2017.

[2] Y. J. Li and M. S. Ying, Algorithmic analysis of terminationproblem for quantum programs, POPL 2018.

Page 118: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Research problems

1. Compute the expected running time of the quantum walk.2. Develop a logic for recursive quantum programs.

3. Parallel or distributed quantum programs?4. Improve the invariant generation and termination analysis

algorithms for quantum programs.

Further reading

[1] M. S. Ying, S. G. Ying and X. D. Wu, Invariants of quantumprograms: characterisations and generation, POPL 2017.

[2] Y. J. Li and M. S. Ying, Algorithmic analysis of terminationproblem for quantum programs, POPL 2018.

Page 119: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Research problems

1. Compute the expected running time of the quantum walk.2. Develop a logic for recursive quantum programs.3. Parallel or distributed quantum programs?

4. Improve the invariant generation and termination analysisalgorithms for quantum programs.

Further reading

[1] M. S. Ying, S. G. Ying and X. D. Wu, Invariants of quantumprograms: characterisations and generation, POPL 2017.

[2] Y. J. Li and M. S. Ying, Algorithmic analysis of terminationproblem for quantum programs, POPL 2018.

Page 120: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Research problems

1. Compute the expected running time of the quantum walk.2. Develop a logic for recursive quantum programs.3. Parallel or distributed quantum programs?4. Improve the invariant generation and termination analysis

algorithms for quantum programs.

Further reading

[1] M. S. Ying, S. G. Ying and X. D. Wu, Invariants of quantumprograms: characterisations and generation, POPL 2017.

[2] Y. J. Li and M. S. Ying, Algorithmic analysis of terminationproblem for quantum programs, POPL 2018.

Page 121: Foundations of Quantum Programming - Tsinghua Universityconference.iiis.tsinghua.edu.cn/QCSS2018/wp-content/uploads/2018/... · Foundations of Quantum Programming Mingsheng Ying University

Thank You!