A Brief Introduction to Probabilistic and Quantum Programming Part - - PowerPoint PPT Presentation

a brief introduction to probabilistic and quantum
SMART_READER_LITE
LIVE PREVIEW

A Brief Introduction to Probabilistic and Quantum Programming Part - - PowerPoint PPT Presentation

A Brief Introduction to Probabilistic and Quantum Programming Part II Ugo Dal Lago Universidade do Minho, Friday May 5, 2017 Section 1 Probabilistic Programming Languages Flipping a Coin Making any programming language probabilistic is


slide-1
SLIDE 1

A Brief Introduction to Probabilistic and Quantum Programming

Part II Ugo Dal Lago Universidade do Minho, Friday May 5, 2017

slide-2
SLIDE 2

Section 1 Probabilistic Programming Languages

slide-3
SLIDE 3

Flipping a Coin

◮ Making any programming language probabilistic is

relatively easy, at least from a purely linguistic point of view.

◮ The naïve solution is to endow your favourite language with

a primitive that, when executed, “flips a fair coin” returning 0 or 1 with equal probability.

◮ In imperative programming langauges, this can take the

form of a keyword rand, to be used in expressions;

◮ In functional programming languages, one could also use a

form of binary, probabilistic sum, call it ⊕, as follows: letrec f x = x (+) (f (x+1))

◮ How do we get the necessary randomness, when executing

programs?

◮ By a source of true randomness, like physical randomness. ◮ By pseudorandomness (we will come to that later).

slide-4
SLIDE 4

Sampling

◮ If incepted into a universal programming language, binary

uniform choice is enough to encode sampling from any computable distribution.

◮ As an example, if f is defined as follows

letrec f x = x (+) (f (x+1)) then f(0) produces the exponential distribution {0

1 2 , 1 1 4 , 2 1 8 , . . .}.

◮ A real number x ∈ R is computable if there is an

algorithm Ax outputting, on input n ∈ N, a rational number qn ∈ Q such that |x − qn| <

1 2n . ◮ A computable distribution is one such that there is an

algorithm B that, on input n, outputs the code of Apn, where pn is the probability the distribution assigns to n.

Theorem

PTMs are universal for computable distributions.

slide-5
SLIDE 5

True Randomness vs. Pseudorandomness

◮ Having access to a source of true randomness is definitely

not trivial.

◮ One could make use, as an example, of:

◮ Keyboard and mouse actions; ◮ External sources of randomness, like sound or movements; ◮ TRNGs (True Random Number Generators).

◮ A pseudorandom generator is a deterministic algorithm

G from strings in Σ∗ to Σ∗ such that:

◮ |G(s)| > |s|; ◮ G(s) is somehow indistinguishable from a truly random

string t of the same length.

◮ The point of pseudorandomness is amplification: a short

truly random string is turned into a longer string which is not random, but looks so.

slide-6
SLIDE 6

Programming vs. Modeling

◮ Probabilistic models, contrarily to probabilistic languages,

are pervasive and very-well studied from decades.

◮ Markov Chains ◮ Markov Processes ◮ Stochastic Processes ◮ . . .

◮ A probabilistic program, however, can indeed be seen as a

way to concisely specify a model, for the purpose of doing, e.g., machine learning or inference.

◮ A quite large research community is currently involved in

this effort (for more details, see http://probabilistic-programming.org).

◮ Roughly, you cannot only “flip a coin”, but you can also

incorporate observations about your dataset in your program.

slide-7
SLIDE 7

Programming vs. Modeling

◮ Probabilistic models, contrarily to probabilistic languages,

are pervasive and very-well studied from decades.

◮ Markov Chains ◮ Markov Processes ◮ Stochastic Processes ◮ . . .

◮ A probabilistic program, however, can indeed be seen as a

way to concisely specify a model, for the purpose of doing, e.g., machine learning or inference.

◮ A quite large research community is currently involved in

this effort (for more details, see http://probabilistic-programming.org).

◮ Roughly, you cannot only “flip a coin”, but you can also

incorporate observations about your dataset in your program.

slide-8
SLIDE 8

A Nice Example: FUN

slide-9
SLIDE 9

A Nice Example: FUN

slide-10
SLIDE 10

Section 2 Quantum Programming Languages

slide-11
SLIDE 11

Quantum Data and Classical Control

Classical Control Quantum Store

Create a New Qubit Observe the Value of a Qubit

slide-12
SLIDE 12

Quantum Data and Classical Control

Classical Control Quantum Store

Create a New Qubit Observe the Value of a Qubit

slide-13
SLIDE 13

Quantum Data and Classical Control

Classical Control Quantum Store

Observe the Value of a Qubit Create a New Qubit

slide-14
SLIDE 14

Quantum Data and Classical Control

Classical Control Quantum Store

Apply a Transform Unitary Create a New Qubit Observe the Value of a Qubit

slide-15
SLIDE 15

Imperative Quantum Programming Languages

◮ QCL, which has been introduced by Ömer ◮ Example:

qufunct set(int n,qureg q) { int i; for i=0 to #q-1 { if bit(n,i) {Not(q[i]);} } }

◮ Classical and quantum variables. ◮ The syntax is very reminiscent of the one of C.

slide-16
SLIDE 16

Quantum Imperative Programming Languages

◮ qGCL, which has been introduced by Sanders and Zuliani.

◮ It is based on Dijkstra’s predicate transformers and

guarded-command language, called GCL.

◮ Features quantum, probabilistic, and nondeterministic

evolution.

◮ It can be seen as a generalization of pGCL, itself a

probabilistic variation on GCL.

◮ Tafliovich and Hehner adapted predicative programming to

quantum computation.

◮ Predicative programming is not a proper programming

language, but rather a methodology for specification and verification.

slide-17
SLIDE 17

Quantum Functional Programming Languages

◮ QPL, introduced by Selinger.

◮ A very simple, first-order, functional programming

language.

◮ The first one with a proper denotational semantics, given in

terms of superoperators, but also handling divergence by way of domain theory.

◮ A superoperator is a mathematical object by which we can

describe the evolution of a quantum system in presence of measurements.

◮ Many papers investigated the possibility of embedding

quantum programming into Haskell, arguably the most successful real-world functional programming language.

◮ In a way or another, they are all based on the concept of a

monad.

slide-18
SLIDE 18

Quantum Functional Programming Languages

◮ QPL, introduced by Selinger.

◮ A very simple, first-order, functional programming

language.

◮ The first one with a proper denotational semantics, given in

terms of superoperators, but also handling divergence by way of domain theory.

◮ A superoperator is a mathematical object by which we can

describe the evolution of a quantum system in presence of measurements.

◮ Many papers investigated the possibility of embedding

quantum programming into Haskell, arguably the most successful real-world functional programming language.

◮ In a way or another, they are all based on the concept of a

monad.

slide-19
SLIDE 19

QPL: an Example

slide-20
SLIDE 20

Quantum Functional Programming Languages

◮ In a first-order fragment of Haskell, one can also model a

form of quantum control, i.e., programs whose internal state is in superposition.

◮ This is Altenkirch and Grattage’s QML.

◮ Operations are programmed at a very low level: unitary

transforms become programs themselves, e.g.

◮ Whenever you program by way of the if construct, you

should be careful and check that the two branches are

  • rthogonal in a certain sense.
slide-21
SLIDE 21

Quantum Functional Programming Languages

◮ Most work on functional programming languages has

focused on λ-calculi, which are minimalist, paradigmatic languages only including the essential features.

◮ Programs are seen as terms from a simple grammar

M, N ::= x | MN | λx.M | . . .

◮ Computation is captured by way of rewriting ◮ Quantum features can be added in many different ways.

◮ By adding quantum variables, which are meant to model

the interaction with the quantum store.

◮ By allowing terms to be in superposition, somehow

diverging from the quantum-data-and-classical-control paradigm: M ::= . . . |

  • i∈I

αiMi

◮ The rest of this course will be almost entirely devoted to

(probabilistic and) quantum λ-calculi.

slide-22
SLIDE 22

Quantum Process Algebras

◮ Process algebras are calculi meant to model concurrency

and interaction rather than mere computation.

◮ Terms of process algebras are usually of the following form;

P, Q ::= 0 | a.P | a.P | P||Q | . . .

◮ Again, computation is modeled by a form of rewriting, e.g.,

a.P||a.Q → P||Q

◮ How could we incept quantum computation? Usually:

◮ Each process has its own set of classical and quantum

(local) variables.

◮ Processes do not only synchronize, but can also send

classical and quantum data along channels.

◮ Unitary transformations and measurements are done locally.

slide-23
SLIDE 23

Other Programming Paradigms

◮ Concurrent Constraint Programming ◮ Measurement-Based Quantum Computation ◮ Hardware Description Languages ◮ . . .

slide-24
SLIDE 24

Section 3 The λ-Calculus as a Functional Language

slide-25
SLIDE 25

Minimal Syntax and Dynamics

◮ Terms:

M ::= x | MN | λx.M.

◮ Substitution:

x{x/M} = M y{x/M} = y NL{x/M} = (N{x/M})(L{x/M}) λy.N{x/M} = λy.(N{x/M})

◮ CBN Operational Semantics:

(λx.M)N → M{x/N} M → N ML → NL

◮ Values:

V ::= λx.M

◮ CBV Operational Semantics:

(λx.M)V → M{x/V } M → N ML → NL M → N V M → V N

slide-26
SLIDE 26

Minimal Syntax and Dynamics

◮ Terms:

M ::= x | MN | λx.M.

◮ Substitution:

x{x/M} = M y{x/M} = y NL{x/M} = (N{x/M})(L{x/M}) λy.N{x/M} = λy.(N{x/M})

◮ CBN Operational Semantics:

(λx.M)N → M{x/N} M → N ML → NL

◮ Values:

V ::= λx.M

◮ CBV Operational Semantics:

(λx.M)V → M{x/V } M → N ML → NL M → N V M → V N

slide-27
SLIDE 27

Minimal Syntax and Dynamics

◮ Terms:

M ::= x | MN | λx.M.

◮ Substitution:

x{x/M} = M y{x/M} = y NL{x/M} = (N{x/M})(L{x/M}) λy.N{x/M} = λy.(N{x/M})

◮ CBN Operational Semantics:

(λx.M)N → M{x/N} M → N ML → NL

◮ Values:

V ::= λx.M

◮ CBV Operational Semantics:

(λx.M)V → M{x/V } M → N ML → NL M → N V M → V N

slide-28
SLIDE 28

Minimal Syntax and Dynamics

◮ Terms:

M ::= x | MN | λx.M.

◮ Substitution:

x{x/M} = M y{x/M} = y NL{x/M} = (N{x/M})(L{x/M}) λy.N{x/M} = λy.(N{x/M})

◮ CBN Operational Semantics:

(λx.M)N → M{x/N} M → N ML → NL

◮ Values:

V ::= λx.M

◮ CBV Operational Semantics:

(λx.M)V → M{x/V } M → N ML → NL M → N V M → V N

slide-29
SLIDE 29

Minimal Syntax and Dynamics

◮ Terms:

M ::= x | MN | λx.M.

◮ Substitution:

x{x/M} = M y{x/M} = y NL{x/M} = (N{x/M})(L{x/M}) λy.N{x/M} = λy.(N{x/M})

◮ CBN Operational Semantics:

(λx.M)N → M{x/N} M → N ML → NL

◮ Values:

V ::= λx.M

◮ CBV Operational Semantics:

(λx.M)V → M{x/V } M → N ML → NL M → N V M → V N

slide-30
SLIDE 30

Observations

◮ Not all redexes are reduced. ◮ For every M there is at most one N such that M → N. ◮ It is easy to find a term M such that

M = N0 → N1 → N2 → . . .

◮ There is a problem with substitutions:

(λx.λy.x)(yz) → λy.yz. (λx.λy.x)(yz) → λw.yz.

◮ The standard solution is to consider terms modulo so-called

α-equivalence: renaming bound variables turns a term into one which is indistinguishable. λx.λy.xxy ≡ λz.λy.zzy.

◮ α-equivalence is not necessary if we assume to work with

closed terms.

slide-31
SLIDE 31

Observations

◮ Not all redexes are reduced. ◮ For every M there is at most one N such that M → N. ◮ It is easy to find a term M such that

M = N0 → N1 → N2 → . . .

◮ There is a problem with substitutions:

(λx.λy.x)(yz) → λy.yz. (λx.λy.x)(yz) → λw.yz.

◮ The standard solution is to consider terms modulo so-called

α-equivalence: renaming bound variables turns a term into one which is indistinguishable. λx.λy.xxy ≡ λz.λy.zzy.

◮ α-equivalence is not necessary if we assume to work with

closed terms.

slide-32
SLIDE 32

Observations

◮ Not all redexes are reduced. ◮ For every M there is at most one N such that M → N. ◮ It is easy to find a term M such that

M = N0 → N1 → N2 → . . .

◮ There is a problem with substitutions:

(λx.λy.x)(yz) → λy.yz. (λx.λy.x)(yz) → λw.yz.

◮ The standard solution is to consider terms modulo so-called

α-equivalence: renaming bound variables turns a term into one which is indistinguishable. λx.λy.xxy ≡ λz.λy.zzy.

◮ α-equivalence is not necessary if we assume to work with

closed terms.

slide-33
SLIDE 33

Computing Simple Function on N, in CBV

◮ Natural Numbers

0 = λx.λy.x; n + 1 = λx.λy.yn.

◮ Finite Set A = {a1, . . . , an}

ai = λx1 · · · λxn.xi.

◮ Pairs

M, N = λx.xMN

◮ Fixed-Point Combinator

Θ = λx.λy.y(λz.(xx)yz); H = ΘΘ.

slide-34
SLIDE 34

Computing Simple Functions on N, in CBV

◮ Successor

SUCC = λz.λx.λy.yz Indeed: SUCCn → λx.λy.yn

◮ Projections

PROJk

i = λx.x(λy1 · λyk.yi)

Indeed: PROJk

i n1, . . . , nk → n1, . . . , nk(λy1 · · · λyk.yi)

→ (λy1 · · · λyk.yi)n1 · · · nk →∗ ni.

slide-35
SLIDE 35

Computing Simple Functions on N, in CBV

◮ Successor

SUCC = λz.λx.λy.yz Indeed: SUCCn → λx.λy.yn

◮ Projections

PROJk

i = λx.x(λy1 · λyk.yi)

Indeed: PROJk

i n1, . . . , nk → n1, . . . , nk(λy1 · · · λyk.yi)

→ (λy1 · · · λyk.yi)n1 · · · nk →∗ ni.

slide-36
SLIDE 36

Computing Simple Functions on N, in CBV

◮ Successor

SUCC = λz.λx.λy.yz Indeed: SUCCn → λx.λy.yn

◮ Projections

PROJk

i = λx.x(λy1 · λyk.yi)

Indeed: PROJk

i n1, . . . , nk → n1, . . . , nk(λy1 · · · λyk.yi)

→ (λy1 · · · λyk.yi)n1 · · · nk →∗ ni.

slide-37
SLIDE 37

Computing Simple Functions on N, in CBV

◮ Successor

SUCC = λz.λx.λy.yz Indeed: SUCCn → λx.λy.yn

◮ Projections

PROJk

i = λx.x(λy1 · λyk.yi)

Indeed: PROJk

i n1, . . . , nk → n1, . . . , nk(λy1 · · · λyk.yi)

→ (λy1 · · · λyk.yi)n1 · · · nk →∗ ni.

slide-38
SLIDE 38

A Simple Form of Recursion

◮ Suppose you have a term Mf which computes the function

f : N → N, and you want to iterate over it, i.e. you want to compute g : N × N → N such that g(0, n) = n; g(m + 1, n) = f(g(m, n)).

◮ We need a form of recursion in the language. Observe that:

HV = (ΘΘ)V → (λy.y(λz.Hyz))V → V (λz.HV z)

◮ The function g can be computed by way of

Mg = H(λx.λy.y(λz.λw.zw(λq.Mf(xq, w)))

slide-39
SLIDE 39

A Simple Form of Recursion

◮ Suppose you have a term Mf which computes the function

f : N → N, and you want to iterate over it, i.e. you want to compute g : N × N → N such that g(0, n) = n; g(m + 1, n) = f(g(m, n)).

◮ We need a form of recursion in the language. Observe that:

HV = (ΘΘ)V → (λy.y(λz.Hyz))V → V (λz.HV z)

◮ The function g can be computed by way of

Mg = H(λx.λy.y(λz.λw.zw(λq.Mf(xq, w)))

slide-40
SLIDE 40

A Simple Form of Recursion

◮ Suppose you have a term Mf which computes the function

f : N → N, and you want to iterate over it, i.e. you want to compute g : N × N → N such that g(0, n) = n; g(m + 1, n) = f(g(m, n)).

◮ We need a form of recursion in the language. Observe that:

HV = (ΘΘ)V → (λy.y(λz.Hyz))V → V (λz.HV z)

◮ The function g can be computed by way of

Mg = H(λx.λy.y(λz.λw.zw(λq.Mf(xq, w)))

slide-41
SLIDE 41

Universality

◮ One could go on, and show that the following schemes can

all be encoded:

◮ Composition; ◮ Primitive Recursion; ◮ Minimization.

◮ This implies that all partial recursive functions can be

computed in the λ-calculus.

Theorem

The λ-calculus is Turing-complete, both when CBV and CBN are considered.

slide-42
SLIDE 42

Why is This a Faithful Model of Functional Computation?

◮ Data, conditionals, basic functions, and recursion can all be

encoded into the λ-calculus. We can then give programs “informally”, in our favourite functional language.

◮ Take, as an example, the usual recursive program

computing the factorial of a natural number

let rec fact x = if (x==0) then 1 else x*(fact x-1)

◮ This can indeed be turned into a λ-term (where M∗ and

M−1 are terms for multiplication and the predecessor, respectively):

let rec fact x = if (x==0) then 1 else x*(fact x-1) H(λfact.λx.if (x==0) then 1 else x*(fact x-1)) H(λfact.λx.x 1 (x*(fact x-1))) H(λfact.λx.x 1 (M∗ x (fact x-1))) H(λfact.λx.x 1 (M∗ x (fact (M−1x))))

slide-43
SLIDE 43

Why is This a Faithful Model of Functional Computation?

◮ Data, conditionals, basic functions, and recursion can all be

encoded into the λ-calculus. We can then give programs “informally”, in our favourite functional language.

◮ Take, as an example, the usual recursive program

computing the factorial of a natural number

let rec fact x = if (x==0) then 1 else x*(fact x-1)

◮ This can indeed be turned into a λ-term (where M∗ and

M−1 are terms for multiplication and the predecessor, respectively):

let rec fact x = if (x==0) then 1 else x*(fact x-1) H(λfact.λx.if (x==0) then 1 else x*(fact x-1)) H(λfact.λx.x 1 (x*(fact x-1))) H(λfact.λx.x 1 (M∗ x (fact x-1))) H(λfact.λx.x 1 (M∗ x (fact (M−1x))))

slide-44
SLIDE 44

Why is This a Faithful Model of Functional Computation?

◮ Data, conditionals, basic functions, and recursion can all be

encoded into the λ-calculus. We can then give programs “informally”, in our favourite functional language.

◮ Take, as an example, the usual recursive program

computing the factorial of a natural number

let rec fact x = if (x==0) then 1 else x*(fact x-1)

◮ This can indeed be turned into a λ-term (where M∗ and

M−1 are terms for multiplication and the predecessor, respectively):

let rec fact x = if (x==0) then 1 else x*(fact x-1) H(λfact.λx.if (x==0) then 1 else x*(fact x-1)) H(λfact.λx.x 1 (x*(fact x-1))) H(λfact.λx.x 1 (M∗ x (fact x-1))) H(λfact.λx.x 1 (M∗ x (fact (M−1x))))

slide-45
SLIDE 45

Why is This a Faithful Model of Functional Computation?

◮ Data, conditionals, basic functions, and recursion can all be

encoded into the λ-calculus. We can then give programs “informally”, in our favourite functional language.

◮ Take, as an example, the usual recursive program

computing the factorial of a natural number

let rec fact x = if (x==0) then 1 else x*(fact x-1)

◮ This can indeed be turned into a λ-term (where M∗ and

M−1 are terms for multiplication and the predecessor, respectively):

let rec fact x = if (x==0) then 1 else x*(fact x-1) H(λfact.λx.if (x==0) then 1 else x*(fact x-1)) H(λfact.λx.x 1 (x*(fact x-1))) H(λfact.λx.x 1 (M∗ x (fact x-1))) H(λfact.λx.x 1 (M∗ x (fact (M−1x))))

slide-46
SLIDE 46

Why is This a Faithful Model of Functional Computation?

◮ Data, conditionals, basic functions, and recursion can all be

encoded into the λ-calculus. We can then give programs “informally”, in our favourite functional language.

◮ Take, as an example, the usual recursive program

computing the factorial of a natural number

let rec fact x = if (x==0) then 1 else x*(fact x-1)

◮ This can indeed be turned into a λ-term (where M∗ and

M−1 are terms for multiplication and the predecessor, respectively):

let rec fact x = if (x==0) then 1 else x*(fact x-1) H(λfact.λx.if (x==0) then 1 else x*(fact x-1)) H(λfact.λx.x 1 (x*(fact x-1))) H(λfact.λx.x 1 (M∗ x (fact x-1))) H(λfact.λx.x 1 (M∗ x (fact (M−1x))))

slide-47
SLIDE 47

More About Semantics

◮ The semantics we have adopted so far is said to be

small-step, since it derives assertions in the form M → N, each corresponding to one atomic computation step.

◮ There is an equivalent way of formulating the same

concept, big-step semantics, in which we “jump directly to the result”:

◮ CBN

V ⇓ V M ⇓ λx.N N{x/L} ⇓ V ML ⇓ V

◮ CBV

V ⇓ V M ⇓ λx.N L ⇓ V N{x/V } ⇓ W ML ⇓ W

Theorem

In both CBN and CBV, M →∗ V if and only if M ⇓ V .

◮ If M ⇓ V for some V , then we write M ⇓, otherwise M ⇑

slide-48
SLIDE 48

More About Semantics

◮ The semantics we have adopted so far is said to be

small-step, since it derives assertions in the form M → N, each corresponding to one atomic computation step.

◮ There is an equivalent way of formulating the same

concept, big-step semantics, in which we “jump directly to the result”:

◮ CBN

V ⇓ V M ⇓ λx.N N{x/L} ⇓ V ML ⇓ V

◮ CBV

V ⇓ V M ⇓ λx.N L ⇓ V N{x/V } ⇓ W ML ⇓ W

Theorem

In both CBN and CBV, M →∗ V if and only if M ⇓ V .

◮ If M ⇓ V for some V , then we write M ⇓, otherwise M ⇑

slide-49
SLIDE 49

More About Semantics

◮ The semantics we have adopted so far is said to be

small-step, since it derives assertions in the form M → N, each corresponding to one atomic computation step.

◮ There is an equivalent way of formulating the same

concept, big-step semantics, in which we “jump directly to the result”:

◮ CBN

V ⇓ V M ⇓ λx.N N{x/L} ⇓ V ML ⇓ V

◮ CBV

V ⇓ V M ⇓ λx.N L ⇓ V N{x/V } ⇓ W ML ⇓ W

Theorem

In both CBN and CBV, M →∗ V if and only if M ⇓ V .

◮ If M ⇓ V for some V , then we write M ⇓, otherwise M ⇑

slide-50
SLIDE 50

Section 4 Probabilistic λ-Calculi

slide-51
SLIDE 51

Probabilistic λ-Calculus: Syntax and Operational Semantics

◮ Terms: M, N ::= x | λx.M | MN | M ⊕ N; ◮ Values: V ::= λx.M; ◮ How should we define the semantics of a probabilistic term

M?

◮ Informally, M ⊕ N rewrites to M or to N with probability

1 2: this is just like flippling a coin and choosing one of the

two terms according to the result.

◮ A value distribution is a function D from the set V of

values to R such

  • V ∈V

D(V ) ≤ 1.

◮ The fact the sum can be strictly smaller than 1 is a way

to reflect (the probability of) divergence.

◮ The empty value distribution is denoted as ∅. ◮ Useful notation for finite distributions: {V p1

1 , . . . , V pn n }.

◮ Value distributions can be ordered, pointwise. ◮ S(D) is the support of D, i.e. the set of values to which D

assigns nonnull probability.

slide-52
SLIDE 52

Probabilistic λ-Calculus: Syntax and Operational Semantics

◮ Terms: M, N ::= x | λx.M | MN | M ⊕ N; ◮ Values: V ::= λx.M; ◮ How should we define the semantics of a probabilistic term

M?

◮ Informally, M ⊕ N rewrites to M or to N with probability

1 2: this is just like flippling a coin and choosing one of the

two terms according to the result.

◮ A value distribution is a function D from the set V of

values to R such

  • V ∈V

D(V ) ≤ 1.

◮ The fact the sum can be strictly smaller than 1 is a way

to reflect (the probability of) divergence.

◮ The empty value distribution is denoted as ∅. ◮ Useful notation for finite distributions: {V p1

1 , . . . , V pn n }.

◮ Value distributions can be ordered, pointwise. ◮ S(D) is the support of D, i.e. the set of values to which D

assigns nonnull probability.

slide-53
SLIDE 53

Probabilistic λ-Calculus: Syntax and Operational Semantics

◮ Terms: M, N ::= x | λx.M | MN | M ⊕ N; ◮ Values: V ::= λx.M; ◮ How should we define the semantics of a probabilistic term

M?

◮ Informally, M ⊕ N rewrites to M or to N with probability

1 2: this is just like flippling a coin and choosing one of the

two terms according to the result.

◮ A value distribution is a function D from the set V of

values to R such

  • V ∈V

D(V ) ≤ 1.

◮ The fact the sum can be strictly smaller than 1 is a way

to reflect (the probability of) divergence.

◮ The empty value distribution is denoted as ∅. ◮ Useful notation for finite distributions: {V p1

1 , . . . , V pn n }.

◮ Value distributions can be ordered, pointwise. ◮ S(D) is the support of D, i.e. the set of values to which D

assigns nonnull probability.

slide-54
SLIDE 54

Probabilistic λ-Calculus: Syntax and Operational Semantics

◮ Approximation (Big-Step) Semantics, CBN:

M ⇓ ∅ V ⇓ {V 1} M ⇓ D N ⇓ E M ⊕ N ⇓ 1

2D + 1 2E

M ⇓ D {P{x/N} ⇓ Eλx.P }λx.P ∈S(D) MN ⇓

  • V ∈S(F)

D(V )Eλx.P

◮ Example: consider M = I ⊕ ((II) ⊕ Ω), where I = λx.x

and Ω = (λx.xx)(λx.xx). M ⇓ ∅ M ⇓ {I

1 2 }

M ⇓ {I

3 4 }

◮ Semantics: [

[M] ] = supM⇓D D;

◮ Variations: Small-Step Semantics, CBV.

slide-55
SLIDE 55

Probabilistic λ-Calculus: Syntax and Operational Semantics

◮ Approximation (Big-Step) Semantics, CBN:

M ⇓ ∅ V ⇓ {V 1} M ⇓ D N ⇓ E M ⊕ N ⇓ 1

2D + 1 2E

M ⇓ D {P{x/N} ⇓ Eλx.P }λx.P ∈S(D) MN ⇓

  • V ∈S(F)

D(V )Eλx.P

◮ Example: consider M = I ⊕ ((II) ⊕ Ω), where I = λx.x

and Ω = (λx.xx)(λx.xx). M ⇓ ∅ M ⇓ {I

1 2 }

M ⇓ {I

3 4 }

◮ Semantics: [

[M] ] = supM⇓D D;

◮ Variations: Small-Step Semantics, CBV.

slide-56
SLIDE 56

Probabilistic λ-Calculus: Syntax and Operational Semantics

◮ Approximation (Big-Step) Semantics, CBN:

M ⇓ ∅ V ⇓ {V 1} M ⇓ D N ⇓ E M ⊕ N ⇓ 1

2D + 1 2E

M ⇓ D {P{x/N} ⇓ Eλx.P }λx.P ∈S(D) MN ⇓

  • V ∈S(F)

D(V )Eλx.P

◮ Example: consider M = I ⊕ ((II) ⊕ Ω), where I = λx.x

and Ω = (λx.xx)(λx.xx). M ⇓ ∅ M ⇓ {I

1 2 }

M ⇓ {I

3 4 }

◮ Semantics: [

[M] ] = supM⇓D D;

◮ Variations: Small-Step Semantics, CBV.

slide-57
SLIDE 57

Probabilistic λ-Calculus: Syntax and Operational Semantics

◮ Approximation (Big-Step) Semantics, CBN:

M ⇓ ∅ V ⇓ {V 1} M ⇓ D N ⇓ E M ⊕ N ⇓ 1

2D + 1 2E

M ⇓ D {P{x/N} ⇓ Eλx.P }λx.P ∈S(D) MN ⇓

  • V ∈S(F)

D(V )Eλx.P

◮ Example: consider M = I ⊕ ((II) ⊕ Ω), where I = λx.x

and Ω = (λx.xx)(λx.xx). M ⇓ ∅ M ⇓ {I

1 2 }

M ⇓ {I

3 4 }

◮ Semantics: [

[M] ] = supM⇓D D;

◮ Variations: Small-Step Semantics, CBV.

slide-58
SLIDE 58

Probabilistic λ-Calculus: Syntax and Operational Semantics

◮ Approximation (Big-Step) Semantics, CBN:

M ⇓ ∅ V ⇓ {V 1} M ⇓ D N ⇓ E M ⊕ N ⇓ 1

2D + 1 2E

M ⇓ D {P{x/N} ⇓ Eλx.P }λx.P ∈S(D) MN ⇓

  • V ∈S(F)

D(V )Eλx.P

◮ Example: consider M = I ⊕ ((II) ⊕ Ω), where I = λx.x

and Ω = (λx.xx)(λx.xx). M ⇓ ∅ M ⇓ {I

1 2 }

M ⇓ {I

3 4 }

◮ Semantics: [

[M] ] = supM⇓D D;

◮ Variations: Small-Step Semantics, CBV.

slide-59
SLIDE 59

Probabilistic λ-Calculus: Syntax and Operational Semantics

◮ Approximation (Big-Step) Semantics, CBN:

M ⇓ ∅ V ⇓ {V 1} M ⇓ D N ⇓ E M ⊕ N ⇓ 1

2D + 1 2E

M ⇓ D {P{x/N} ⇓ Eλx.P }λx.P ∈S(D) MN ⇓

  • V ∈S(F)

D(V )Eλx.P

◮ Example: consider M = I ⊕ ((II) ⊕ Ω), where I = λx.x

and Ω = (λx.xx)(λx.xx). M ⇓ ∅ M ⇓ {I

1 2 }

M ⇓ {I

3 4 }

◮ Semantics: [

[M] ] = supM⇓D D;

◮ Variations: Small-Step Semantics, CBV.

slide-60
SLIDE 60

Probabilistic λ-Calculus: Syntax and Operational Semantics

◮ As an example, consider the following recursive program,

and call it M:

let rec fancy x = x (+) (fancy x+1)

◮ One can easily check that:

M0 ⇓ ∅ M0 ⇓ {0

1 2 }

M0 ⇓ {0

1 2 , 1 1 4 }

· · ·

◮ As a consequence:

[ [M0] ] = sup

M0⇓D

D = {0

1 2 , 1 1 4 , 2 1 8 , . . .}

Theorem

The probabilistic λ-calculus and PTMs are equiexpressive.

slide-61
SLIDE 61

Probabilistic λ-Calculus: Syntax and Operational Semantics

◮ As an example, consider the following recursive program,

and call it M:

let rec fancy x = x (+) (fancy x+1)

◮ One can easily check that:

M0 ⇓ ∅ M0 ⇓ {0

1 2 }

M0 ⇓ {0

1 2 , 1 1 4 }

· · ·

◮ As a consequence:

[ [M0] ] = sup

M0⇓D

D = {0

1 2 , 1 1 4 , 2 1 8 , . . .}

Theorem

The probabilistic λ-calculus and PTMs are equiexpressive.

slide-62
SLIDE 62

Probabilistic λ-Calculus: Syntax and Operational Semantics

◮ As an example, consider the following recursive program,

and call it M:

let rec fancy x = x (+) (fancy x+1)

◮ One can easily check that:

M0 ⇓ ∅ M0 ⇓ {0

1 2 }

M0 ⇓ {0

1 2 , 1 1 4 }

· · ·

◮ As a consequence:

[ [M0] ] = sup

M0⇓D

D = {0

1 2 , 1 1 4 , 2 1 8 , . . .}

Theorem

The probabilistic λ-calculus and PTMs are equiexpressive.

slide-63
SLIDE 63

Probabilistic λ-Calculus: Syntax and Operational Semantics

◮ As an example, consider the following recursive program,

and call it M:

let rec fancy x = x (+) (fancy x+1)

◮ One can easily check that:

M0 ⇓ ∅ M0 ⇓ {0

1 2 }

M0 ⇓ {0

1 2 , 1 1 4 }

· · ·

◮ As a consequence:

[ [M0] ] = sup

M0⇓D

D = {0

1 2 , 1 1 4 , 2 1 8 , . . .}

Theorem

The probabilistic λ-calculus and PTMs are equiexpressive.

slide-64
SLIDE 64

Probabilistic λ-Calculus: Syntax and Operational Semantics

◮ As an example, consider the following recursive program,

and call it M:

let rec fancy x = x (+) (fancy x+1)

◮ One can easily check that:

M0 ⇓ ∅ M0 ⇓ {0

1 2 }

M0 ⇓ {0

1 2 , 1 1 4 }

· · ·

◮ As a consequence:

[ [M0] ] = sup

M0⇓D

D = {0

1 2 , 1 1 4 , 2 1 8 , . . .}

Theorem

The probabilistic λ-calculus and PTMs are equiexpressive.

slide-65
SLIDE 65

Probabilistic λ-Calculus: Syntax and Operational Semantics

◮ As an example, consider the following recursive program,

and call it M:

let rec fancy x = x (+) (fancy x+1)

◮ One can easily check that:

M0 ⇓ ∅ M0 ⇓ {0

1 2 }

M0 ⇓ {0

1 2 , 1 1 4 }

· · ·

◮ As a consequence:

[ [M0] ] = sup

M0⇓D

D = {0

1 2 , 1 1 4 , 2 1 8 , . . .}

Theorem

The probabilistic λ-calculus and PTMs are equiexpressive.

slide-66
SLIDE 66

Probabilistic λ-Calculus: Syntax and Operational Semantics

◮ As an example, consider the following recursive program,

and call it M:

let rec fancy x = x (+) (fancy x+1)

◮ One can easily check that:

M0 ⇓ ∅ M0 ⇓ {0

1 2 }

M0 ⇓ {0

1 2 , 1 1 4 }

· · ·

◮ As a consequence:

[ [M0] ] = sup

M0⇓D

D = {0

1 2 , 1 1 4 , 2 1 8 , . . .}

Theorem

The probabilistic λ-calculus and PTMs are equiexpressive.

slide-67
SLIDE 67

Section 5 Quantum λ-Calculi

slide-68
SLIDE 68

A Naïve Attempt

◮ While looking for a quantum generalization of the

λ-calculus, one could be tempted to proceed merely by enriching its syntax of terms as follows: M, N ::= x | λx.M | MN | r | U | new | meas where:

◮ r is a quantum variable pointing to the quantum store; ◮ the operator new creates a new qubit; ◮ the operator meas measures a qubit from the quantum

store;

◮ U applies a unitary transform to one (or more) qubits from

the quantum store.

◮ This would be enough to express, e.g., some simple

quantum circuits: λx.λy.CNOTH x, y λx.meas(H(new x))

slide-69
SLIDE 69

A Naïve Attempt

[∅, (λx.λy.CNOTH x, y)new 0, new 0] →∗ [|r → 0 ⊗ |q → 0, (λx.λy.CNOTH x, y)r, q] → [|r → 0 ⊗ |q → 0, CNOTH r, q] → [ 1 √ 2|r → 0, q → 0 + 1 √ 2|r → 1, q → 0, CNOTr, q] → [ 1 √ 2|r → 0, q → 0 + 1 √ 2|r → 1, q → 1, r, q]

slide-70
SLIDE 70

A Naïve Attempt

[∅, (λx.λy.CNOTH x, y)new 0, new 0] →∗ [|r → 0 ⊗ |q → 0, (λx.λy.CNOTH x, y)r, q] → [|r → 0 ⊗ |q → 0, CNOTH r, q] → [ 1 √ 2|r → 0, q → 0 + 1 √ 2|r → 1, q → 0, CNOTr, q] → [ 1 √ 2|r → 0, q → 0 + 1 √ 2|r → 1, q → 1, r, q]

slide-71
SLIDE 71

A Naïve Attempt

[∅, (λx.λy.CNOTH x, y)new 0, new 0] →∗ [|r → 0 ⊗ |q → 0, (λx.λy.CNOTH x, y)r, q] → [|r → 0 ⊗ |q → 0, CNOTH r, q] → [ 1 √ 2|r → 0, q → 0 + 1 √ 2|r → 1, q → 0, CNOTr, q] → [ 1 √ 2|r → 0, q → 0 + 1 √ 2|r → 1, q → 1, r, q]

slide-72
SLIDE 72

A Naïve Attempt

[∅, (λx.λy.CNOTH x, y)new 0, new 0] →∗ [|r → 0 ⊗ |q → 0, (λx.λy.CNOTH x, y)r, q] → [|r → 0 ⊗ |q → 0, CNOTH r, q] → [ 1 √ 2|r → 0, q → 0 + 1 √ 2|r → 1, q → 0, CNOTr, q] → [ 1 √ 2|r → 0, q → 0 + 1 √ 2|r → 1, q → 1, r, q]

slide-73
SLIDE 73

A Naïve Attempt

[∅, (λx.λy.CNOTH x, y)new 0, new 0] →∗ [|r → 0 ⊗ |q → 0, (λx.λy.CNOTH x, y)r, q] → [|r → 0 ⊗ |q → 0, CNOTH r, q] → [ 1 √ 2|r → 0, q → 0 + 1 √ 2|r → 1, q → 0, CNOTr, q] → [ 1 √ 2|r → 0, q → 0 + 1 √ 2|r → 1, q → 1, r, q]

slide-74
SLIDE 74

A Naïve Attempt

◮ This approach has some fundamental problems,

however.

◮ Take the term (λx.CNOTx, x)new and suppose, as in the

previous example, to reduce it in CBV: [∅, (λx.CNOTx, x)(new0)] → [|r → 0, (λx.CNOTx, x)r] → [|r → 0, CNOTr, r]

◮ Qubits can be freely duplicated or erased!

◮ And this goes against the principles of quantum mechanics.

◮ We need a way to force qubits to be used exactly once

when passed to functions.

slide-75
SLIDE 75

A Naïve Attempt

◮ This approach has some fundamental problems,

however.

◮ Take the term (λx.CNOTx, x)new and suppose, as in the

previous example, to reduce it in CBV: [∅, (λx.CNOTx, x)(new0)] → [|r → 0, (λx.CNOTx, x)r] → [|r → 0, CNOTr, r]

◮ Qubits can be freely duplicated or erased!

◮ And this goes against the principles of quantum mechanics.

◮ We need a way to force qubits to be used exactly once

when passed to functions.

slide-76
SLIDE 76

A Naïve Attempt

◮ This approach has some fundamental problems,

however.

◮ Take the term (λx.CNOTx, x)new and suppose, as in the

previous example, to reduce it in CBV: [∅, (λx.CNOTx, x)(new0)] → [|r → 0, (λx.CNOTx, x)r] → [|r → 0, CNOTr, r]

◮ Qubits can be freely duplicated or erased!

◮ And this goes against the principles of quantum mechanics.

◮ We need a way to force qubits to be used exactly once

when passed to functions.

slide-77
SLIDE 77

A Naïve Attempt

◮ This approach has some fundamental problems,

however.

◮ Take the term (λx.CNOTx, x)new and suppose, as in the

previous example, to reduce it in CBV: [∅, (λx.CNOTx, x)(new0)] → [|r → 0, (λx.CNOTx, x)r] → [|r → 0, CNOTr, r]

◮ Qubits can be freely duplicated or erased!

◮ And this goes against the principles of quantum mechanics.

◮ We need a way to force qubits to be used exactly once

when passed to functions.

slide-78
SLIDE 78

Linearity and the λ-Calculus

◮ First of all, let us impose that in any abstraction λx.M, the

variable x occurs exactly once in M.

◮ Copying and erasure not possible, anymore. ◮ But the calculus loses much of its expressive power.

◮ The idea is to refine the calculus in such a way as to

reintroduce erasure and copying, but in a controlled way.

◮ We mark as !M all those subterms which can be

(potentially) copied or erased;

◮ Besides the usual linear abstraction λx.M, there is a

non-linear abstraction λ!x.M.

◮ Altogether, then, the language of terms becomes:

M, N ::= x | λx.M | λ!x.M | MN | !M r | U | new | meas where we insist that any term in the form !M does not contain any quantum variable.

slide-79
SLIDE 79

Linearity and the λ-Calculus

◮ First of all, let us impose that in any abstraction λx.M, the

variable x occurs exactly once in M.

◮ Copying and erasure not possible, anymore. ◮ But the calculus loses much of its expressive power.

◮ The idea is to refine the calculus in such a way as to

reintroduce erasure and copying, but in a controlled way.

◮ We mark as !M all those subterms which can be

(potentially) copied or erased;

◮ Besides the usual linear abstraction λx.M, there is a

non-linear abstraction λ!x.M.

◮ Altogether, then, the language of terms becomes:

M, N ::= x | λx.M | λ!x.M | MN | !M r | U | new | meas where we insist that any term in the form !M does not contain any quantum variable.

slide-80
SLIDE 80

Operational Semantics

Evaluation Contexts E ::= [·] | EM | ME | λx.E | λ!x.E Small Step Rules [Q, E[(λx.M)N]] ⇒ {[Q, E[M{x/N}]]1} [Q, E[(λ!x.M)!N]] ⇒ {[Q, E[M{x/N}]]1} [Q, E[meas r]] ⇒ {[Π0

r(Q), E[0]]Ξ0

r(Q), [Π1

r(Q), E[1]]Ξ1

r(Q)}

[Q, E[U r]] ⇒ {[Ur(Q), E[r]]1} [Q, E[new 0]] ⇒ {[Q ⊗ |r → 0, E[r]]1} [Q, E[new 1]] ⇒ {[Q ⊗ |r → 1, E[r]]1}

slide-81
SLIDE 81

Operational Semantics

Evaluation Contexts E ::= [·] | EM | ME | λx.E | λ!x.E Small Step Rules [Q, E[(λx.M)N]] ⇒ {[Q, E[M{x/N}]]1} [Q, E[(λ!x.M)!N]] ⇒ {[Q, E[M{x/N}]]1} [Q, E[meas r]] ⇒ {[Π0

r(Q), E[0]]Ξ0

r(Q), [Π1

r(Q), E[1]]Ξ1

r(Q)}

[Q, E[U r]] ⇒ {[Ur(Q), E[r]]1} [Q, E[new 0]] ⇒ {[Q ⊗ |r → 0, E[r]]1} [Q, E[new 1]] ⇒ {[Q ⊗ |r → 1, E[r]]1}

slide-82
SLIDE 82

Operational Semantics

Evaluation Contexts E ::= [·] | EM | ME | λx.E | λ!x.E Small Step Rules [Q, E[(λx.M)N]] ⇒ {[Q, E[M{x/N}]]1} [Q, E[(λ!x.M)!N]] ⇒ {[Q, E[M{x/N}]]1} [Q, E[meas r]] ⇒ {[Π0

r(Q), E[0]]Ξ0

r(Q), [Π1

r(Q), E[1]]Ξ1

r(Q)}

[Q, E[U r]] ⇒ {[Ur(Q), E[r]]1} [Q, E[new 0]] ⇒ {[Q ⊗ |r → 0, E[r]]1} [Q, E[new 1]] ⇒ {[Q ⊗ |r → 1, E[r]]1}

slide-83
SLIDE 83

Operational Semantics

Evaluation Contexts E ::= [·] | EM | ME | λx.E | λ!x.E Small Step Rules [Q, E[(λx.M)N]] ⇒ {[Q, E[M{x/N}]]1} [Q, E[(λ!x.M)!N]] ⇒ {[Q, E[M{x/N}]]1} [Q, E[meas r]] ⇒ {[Π0

r(Q), E[0]]Ξ0

r(Q), [Π1

r(Q), E[1]]Ξ1

r(Q)}

[Q, E[U r]] ⇒ {[Ur(Q), E[r]]1} [Q, E[new 0]] ⇒ {[Q ⊗ |r → 0, E[r]]1} [Q, E[new 1]] ⇒ {[Q ⊗ |r → 1, E[r]]1}

slide-84
SLIDE 84

Operational Semantics

Evaluation Contexts E ::= [·] | EM | ME | λx.E | λ!x.E Small Step Rules [Q, E[(λx.M)N]] ⇒ {[Q, E[M{x/N}]]1} [Q, E[(λ!x.M)!N]] ⇒ {[Q, E[M{x/N}]]1} [Q, E[meas r]] ⇒ {[Π0

r(Q), E[0]]Ξ0

r(Q), [Π1

r(Q), E[1]]Ξ1

r(Q)}

[Q, E[U r]] ⇒ {[Ur(Q), E[r]]1} [Q, E[new 0]] ⇒ {[Q ⊗ |r → 0, E[r]]1} [Q, E[new 1]] ⇒ {[Q ⊗ |r → 1, E[r]]1}

slide-85
SLIDE 85

Expressive Power

Theorem

Any uniform quantum circuit family {Cn}n∈N is simulated by a meas-free term M.

◮ Given s, the term M computes a code for C|s| ◮ Then, it applies C|s| to s.

Theorem

Any meas-free term M computes the same function as a uniform quantum circuit family {Cn}n∈N.

◮ A term M can be evaluated by first reducing all the

“classical” redexes, and the reducing the “quantum” ones.

◮ This is possible due to a standardization result.

slide-86
SLIDE 86

Expressive Power

Theorem

Any uniform quantum circuit family {Cn}n∈N is simulated by a meas-free term M.

◮ Given s, the term M computes a code for C|s| ◮ Then, it applies C|s| to s.

Theorem

Any meas-free term M computes the same function as a uniform quantum circuit family {Cn}n∈N.

◮ A term M can be evaluated by first reducing all the

“classical” redexes, and the reducing the “quantum” ones.

◮ This is possible due to a standardization result.

slide-87
SLIDE 87

Expressive Power

Theorem

Any uniform quantum circuit family {Cn}n∈N is simulated by a meas-free term M.

◮ Given s, the term M computes a code for C|s| ◮ Then, it applies C|s| to s.

Theorem

Any meas-free term M computes the same function as a uniform quantum circuit family {Cn}n∈N.

◮ A term M can be evaluated by first reducing all the

“classical” redexes, and the reducing the “quantum” ones.

◮ This is possible due to a standardization result.

slide-88
SLIDE 88

Expressive Power

Theorem

Any uniform quantum circuit family {Cn}n∈N is simulated by a meas-free term M.

◮ Given s, the term M computes a code for C|s| ◮ Then, it applies C|s| to s.

Theorem

Any meas-free term M computes the same function as a uniform quantum circuit family {Cn}n∈N.

◮ A term M can be evaluated by first reducing all the

“classical” redexes, and the reducing the “quantum” ones.

◮ This is possible due to a standardization result.

slide-89
SLIDE 89

Wrapping Up

◮ Probabilistic and quantum programming are both at their

infancy.

◮ A lot of interest. ◮ Many different proposals. ◮ Not so many results relating one programming language to

the other.

◮ We have only presented some of the many proposals for

models and calculi.

◮ Very interesting topics we have no time to talk about:

◮ Denotational semantics. ◮ Type Systems. ◮ Implicit Computational Complexity. ◮ Concrete programming languages: Quipper, Church,

Venture, QScript.

slide-90
SLIDE 90

Wrapping Up

◮ Probabilistic and quantum programming are both at their

infancy.

◮ A lot of interest. ◮ Many different proposals. ◮ Not so many results relating one programming language to

the other.

◮ We have only presented some of the many proposals for

models and calculi.

◮ Very interesting topics we have no time to talk about:

◮ Denotational semantics. ◮ Type Systems. ◮ Implicit Computational Complexity. ◮ Concrete programming languages: Quipper, Church,

Venture, QScript.

slide-91
SLIDE 91

Wrapping Up

◮ Probabilistic and quantum programming are both at their

infancy.

◮ A lot of interest. ◮ Many different proposals. ◮ Not so many results relating one programming language to

the other.

◮ We have only presented some of the many proposals for

models and calculi.

◮ Very interesting topics we have no time to talk about:

◮ Denotational semantics. ◮ Type Systems. ◮ Implicit Computational Complexity. ◮ Concrete programming languages: Quipper, Church,

Venture, QScript.

slide-92
SLIDE 92

Thank You!

Questions?