Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf ·...

145
Introduction to Probabilistic and Quantum Programming Part III Ugo Dal Lago BISS 2014, Bertinoro

Transcript of Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf ·...

Page 1: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Introduction to Probabilisticand Quantum Programming

Part III

Ugo Dal Lago

BISS 2014, Bertinoro

Page 2: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Section 1

The λ-Calculus as a Functional Language

Page 3: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Minimal Syntax and Dynamics

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

I Substitution:

xx/M =M yx/M = y

NLx/M = (Nx/M)(Lx/M) λy.Nx/M = λy.(Nx/M)

I CBN Operational Semantics:

(λx.M)N →Mx/NM → N

ML→ NL

I Values:V ::= λx.M

I CBV Operational Semantics:

(λx.M)V →Mx/V M → N

ML→ NLM → N

VM → V N

Page 4: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Minimal Syntax and Dynamics

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

I Substitution:

xx/M =M yx/M = y

NLx/M = (Nx/M)(Lx/M) λy.Nx/M = λy.(Nx/M)

I CBN Operational Semantics:

(λx.M)N →Mx/NM → N

ML→ NL

I Values:V ::= λx.M

I CBV Operational Semantics:

(λx.M)V →Mx/V M → N

ML→ NLM → N

VM → V N

Page 5: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Minimal Syntax and Dynamics

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

I Substitution:

xx/M =M yx/M = y

NLx/M = (Nx/M)(Lx/M) λy.Nx/M = λy.(Nx/M)

I CBN Operational Semantics:

(λx.M)N →Mx/NM → N

ML→ NL

I Values:V ::= λx.M

I CBV Operational Semantics:

(λx.M)V →Mx/V M → N

ML→ NLM → N

VM → V N

Page 6: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Minimal Syntax and Dynamics

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

I Substitution:

xx/M =M yx/M = y

NLx/M = (Nx/M)(Lx/M) λy.Nx/M = λy.(Nx/M)

I CBN Operational Semantics:

(λx.M)N →Mx/NM → N

ML→ NL

I Values:V ::= λx.M

I CBV Operational Semantics:

(λx.M)V →Mx/V M → N

ML→ NLM → N

VM → V N

Page 7: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Minimal Syntax and Dynamics

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

I Substitution:

xx/M =M yx/M = y

NLx/M = (Nx/M)(Lx/M) λy.Nx/M = λy.(Nx/M)

I CBN Operational Semantics:

(λx.M)N →Mx/NM → N

ML→ NL

I Values:V ::= λx.M

I CBV Operational Semantics:

(λx.M)V →Mx/V M → N

ML→ NLM → N

VM → V N

Page 8: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

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

M = N0 → N1 → N2 → . . .

I There is a problem with substitutions:

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

I The standard solution is to consider terms modulo so-calledα-equivalence: renaming bound variables turns a terminto one which is indistinguishable.

λx.λy.xxy ≡ λz.λy.zzy.

I α-equivalence is not necessary if we assume to work withclosed terms.

Page 9: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

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

M = N0 → N1 → N2 → . . .

I There is a problem with substitutions:

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

I The standard solution is to consider terms modulo so-calledα-equivalence: renaming bound variables turns a terminto one which is indistinguishable.

λx.λy.xxy ≡ λz.λy.zzy.

I α-equivalence is not necessary if we assume to work withclosed terms.

Page 10: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

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

M = N0 → N1 → N2 → . . .

I There is a problem with substitutions:

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

I The standard solution is to consider terms modulo so-calledα-equivalence: renaming bound variables turns a terminto one which is indistinguishable.

λx.λy.xxy ≡ λz.λy.zzy.

I α-equivalence is not necessary if we assume to work withclosed terms.

Page 11: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Computing Simple Function on N, in CBV

I Natural Numbers

p0q = λx.λy.x;

pn+ 1q = λx.λy.ypnq.

I Finite Set A = a1, . . . , an

paiq = λx1 · · ·λxn.xi.

I Pairs〈M,N〉 = λx.xMN

I Fixed-Point Combinator

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

H = ΘΘ.

Page 12: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Computing Simple Functions on N, in CBV

I SuccessorSUCC = λz.λx.λy.yz

Indeed:SUCCpnq→ λx.λy.ypnq

I Projections

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

Indeed:

PROJki 〈pn1q, . . . , pnkq〉 → 〈pn1q, . . . , pnkq〉(λy1 · · ·λyk.yi)→ (λy1 · · ·λyk.yi)pn1q · · · pnkq→∗ pniq.

Page 13: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Computing Simple Functions on N, in CBV

I SuccessorSUCC = λz.λx.λy.yz

Indeed:SUCCpnq→ λx.λy.ypnq

I Projections

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

Indeed:

PROJki 〈pn1q, . . . , pnkq〉 → 〈pn1q, . . . , pnkq〉(λy1 · · ·λyk.yi)→ (λy1 · · ·λyk.yi)pn1q · · · pnkq→∗ pniq.

Page 14: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Computing Simple Functions on N, in CBV

I SuccessorSUCC = λz.λx.λy.yz

Indeed:SUCCpnq→ λx.λy.ypnq

I Projections

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

Indeed:

PROJki 〈pn1q, . . . , pnkq〉 → 〈pn1q, . . . , pnkq〉(λy1 · · ·λyk.yi)→ (λy1 · · ·λyk.yi)pn1q · · · pnkq→∗ pniq.

Page 15: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Computing Simple Functions on N, in CBV

I SuccessorSUCC = λz.λx.λy.yz

Indeed:SUCCpnq→ λx.λy.ypnq

I Projections

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

Indeed:

PROJki 〈pn1q, . . . , pnkq〉 → 〈pn1q, . . . , pnkq〉(λy1 · · ·λyk.yi)→ (λy1 · · ·λyk.yi)pn1q · · · pnkq→∗ pniq.

Page 16: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

A Simple Form of Recursion

I Suppose you have a term Mf which computes the functionf : N→ N, and you want to iterate over it, i.e. you want tocompute g : N× N→ N such that

g(0, n) = n;

g(m+ 1, n) = f(g(m,n)).

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

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

I The function g can be computed by way of

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

Page 17: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

A Simple Form of Recursion

I Suppose you have a term Mf which computes the functionf : N→ N, and you want to iterate over it, i.e. you want tocompute g : N× N→ N such that

g(0, n) = n;

g(m+ 1, n) = f(g(m,n)).

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

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

I The function g can be computed by way of

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

Page 18: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

A Simple Form of Recursion

I Suppose you have a term Mf which computes the functionf : N→ N, and you want to iterate over it, i.e. you want tocompute g : N× N→ N such that

g(0, n) = n;

g(m+ 1, n) = f(g(m,n)).

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

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

I The function g can be computed by way of

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

Page 19: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

A Simple Form of Recursion

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

Mg〈pm+ 1q, pnq〉 →∗ 〈pm+ 1q, pnq〉(λz.λw.zw(λq.Mf ((λx.Mgx)〈q, w〉x))→ (λz.λw.zw(λq.Mf ((λx.Mgx)〈q, pnq〉))pm+ 1qpnq

→∗ pm+ 1qpnq(λq.Mf ((λx.Mgx)〈q, pnq〉))→∗ (λq.Mf ((λx.Mgx)〈q, pnq〉))pmq

→∗ Mf ((λx.Mgx)〈pmq, pnq〉)→∗ Mf (Mg〈pmq, pnq〉)

Page 20: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

A Simple Form of Recursion

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

Mg〈pm+ 1q, pnq〉 →∗ 〈pm+ 1q, pnq〉(λz.λw.zw(λq.Mf ((λx.Mgx)〈q, w〉x))→ (λz.λw.zw(λq.Mf ((λx.Mgx)〈q, pnq〉))pm+ 1qpnq

→∗ pm+ 1qpnq(λq.Mf ((λx.Mgx)〈q, pnq〉))→∗ (λq.Mf ((λx.Mgx)〈q, pnq〉))pmq

→∗ Mf ((λx.Mgx)〈pmq, pnq〉)→∗ Mf (Mg〈pmq, pnq〉)

Page 21: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

A Simple Form of Recursion

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

Mg〈pm+ 1q, pnq〉 →∗ 〈pm+ 1q, pnq〉(λz.λw.zw(λq.Mf ((λx.Mgx)〈q, w〉x))→ (λz.λw.zw(λq.Mf ((λx.Mgx)〈q, pnq〉))pm+ 1qpnq

→∗ pm+ 1qpnq(λq.Mf ((λx.Mgx)〈q, pnq〉))→∗ (λq.Mf ((λx.Mgx)〈q, pnq〉))pmq

→∗ Mf ((λx.Mgx)〈pmq, pnq〉)→∗ Mf (Mg〈pmq, pnq〉)

Page 22: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

A Simple Form of Recursion

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

Mg〈pm+ 1q, pnq〉 →∗ 〈pm+ 1q, pnq〉(λz.λw.zw(λq.Mf ((λx.Mgx)〈q, w〉x))→ (λz.λw.zw(λq.Mf ((λx.Mgx)〈q, pnq〉))pm+ 1qpnq

→∗ pm+ 1qpnq(λq.Mf ((λx.Mgx)〈q, pnq〉))→∗ (λq.Mf ((λx.Mgx)〈q, pnq〉))pmq

→∗ Mf ((λx.Mgx)〈pmq, pnq〉)→∗ Mf (Mg〈pmq, pnq〉)

Page 23: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

A Simple Form of Recursion

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

Mg〈pm+ 1q, pnq〉 →∗ 〈pm+ 1q, pnq〉(λz.λw.zw(λq.Mf ((λx.Mgx)〈q, w〉x))→ (λz.λw.zw(λq.Mf ((λx.Mgx)〈q, pnq〉))pm+ 1qpnq

→∗ pm+ 1qpnq(λq.Mf ((λx.Mgx)〈q, pnq〉))→∗ (λq.Mf ((λx.Mgx)〈q, pnq〉))pmq

→∗ Mf ((λx.Mgx)〈pmq, pnq〉)→∗ Mf (Mg〈pmq, pnq〉)

Page 24: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

A Simple Form of Recursion

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

Mg〈pm+ 1q, pnq〉 →∗ 〈pm+ 1q, pnq〉(λz.λw.zw(λq.Mf ((λx.Mgx)〈q, w〉x))→ (λz.λw.zw(λq.Mf ((λx.Mgx)〈q, pnq〉))pm+ 1qpnq

→∗ pm+ 1qpnq(λq.Mf ((λx.Mgx)〈q, pnq〉))→∗ (λq.Mf ((λx.Mgx)〈q, pnq〉))pmq

→∗ Mf ((λx.Mgx)〈pmq, pnq〉)→∗ Mf (Mg〈pmq, pnq〉)

Page 25: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

A Simple Form of Recursion

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

Mg〈pm+ 1q, pnq〉 →∗ 〈pm+ 1q, pnq〉(λz.λw.zw(λq.Mf ((λx.Mgx)〈q, w〉x))→ (λz.λw.zw(λq.Mf ((λx.Mgx)〈q, pnq〉))pm+ 1qpnq

→∗ pm+ 1qpnq(λq.Mf ((λx.Mgx)〈q, pnq〉))→∗ (λq.Mf ((λx.Mgx)〈q, pnq〉))pmq

→∗ Mf ((λx.Mgx)〈pmq, pnq〉)→∗ Mf (Mg〈pmq, pnq〉)

Page 26: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Universality

I One could go on, and show that the following schemes canall be encoded:

I Composition;I Primitive Recursion;I Minimization.

I This implies that all partial recursive functions can becomputed in the λ-calculus.

TheoremThe λ-calculus is Turing-complete, both when CBV and CBNare considered.

Page 27: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Why is This a Faithful Model of FunctionalComputation?

I Data, conditionals, basic functions, and recursion can all beencoded into the λ-calculus. We can then give programs“informally”, in our favourite functional language.

I Take, as an example, the usual recursive programcomputing the factorial of a natural numberlet rec fact x = if (x==0) then 1 else x*(fact x-1)

I This can indeed be turned into a λ-term (where M∗ andM−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 p1q (x*(fact x-1)))

H(λfact.λx.x p1q (M∗ x (fact x-1)))

H(λfact.λx.x p1q (M∗ x (fact (M−1x))))

Page 28: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Why is This a Faithful Model of FunctionalComputation?

I Data, conditionals, basic functions, and recursion can all beencoded into the λ-calculus. We can then give programs“informally”, in our favourite functional language.

I Take, as an example, the usual recursive programcomputing the factorial of a natural numberlet rec fact x = if (x==0) then 1 else x*(fact x-1)

I This can indeed be turned into a λ-term (where M∗ andM−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 p1q (x*(fact x-1)))

H(λfact.λx.x p1q (M∗ x (fact x-1)))

H(λfact.λx.x p1q (M∗ x (fact (M−1x))))

Page 29: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Why is This a Faithful Model of FunctionalComputation?

I Data, conditionals, basic functions, and recursion can all beencoded into the λ-calculus. We can then give programs“informally”, in our favourite functional language.

I Take, as an example, the usual recursive programcomputing the factorial of a natural numberlet rec fact x = if (x==0) then 1 else x*(fact x-1)

I This can indeed be turned into a λ-term (where M∗ andM−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 p1q (x*(fact x-1)))

H(λfact.λx.x p1q (M∗ x (fact x-1)))

H(λfact.λx.x p1q (M∗ x (fact (M−1x))))

Page 30: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Why is This a Faithful Model of FunctionalComputation?

I Data, conditionals, basic functions, and recursion can all beencoded into the λ-calculus. We can then give programs“informally”, in our favourite functional language.

I Take, as an example, the usual recursive programcomputing the factorial of a natural numberlet rec fact x = if (x==0) then 1 else x*(fact x-1)

I This can indeed be turned into a λ-term (where M∗ andM−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 p1q (x*(fact x-1)))

H(λfact.λx.x p1q (M∗ x (fact x-1)))

H(λfact.λx.x p1q (M∗ x (fact (M−1x))))

Page 31: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Why is This a Faithful Model of FunctionalComputation?

I Data, conditionals, basic functions, and recursion can all beencoded into the λ-calculus. We can then give programs“informally”, in our favourite functional language.

I Take, as an example, the usual recursive programcomputing the factorial of a natural numberlet rec fact x = if (x==0) then 1 else x*(fact x-1)

I This can indeed be turned into a λ-term (where M∗ andM−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 p1q (x*(fact x-1)))

H(λfact.λx.x p1q (M∗ x (fact x-1)))

H(λfact.λx.x p1q (M∗ x (fact (M−1x))))

Page 32: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

More About SemanticsI The semantics we have adopted so far is said to besmall-step, since it derives assertions in the form M → N ,each corresponding to one atomic computation step.

I There is an equivalent way of formulating the sameconcept, big-step semantics, in which we “jump directlyto the result”:

I CBN

V ⇓ VM ⇓ λx.N Nx/L ⇓ V

ML ⇓ V

I CBV

V ⇓ VM ⇓ λx.N L ⇓ V Nx/V ⇓W

ML ⇓W

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

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

Page 33: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

More About SemanticsI The semantics we have adopted so far is said to besmall-step, since it derives assertions in the form M → N ,each corresponding to one atomic computation step.

I There is an equivalent way of formulating the sameconcept, big-step semantics, in which we “jump directlyto the result”:

I CBN

V ⇓ VM ⇓ λx.N Nx/L ⇓ V

ML ⇓ V

I CBV

V ⇓ VM ⇓ λx.N L ⇓ V Nx/V ⇓W

ML ⇓W

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

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

Page 34: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

More About SemanticsI The semantics we have adopted so far is said to besmall-step, since it derives assertions in the form M → N ,each corresponding to one atomic computation step.

I There is an equivalent way of formulating the sameconcept, big-step semantics, in which we “jump directlyto the result”:

I CBN

V ⇓ VM ⇓ λx.N Nx/L ⇓ V

ML ⇓ V

I CBV

V ⇓ VM ⇓ λx.N L ⇓ V Nx/V ⇓W

ML ⇓W

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

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

Page 35: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Program Equivalence

I A fundamental question in programming language theory isthe following: when can two programs be consideredequivalent?

I A satisfactory answer to this question would enable:I To validate program optimizations; you could be sure

that the transformations you are performing turn programsinto equivalent ones.

I To perform program verification; just compare theprogram at hand with another (abstract) programcorresponding to the underlying specification.

I But what is the right notion of program equivalence?I M ≡ N iff M = N ; trivial!I M ≡ N iff either M ⇓ V and N ⇓ V for some V or M ⇑ andN ⇑; does not equate values which behave the same.

I M ≡ N iff M and N “have the same semantics”; nice, butwe do not have time to talk about program’s semantics.

Page 36: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Program Equivalence

I A fundamental question in programming language theory isthe following: when can two programs be consideredequivalent?

I A satisfactory answer to this question would enable:I To validate program optimizations; you could be sure

that the transformations you are performing turn programsinto equivalent ones.

I To perform program verification; just compare theprogram at hand with another (abstract) programcorresponding to the underlying specification.

I But what is the right notion of program equivalence?I M ≡ N iff M = N ; trivial!I M ≡ N iff either M ⇓ V and N ⇓ V for some V or M ⇑ andN ⇑; does not equate values which behave the same.

I M ≡ N iff M and N “have the same semantics”; nice, butwe do not have time to talk about program’s semantics.

Page 37: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Program Equivalence

I A fundamental question in programming language theory isthe following: when can two programs be consideredequivalent?

I A satisfactory answer to this question would enable:I To validate program optimizations; you could be sure

that the transformations you are performing turn programsinto equivalent ones.

I To perform program verification; just compare theprogram at hand with another (abstract) programcorresponding to the underlying specification.

I But what is the right notion of program equivalence?I M ≡ N iff M = N ; trivial!I M ≡ N iff either M ⇓ V and N ⇓ V for some V or M ⇑ andN ⇑; does not equate values which behave the same.

I M ≡ N iff M and N “have the same semantics”; nice, butwe do not have time to talk about program’s semantics.

Page 38: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Program Equivalence

I A fundamental question in programming language theory isthe following: when can two programs be consideredequivalent?

I A satisfactory answer to this question would enable:I To validate program optimizations; you could be sure

that the transformations you are performing turn programsinto equivalent ones.

I To perform program verification; just compare theprogram at hand with another (abstract) programcorresponding to the underlying specification.

I But what is the right notion of program equivalence?I M ≡ N iff M = N ; trivial!I M ≡ N iff either M ⇓ V and N ⇓ V for some V or M ⇑ andN ⇑; does not equate values which behave the same.

I M ≡ N iff M and N “have the same semantics”; nice, butwe do not have time to talk about program’s semantics.

Page 39: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Program Equivalence

I A fundamental question in programming language theory isthe following: when can two programs be consideredequivalent?

I A satisfactory answer to this question would enable:I To validate program optimizations; you could be sure

that the transformations you are performing turn programsinto equivalent ones.

I To perform program verification; just compare theprogram at hand with another (abstract) programcorresponding to the underlying specification.

I But what is the right notion of program equivalence?I M ≡ N iff M = N ; trivial!I M ≡ N iff either M ⇓ V and N ⇓ V for some V or M ⇑ andN ⇑; does not equate values which behave the same.

I M ≡ N iff M and N “have the same semantics”; nice, butwe do not have time to talk about program’s semantics.

Page 40: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Context Equivalence

I What we need is a notion of equivalence which equatesterms with the same behaviour.

I More specifically, we would like to equate those termswhich have the same observable behavior in every context.

I Observable Behaviour. Two terms M and N have thesame observable behaviour whenver M ⇓ iff N ⇓ .

I Contexts. They are defined as terms, but they contain aunique placeholder [·]:

C ::= [·] | CM | MC | λx.C.

The term C[M ] is the one obtained from C by substituting[·] with M .

I We can then stipulate that M ≡ N iff for every C, C[M ] ⇓iff C[N ] ⇓.

Page 41: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Context Equivalence

I What we need is a notion of equivalence which equatesterms with the same behaviour.

I More specifically, we would like to equate those termswhich have the same observable behavior in every context.

I Observable Behaviour. Two terms M and N have thesame observable behaviour whenver M ⇓ iff N ⇓ .

I Contexts. They are defined as terms, but they contain aunique placeholder [·]:

C ::= [·] | CM | MC | λx.C.

The term C[M ] is the one obtained from C by substituting[·] with M .

I We can then stipulate that M ≡ N iff for every C, C[M ] ⇓iff C[N ] ⇓.

Page 42: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Context Equivalence

I What we need is a notion of equivalence which equatesterms with the same behaviour.

I More specifically, we would like to equate those termswhich have the same observable behavior in every context.

I Observable Behaviour. Two terms M and N have thesame observable behaviour whenver M ⇓ iff N ⇓ .

I Contexts. They are defined as terms, but they contain aunique placeholder [·]:

C ::= [·] | CM | MC | λx.C.

The term C[M ] is the one obtained from C by substituting[·] with M .

I We can then stipulate that M ≡ N iff for every C, C[M ] ⇓iff C[N ] ⇓.

Page 43: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Context Equivalence

I Examples:λx.x ≡ λx.(λy.y)x

(λx.xx)(λx.xx) = Ω 6≡ λx.Ω

I Exercise: is it true that for every closed M , M ≡ λx.Mx?I Proving that two terms are not context equivalent seems to

be easier than proving that they are.I We need some new techniques to overcome this problem.

Page 44: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Context Equivalence

I Examples:λx.x ≡ λx.(λy.y)x

(λx.xx)(λx.xx) = Ω 6≡ λx.Ω

I Exercise: is it true that for every closed M , M ≡ λx.Mx?I Proving that two terms are not context equivalent seems to

be easier than proving that they are.I We need some new techniques to overcome this problem.

Page 45: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Context Equivalence

I Examples:λx.x ≡ λx.(λy.y)x

(λx.xx)(λx.xx) = Ω 6≡ λx.Ω

I Exercise: is it true that for every closed M , M ≡ λx.Mx?I Proving that two terms are not context equivalent seems to

be easier than proving that they are.I We need some new techniques to overcome this problem.

Page 46: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Context Equivalence

I Examples:λx.x ≡ λx.(λy.y)x

(λx.xx)(λx.xx) = Ω 6≡ λx.Ω

I Exercise: is it true that for every closed M , M ≡ λx.Mx?I Proving that two terms are not context equivalent seems to

be easier than proving that they are.I We need some new techniques to overcome this problem.

Page 47: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Context Equivalence

I Examples:λx.x ≡ λx.(λy.y)x

(λx.xx)(λx.xx) = Ω 6≡ λx.Ω

I Exercise: is it true that for every closed M , M ≡ λx.Mx?I Proving that two terms are not context equivalent seems to

be easier than proving that they are.I We need some new techniques to overcome this problem.

Page 48: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Applicative Bisimulation

Terms Values

M

N

L

...

V

W

Z

...

Page 49: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Applicative Bisimulation

Terms Values

M

N

L

...

V

W

Z

...

Page 50: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Applicative Bisimulation

Terms Values

M

N

L

...

V

W

Z

...

Page 51: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Applicative Bisimulation

Terms Values

M

N

L

...

V

W

Z

...

Page 52: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Applicative Bisimulation

Terms Values

M

N

L

...

V

W

Z

...

M

Page 53: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Applicative Bisimulation

Terms Values

M

N

L

...

V

W

Z

...

M Veval

Page 54: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Applicative Bisimulation

Terms Values

M

N

L

...

V

W

Z

...

M Veval

λx.N

Page 55: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Applicative Bisimulation

Terms Values

M

N

L

...

V

W

Z

...

M Veval

λx.NNx/W W

Page 56: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Applicative Bisimulation

I Simulation.I If M R N and M ⇓ λx.L, then N ⇓ λx.P and for every

argument Q, (LQ/x) R (PQ/x).I Bisimulation.

I If M R N then:I If M ⇓ λx.L, then N ⇓ λx.P and for every argument Q,

(LQ/x) R (PQ/x).I If N ⇓ λx.L, then M ⇓ λx.P and for every argument Q,

(LQ/x) R (PQ/x).I Similarity: union of all simulations, denoted -;I Bisimilarity: union of all bisimulation, denoted ∼.

Theorem (Full Abstraction)M ≡ N iff M ∼ N .

Page 57: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Applicative Bisimulation

I Simulation.I If M R N and M ⇓ λx.L, then N ⇓ λx.P and for every

argument Q, (LQ/x) R (PQ/x).I Bisimulation.

I If M R N then:I If M ⇓ λx.L, then N ⇓ λx.P and for every argument Q,

(LQ/x) R (PQ/x).I If N ⇓ λx.L, then M ⇓ λx.P and for every argument Q,

(LQ/x) R (PQ/x).I Similarity: union of all simulations, denoted -;I Bisimilarity: union of all bisimulation, denoted ∼.

Theorem (Full Abstraction)M ≡ N iff M ∼ N .

Page 58: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Applicative Bisimulation

I Suppose we want to prove that, indeed,

M = λx.x ≡ λx.(λy.y)x = N.

I In principle, we should consider all possible contexts.I But we can also exploit full-abstraction, and just exhibitone applicative bisimulation containing (M,N).

I Here it is:

R = (M,N)∪(L, (λx.x)L) | L is a closed term∪((λx.x)L,L) | L is a closed term∪(L,L) | L is a closed term

I Exercise: prove that R is indeed an applicativebisimulation.

Page 59: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Applicative Bisimulation

I Suppose we want to prove that, indeed,

M = λx.x ≡ λx.(λy.y)x = N.

I In principle, we should consider all possible contexts.I But we can also exploit full-abstraction, and just exhibitone applicative bisimulation containing (M,N).

I Here it is:

R = (M,N)∪(L, (λx.x)L) | L is a closed term∪((λx.x)L,L) | L is a closed term∪(L,L) | L is a closed term

I Exercise: prove that R is indeed an applicativebisimulation.

Page 60: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Applicative Bisimulation

I Suppose we want to prove that, indeed,

M = λx.x ≡ λx.(λy.y)x = N.

I In principle, we should consider all possible contexts.I But we can also exploit full-abstraction, and just exhibitone applicative bisimulation containing (M,N).

I Here it is:

R = (M,N)∪(L, (λx.x)L) | L is a closed term∪((λx.x)L,L) | L is a closed term∪(L,L) | L is a closed term

I Exercise: prove that R is indeed an applicativebisimulation.

Page 61: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Applicative Bisimulation

I Suppose we want to prove that, indeed,

M = λx.x ≡ λx.(λy.y)x = N.

I In principle, we should consider all possible contexts.I But we can also exploit full-abstraction, and just exhibitone applicative bisimulation containing (M,N).

I Here it is:

R = (M,N)∪(L, (λx.x)L) | L is a closed term∪((λx.x)L,L) | L is a closed term∪(L,L) | L is a closed term

I Exercise: prove that R is indeed an applicativebisimulation.

Page 62: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Applicative Bisimulation

I Suppose we want to prove that, indeed,

M = λx.x ≡ λx.(λy.y)x = N.

I In principle, we should consider all possible contexts.I But we can also exploit full-abstraction, and just exhibitone applicative bisimulation containing (M,N).

I Here it is:

R = (M,N)∪(L, (λx.x)L) | L is a closed term∪((λx.x)L,L) | L is a closed term∪(L,L) | L is a closed term

I Exercise: prove that R is indeed an applicativebisimulation.

Page 63: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Type Systems

I We haven’t considered any form of static type for ourprograms, so far.

I Some concrete programming languages are designed as todo type-checking only at runtime, i.e., they do not haveany static type system.

I Scheme, Python, etc.I Actually, endowing the λ-calculus with a type system is

relatively simple.I Types: A,B ::= bool | nat | A→ B | A×B | · · ·I Judgments: x1 : A1, . . . , xn : An `M : B.I Rules (Examples):

Γ `M : A→ B Γ ` N : AΓ `MN : B

Γ, x : A `M : B

Γ ` λx.M : A→ B

Γ, x : A ` x : A Γ ` H : (A→ A)→ A

Page 64: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Type Systems

I We haven’t considered any form of static type for ourprograms, so far.

I Some concrete programming languages are designed as todo type-checking only at runtime, i.e., they do not haveany static type system.

I Scheme, Python, etc.I Actually, endowing the λ-calculus with a type system is

relatively simple.I Types: A,B ::= bool | nat | A→ B | A×B | · · ·I Judgments: x1 : A1, . . . , xn : An `M : B.I Rules (Examples):

Γ `M : A→ B Γ ` N : AΓ `MN : B

Γ, x : A `M : B

Γ ` λx.M : A→ B

Γ, x : A ` x : A Γ ` H : (A→ A)→ A

Page 65: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Type Systems

I We haven’t considered any form of static type for ourprograms, so far.

I Some concrete programming languages are designed as todo type-checking only at runtime, i.e., they do not haveany static type system.

I Scheme, Python, etc.I Actually, endowing the λ-calculus with a type system is

relatively simple.I Types: A,B ::= bool | nat | A→ B | A×B | · · ·I Judgments: x1 : A1, . . . , xn : An `M : B.I Rules (Examples):

Γ `M : A→ B Γ ` N : AΓ `MN : B

Γ, x : A `M : B

Γ ` λx.M : A→ B

Γ, x : A ` x : A Γ ` H : (A→ A)→ A

Page 66: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Type Systems

I We haven’t considered any form of static type for ourprograms, so far.

I Some concrete programming languages are designed as todo type-checking only at runtime, i.e., they do not haveany static type system.

I Scheme, Python, etc.I Actually, endowing the λ-calculus with a type system is

relatively simple.I Types: A,B ::= bool | nat | A→ B | A×B | · · ·I Judgments: x1 : A1, . . . , xn : An `M : B.I Rules (Examples):

Γ `M : A→ B Γ ` N : AΓ `MN : B

Γ, x : A `M : B

Γ ` λx.M : A→ B

Γ, x : A ` x : A Γ ` H : (A→ A)→ A

Page 67: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Type Systems

I We haven’t considered any form of static type for ourprograms, so far.

I Some concrete programming languages are designed as todo type-checking only at runtime, i.e., they do not haveany static type system.

I Scheme, Python, etc.I Actually, endowing the λ-calculus with a type system is

relatively simple.I Types: A,B ::= bool | nat | A→ B | A×B | · · ·I Judgments: x1 : A1, . . . , xn : An `M : B.I Rules (Examples):

Γ `M : A→ B Γ ` N : AΓ `MN : B

Γ, x : A `M : B

Γ ` λx.M : A→ B

Γ, x : A ` x : A Γ ` H : (A→ A)→ A

Page 68: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Section 2

Probabilistic λ-Calculi

Page 69: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Probabilistic λ-Calculus: Syntax and OperationalSemantics

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

I Informally, M ⊕N rewrites to M or to N with probability12 : this is just like flippling a coin and choosing one of thetwo terms according to the result.

I A value distribution is a function D from the set V ofvalues to R such ∑

V ∈VD(V ) ≤ 1.

I The fact the sum can be strictly smaller than 1 is a wayto reflect (the probability of) divergence.

I The empty value distribution is denoted as ∅.I Useful notation for finite distributions: V p11 , . . . , V pnn .I Value distributions can be ordere, pointwise.I S(D) is the support of D , i.e. the set of values to which D

assigns nonnull probability.

Page 70: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Probabilistic λ-Calculus: Syntax and OperationalSemantics

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

I Informally, M ⊕N rewrites to M or to N with probability12 : this is just like flippling a coin and choosing one of thetwo terms according to the result.

I A value distribution is a function D from the set V ofvalues to R such ∑

V ∈VD(V ) ≤ 1.

I The fact the sum can be strictly smaller than 1 is a wayto reflect (the probability of) divergence.

I The empty value distribution is denoted as ∅.I Useful notation for finite distributions: V p11 , . . . , V pnn .I Value distributions can be ordere, pointwise.I S(D) is the support of D , i.e. the set of values to which D

assigns nonnull probability.

Page 71: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Probabilistic λ-Calculus: Syntax and OperationalSemantics

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

I Informally, M ⊕N rewrites to M or to N with probability12 : this is just like flippling a coin and choosing one of thetwo terms according to the result.

I A value distribution is a function D from the set V ofvalues to R such ∑

V ∈VD(V ) ≤ 1.

I The fact the sum can be strictly smaller than 1 is a wayto reflect (the probability of) divergence.

I The empty value distribution is denoted as ∅.I Useful notation for finite distributions: V p11 , . . . , V pnn .I Value distributions can be ordere, pointwise.I S(D) is the support of D , i.e. the set of values to which D

assigns nonnull probability.

Page 72: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Probabilistic λ-Calculus: Syntax and OperationalSemantics

I Approximation (Big-Step) Semantics, CBN:

M ⇓ ∅ V ⇓ V 1M ⇓ D N ⇓ E

M ⊕N ⇓ 12D + 1

2E

M ⇓ D Px/N ⇓ Eλx.P λx.P∈S(D)

MN ⇓∑

V ∈S(F)

D(V )Eλx.P

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

M ⇓ ∅ M ⇓ I12 M ⇓ I

34

I Semantics: [[M ]] = supM⇓D D ;I Variations: Small-Step Semantics, CBV.

Page 73: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Probabilistic λ-Calculus: Syntax and OperationalSemantics

I Approximation (Big-Step) Semantics, CBN:

M ⇓ ∅ V ⇓ V 1M ⇓ D N ⇓ E

M ⊕N ⇓ 12D + 1

2E

M ⇓ D Px/N ⇓ Eλx.P λx.P∈S(D)

MN ⇓∑

V ∈S(F)

D(V )Eλx.P

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

M ⇓ ∅ M ⇓ I12 M ⇓ I

34

I Semantics: [[M ]] = supM⇓D D ;I Variations: Small-Step Semantics, CBV.

Page 74: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Probabilistic λ-Calculus: Syntax and OperationalSemantics

I Approximation (Big-Step) Semantics, CBN:

M ⇓ ∅ V ⇓ V 1M ⇓ D N ⇓ E

M ⊕N ⇓ 12D + 1

2E

M ⇓ D Px/N ⇓ Eλx.P λx.P∈S(D)

MN ⇓∑

V ∈S(F)

D(V )Eλx.P

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

M ⇓ ∅ M ⇓ I12 M ⇓ I

34

I Semantics: [[M ]] = supM⇓D D ;I Variations: Small-Step Semantics, CBV.

Page 75: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Probabilistic λ-Calculus: Syntax and OperationalSemantics

I Approximation (Big-Step) Semantics, CBN:

M ⇓ ∅ V ⇓ V 1M ⇓ D N ⇓ E

M ⊕N ⇓ 12D + 1

2E

M ⇓ D Px/N ⇓ Eλx.P λx.P∈S(D)

MN ⇓∑

V ∈S(F)

D(V )Eλx.P

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

M ⇓ ∅ M ⇓ I12 M ⇓ I

34

I Semantics: [[M ]] = supM⇓D D ;I Variations: Small-Step Semantics, CBV.

Page 76: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Probabilistic λ-Calculus: Syntax and OperationalSemantics

I Approximation (Big-Step) Semantics, CBN:

M ⇓ ∅ V ⇓ V 1M ⇓ D N ⇓ E

M ⊕N ⇓ 12D + 1

2E

M ⇓ D Px/N ⇓ Eλx.P λx.P∈S(D)

MN ⇓∑

V ∈S(F)

D(V )Eλx.P

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

M ⇓ ∅ M ⇓ I12 M ⇓ I

34

I Semantics: [[M ]] = supM⇓D D ;I Variations: Small-Step Semantics, CBV.

Page 77: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Probabilistic λ-Calculus: Syntax and OperationalSemantics

I Approximation (Big-Step) Semantics, CBN:

M ⇓ ∅ V ⇓ V 1M ⇓ D N ⇓ E

M ⊕N ⇓ 12D + 1

2E

M ⇓ D Px/N ⇓ Eλx.P λx.P∈S(D)

MN ⇓∑

V ∈S(F)

D(V )Eλx.P

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

M ⇓ ∅ M ⇓ I12 M ⇓ I

34

I Semantics: [[M ]] = supM⇓D D ;I Variations: Small-Step Semantics, CBV.

Page 78: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Probabilistic λ-Calculus: Syntax and OperationalSemantics

I As an example, consider the following recursive program,and call it M :let rec fancy x = x (+) (fancy x+1)

I One can easily check that:

Mp0q ⇓ ∅ Mp0q ⇓ p0q12 Mp0q ⇓ p0q

12 , p1q

14 · · ·

I As a consequence:

[[Mp0q]] = supMp0q⇓D

D = p0q12 , p1q

14 , p2q

18 , . . .

I As an exercise, find a term N such that[[N ]] = p1q

12 , p4q

14 , p9q

18 , . . .

Page 79: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Probabilistic λ-Calculus: Syntax and OperationalSemantics

I As an example, consider the following recursive program,and call it M :let rec fancy x = x (+) (fancy x+1)

I One can easily check that:

Mp0q ⇓ ∅ Mp0q ⇓ p0q12 Mp0q ⇓ p0q

12 , p1q

14 · · ·

I As a consequence:

[[Mp0q]] = supMp0q⇓D

D = p0q12 , p1q

14 , p2q

18 , . . .

I As an exercise, find a term N such that[[N ]] = p1q

12 , p4q

14 , p9q

18 , . . .

Page 80: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Probabilistic λ-Calculus: Syntax and OperationalSemantics

I As an example, consider the following recursive program,and call it M :let rec fancy x = x (+) (fancy x+1)

I One can easily check that:

Mp0q ⇓ ∅ Mp0q ⇓ p0q12 Mp0q ⇓ p0q

12 , p1q

14 · · ·

I As a consequence:

[[Mp0q]] = supMp0q⇓D

D = p0q12 , p1q

14 , p2q

18 , . . .

I As an exercise, find a term N such that[[N ]] = p1q

12 , p4q

14 , p9q

18 , . . .

Page 81: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Probabilistic λ-Calculus: Syntax and OperationalSemantics

I As an example, consider the following recursive program,and call it M :let rec fancy x = x (+) (fancy x+1)

I One can easily check that:

Mp0q ⇓ ∅ Mp0q ⇓ p0q12 Mp0q ⇓ p0q

12 , p1q

14 · · ·

I As a consequence:

[[Mp0q]] = supMp0q⇓D

D = p0q12 , p1q

14 , p2q

18 , . . .

I As an exercise, find a term N such that[[N ]] = p1q

12 , p4q

14 , p9q

18 , . . .

Page 82: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Probabilistic λ-Calculus: Syntax and OperationalSemantics

I As an example, consider the following recursive program,and call it M :let rec fancy x = x (+) (fancy x+1)

I One can easily check that:

Mp0q ⇓ ∅ Mp0q ⇓ p0q12 Mp0q ⇓ p0q

12 , p1q

14 · · ·

I As a consequence:

[[Mp0q]] = supMp0q⇓D

D = p0q12 , p1q

14 , p2q

18 , . . .

I As an exercise, find a term N such that[[N ]] = p1q

12 , p4q

14 , p9q

18 , . . .

Page 83: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Probabilistic λ-Calculus: Syntax and OperationalSemantics

I As an example, consider the following recursive program,and call it M :let rec fancy x = x (+) (fancy x+1)

I One can easily check that:

Mp0q ⇓ ∅ Mp0q ⇓ p0q12 Mp0q ⇓ p0q

12 , p1q

14 · · ·

I As a consequence:

[[Mp0q]] = supMp0q⇓D

D = p0q12 , p1q

14 , p2q

18 , . . .

I As an exercise, find a term N such that[[N ]] = p1q

12 , p4q

14 , p9q

18 , . . .

Page 84: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Contextual Equivalence in a Probabilistic Setting

I In analogy to the deterministic setting, we observeconvergence, which now becomes quantitative.

I The observable behaviour of M is given by∑[[M ]] =

∑V ∈V [[M ]](V ).

I But∑

[[M ]] is nothing more than the probability ofconvergence for the term M .

I Contexts are extended to reflect the presence ofprobabilistic choice

C ::= [·] | CM | MC | λx.C | C ⊕M | M ⊕ C.I Analogously to the deterministic case, M ≡ N iff for everyC, the following equality holds:∑

[[C[M ]]] =∑

[[C[N ]]].

Page 85: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Motivating Example: Perfect Security

Page 86: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Motivating Example: Perfect Security

I We want to formalize the notion of perfect security for anencryption scheme.

I TakeM and C as the random variables modelingmessages and cryptograms, respectively.

I Of course, the two variables are not independent, at least inprinciple.

I If we want the underlying scheme to be secure, we need tobe sure that they are as independent as possible.

Pr(M = m | C = c) = Pr(M = m).

Pr(C = c | M = m) = Pr(C = c).

Pr(C = c | M = m0) = Pr(C = c | M = m1).

Page 87: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Motivating Example: Perfect Security

I We want to formalize the notion of perfect security for anencryption scheme.

I TakeM and C as the random variables modelingmessages and cryptograms, respectively.

I Of course, the two variables are not independent, at least inprinciple.

I If we want the underlying scheme to be secure, we need tobe sure that they are as independent as possible.

Pr(M = m | C = c) = Pr(M = m).

Pr(C = c | M = m) = Pr(C = c).

Pr(C = c | M = m0) = Pr(C = c | M = m1).

Page 88: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Motivating Example: Perfect Security

I We want to formalize the notion of perfect security for anencryption scheme.

I TakeM and C as the random variables modelingmessages and cryptograms, respectively.

I Of course, the two variables are not independent, at least inprinciple.

I If we want the underlying scheme to be secure, we need tobe sure that they are as independent as possible.

Pr(M = m | C = c) = Pr(M = m).

Pr(C = c | M = m) = Pr(C = c).

Pr(C = c | M = m0) = Pr(C = c | M = m1).

Page 89: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Motivating Example: Perfect Security

I We want to formalize the notion of perfect security for anencryption scheme.

I TakeM and C as the random variables modelingmessages and cryptograms, respectively.

I Of course, the two variables are not independent, at least inprinciple.

I If we want the underlying scheme to be secure, we need tobe sure that they are as independent as possible.

Pr(M = m | C = c) = Pr(M = m).

Pr(C = c | M = m) = Pr(C = c).

Pr(C = c | M = m0) = Pr(C = c | M = m1).

Page 90: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Motivating Example: Perfect Security

I We want to formalize the notion of perfect security for anencryption scheme.

I TakeM and C as the random variables modelingmessages and cryptograms, respectively.

I Of course, the two variables are not independent, at least inprinciple.

I If we want the underlying scheme to be secure, we need tobe sure that they are as independent as possible.

Pr(M = m | C = c) = Pr(M = m).

Pr(C = c | M = m) = Pr(C = c).

Pr(C = c | M = m0) = Pr(C = c | M = m1).

Page 91: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Motivating Example: Perfect Security

I We want to formalize the notion of perfect security for anencryption scheme.

I TakeM and C as the random variables modelingmessages and cryptograms, respectively.

I Of course, the two variables are not independent, at least inprinciple.

I If we want the underlying scheme to be secure, we need tobe sure that they are as independent as possible.

Pr(M = m | C = c) = Pr(M = m).

Pr(C = c | M = m) = Pr(C = c).

Pr(C = c | M = m0) = Pr(C = c | M = m1).

Page 92: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Motivating Example: Perfect Security

PrivKm0,m1 ← A1;b← 0, 1;k ← GEN ;c← ENC (mb, k);b′ ← A2(c);return b = b′.

Page 93: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Motivating Example: Perfect Security

PrivKm0,m1 ← A1;b← 0, 1;k ← GEN ;c← ENC (mb, k);b′ ← A2(c);return b = b′.

Page 94: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Motivating Example: Perfect Security

PrivKm0,m1 ← A1;b← 0, 1;k ← GEN ;c← ENC (mb, k);b′ ← A2(c);return b = b′.

Page 95: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Motivating Example: Perfect Security

PrivKm0,m1 ← A1;b← 0, 1;k ← GEN ;c← ENC (mb, k);b′ ← A2(c);return b = b′.

Page 96: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Motivating Example: Perfect Security

PrivKm0,m1 ← A1;b← 0, 1;k ← GEN ;c← ENC (mb, k);b′ ← A2(c);return b = b′.

Page 97: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Motivating Example: Perfect Security

PrivKm0,m1 ← A1;b← 0, 1;k ← GEN ;c← ENC (mb, k);b′ ← A2(c);return b = b′.

Page 98: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Motivating Example: Perfect Security

Pr (PrivK = true) =1

2

Page 99: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Motivating Example: Perfect Security

One-Time-PadGEN = tt⊕ ff : bool;

ENC = λx.λy.if x then ¬y else y : bool→ bool→ bool;

The Experiment as a Pair of TermsEXPFST = λx.λy.ENC x GEN : bool→ bool→ bool;

EXPSND = λx.λy.ENC y GEN : bool→ bool→ bool.

∀A.Pr(PrivKOTP = true) =1

2⇔ EXPFST ≡ EXPSND

Another ExperimentEXPCPA

FST = λx.λy.(λz.〈ENC x z, λw.ENC w z〉)GEN ;

EXPCPASND = λx.λy.(λz.〈ENC y z, λw.ENC w z〉)GEN .

Page 100: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Motivating Example: Perfect Security

One-Time-PadGEN = tt⊕ ff : bool;

ENC = λx.λy.if x then ¬y else y : bool→ bool→ bool;

The Experiment as a Pair of TermsEXPFST = λx.λy.ENC x GEN : bool→ bool→ bool;

EXPSND = λx.λy.ENC y GEN : bool→ bool→ bool.

∀A.Pr(PrivKOTP = true) =1

2⇔ EXPFST ≡ EXPSND

Another ExperimentEXPCPA

FST = λx.λy.(λz.〈ENC x z, λw.ENC w z〉)GEN ;

EXPCPASND = λx.λy.(λz.〈ENC y z, λw.ENC w z〉)GEN .

Page 101: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Motivating Example: Perfect Security

One-Time-PadGEN = tt⊕ ff : bool;

ENC = λx.λy.if x then ¬y else y : bool→ bool→ bool;

The Experiment as a Pair of TermsEXPFST = λx.λy.ENC x GEN : bool→ bool→ bool;

EXPSND = λx.λy.ENC y GEN : bool→ bool→ bool.

∀A.Pr(PrivKOTP = true) =1

2⇔ EXPFST ≡ EXPSND

Another ExperimentEXPCPA

FST = λx.λy.(λz.〈ENC x z, λw.ENC w z〉)GEN ;

EXPCPASND = λx.λy.(λz.〈ENC y z, λw.ENC w z〉)GEN .

Page 102: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Motivating Example: Perfect Security

One-Time-PadGEN = tt⊕ ff : bool;

ENC = λx.λy.if x then ¬y else y : bool→ bool→ bool;

The Experiment as a Pair of TermsEXPFST = λx.λy.ENC x GEN : bool→ bool→ bool;

EXPSND = λx.λy.ENC y GEN : bool→ bool→ bool.

∀A.Pr(PrivKOTP = true) =1

2⇔ EXPFST ≡ EXPSND

Another ExperimentEXPCPA

FST = λx.λy.(λz.〈ENC x z, λw.ENC w z〉)GEN ;

EXPCPASND = λx.λy.(λz.〈ENC y z, λw.ENC w z〉)GEN .

Page 103: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

The Probabilistic λ-Calculus as a Transition System

Terms Values

M V

W

Z

eval, [[M ]](V )

eval, [[M ]](W )

eval, [[M ]](Z)

λx.NNx/WW , 1

Page 104: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

The Probabilistic λ-Calculus as a Transition System

Terms Values

M V

W

Z

eval, [[M ]](V )

eval, [[M ]](W )

eval, [[M ]](Z)

λx.NNx/WW , 1

Page 105: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

The Probabilistic λ-Calculus as a Transition System

Terms Values

M V

W

Z

eval, [[M ]](V )

eval, [[M ]](W )

eval, [[M ]](Z)

λx.NNx/WW , 1

Page 106: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

The Probabilistic λ-Calculus as a Transition System

Terms Values

M V

W

Z

eval, [[M ]](V )

eval, [[M ]](W )

eval, [[M ]](Z)

λx.NNx/WW , 1

Page 107: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

The Probabilistic λ-Calculus as a Transition System

Terms Values

M V

W

Z

eval, [[M ]](V )

eval, [[M ]](W )

eval, [[M ]](Z)

λx.NNx/WW , 1

Page 108: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

The Probabilistic λ-Calculus as a Transition System

Terms Values

M V

W

Z

eval, [[M ]](V )

eval, [[M ]](W )

eval, [[M ]](Z)

λx.NNx/WW , 1

Page 109: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Spelling Out the Definition

λx.M ∼λx.N ML/x

L

NL/x

L

M∼N

[[M ]]eval

[[N ]]eval

[[M ]](E) [[N ]](E)=

Page 110: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Spelling Out the Definition

λx.M ∼λx.N ML/x

L

NL/x

L

M∼N

[[M ]]eval

[[N ]]eval

[[M ]](E) [[N ]](E)=

Page 111: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Spelling Out the Definition

λx.M ∼λx.N ML/x

L

NL/x

L

M∼N

[[M ]]eval

[[N ]]eval

[[M ]](E) [[N ]](E)=

Page 112: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Spelling Out the Definition

λx.M ∼λx.N ML/x

L

NL/x

L

M∼N

[[M ]]eval

[[N ]]eval

[[M ]](E) [[N ]](E)=

Page 113: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Spelling Out the Definition

λx.M ∼λx.N ML/x

L

NL/x

L

M∼N

[[M ]]eval

[[N ]]eval

[[M ]](E) [[N ]](E)=

Page 114: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Spelling Out the Definition

λx.M ∼λx.N ML/x

L

NL/x

L

M∼N

[[M ]]eval

[[N ]]eval

[[M ]](E) [[N ]](E)=

Page 115: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Spelling Out the Definition

λx.M ∼λx.N ML/x

L

NL/x

L

M∼N

[[M ]]eval

[[N ]]eval

[[M ]](E) [[N ]](E)=

Page 116: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Spelling Out the Definition

λx.M ∼λx.N ML/x

L

NL/x

L

M∼N

[[M ]]eval

[[N ]]eval

[[M ]](E) [[N ]](E)=

Page 117: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Spelling Out the Definition

λx.M ∼λx.N ML/x

L

NL/x

L

M∼N

[[M ]]eval

[[N ]]eval

[[M ]](E) [[N ]](E)=

Page 118: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Spelling Out the Definition

λx.M ∼λx.N ML/x

L

NL/x

L

M∼N

[[M ]]eval

[[N ]]eval

[[M ]](E) [[N ]](E)=

Page 119: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Probabilistic Applicative Bisimulation

I Suppose you want to prove that the following two terms arebisimilar (i.e., M ∼ N):

M = I ⊕ ((λx.Ω)⊕ (ΩI))

N = (Ω⊕ (λx.ΩI))⊕ (II)

I We should look for a probabilistic applicative bisimulationR including (M,N).

I Let’s proceed incrementally:

R = (M,N)∪(I, II), (II, I)∪(Ω,ΩI), (ΩI,Ω)

∪(λx.Ω, λx.ΩI), (λx.ΩI, λx.Ω)∪(L,L) | L is s closed term

Page 120: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Probabilistic Applicative Bisimulation

I Suppose you want to prove that the following two terms arebisimilar (i.e., M ∼ N):

M = I ⊕ ((λx.Ω)⊕ (ΩI))

N = (Ω⊕ (λx.ΩI))⊕ (II)

I We should look for a probabilistic applicative bisimulationR including (M,N).

I Let’s proceed incrementally:

R = (M,N)∪(I, II), (II, I)∪(Ω,ΩI), (ΩI,Ω)

∪(λx.Ω, λx.ΩI), (λx.ΩI, λx.Ω)∪(L,L) | L is s closed term

Page 121: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Probabilistic Applicative Bisimulation

I Suppose you want to prove that the following two terms arebisimilar (i.e., M ∼ N):

M = I ⊕ ((λx.Ω)⊕ (ΩI))

N = (Ω⊕ (λx.ΩI))⊕ (II)

I We should look for a probabilistic applicative bisimulationR including (M,N).

I Let’s proceed incrementally:

R = (M,N)∪(I, II), (II, I)∪(Ω,ΩI), (ΩI,Ω)

∪(λx.Ω, λx.ΩI), (λx.ΩI, λx.Ω)∪(L,L) | L is s closed term

Page 122: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Probabilistic Applicative Bisimulation

I Suppose you want to prove that the following two terms arebisimilar (i.e., M ∼ N):

M = I ⊕ ((λx.Ω)⊕ (ΩI))

N = (Ω⊕ (λx.ΩI))⊕ (II)

I We should look for a probabilistic applicative bisimulationR including (M,N).

I Let’s proceed incrementally:

R = (M,N)∪(I, II), (II, I)∪(Ω,ΩI), (ΩI,Ω)

∪(λx.Ω, λx.ΩI), (λx.ΩI, λx.Ω)∪(L,L) | L is s closed term

Page 123: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Probabilistic Applicative Bisimulation

I Suppose you want to prove that the following two terms arebisimilar (i.e., M ∼ N):

M = I ⊕ ((λx.Ω)⊕ (ΩI))

N = (Ω⊕ (λx.ΩI))⊕ (II)

I We should look for a probabilistic applicative bisimulationR including (M,N).

I Let’s proceed incrementally:

R = (M,N)∪(I, II), (II, I)∪(Ω,ΩI), (ΩI,Ω)

∪(λx.Ω, λx.ΩI), (λx.ΩI, λx.Ω)∪(L,L) | L is s closed term

Page 124: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Probabilistic Applicative Bisimulation

I Suppose you want to prove that the following two terms arebisimilar (i.e., M ∼ N):

M = I ⊕ ((λx.Ω)⊕ (ΩI))

N = (Ω⊕ (λx.ΩI))⊕ (II)

I We should look for a probabilistic applicative bisimulationR including (M,N).

I Let’s proceed incrementally:

R = (M,N)∪(I, II), (II, I)∪(Ω,ΩI), (ΩI,Ω)

∪(λx.Ω, λx.ΩI), (λx.ΩI, λx.Ω)∪(L,L) | L is s closed term

Page 125: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Probabilistic Applicative Bisimulation

I Suppose you want to prove that the following two terms arebisimilar (i.e., M ∼ N):

M = I ⊕ ((λx.Ω)⊕ (ΩI))

N = (Ω⊕ (λx.ΩI))⊕ (II)

I We should look for a probabilistic applicative bisimulationR including (M,N).

I Let’s proceed incrementally:

R = (M,N)∪(I, II), (II, I)∪(Ω,ΩI), (ΩI,Ω)

∪(λx.Ω, λx.ΩI), (λx.ΩI, λx.Ω)∪(L,L) | L is s closed term

Page 126: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Full Abstraction?I Is there any correspondence between probabilistic

applicative bisimulation on the one hand and contextequivalence on the other?

I Unfortunately, the situation is not as bright as in thedeterministic case

TheoremIn CBV, M ≡ N iff M ∼ N .

TheoremIn CBN, if M ∼ N then M ≡ N , but the converse does not hold.

I A counterexample for CBN is the following:

M = λx.Ω⊕ I N = (λx.Ω)⊕ (λx.I)

It is quite easy to see that M 6∼ N , while M ≡ N .

Page 127: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Full Abstraction?I Is there any correspondence between probabilistic

applicative bisimulation on the one hand and contextequivalence on the other?

I Unfortunately, the situation is not as bright as in thedeterministic case

TheoremIn CBV, M ≡ N iff M ∼ N .

TheoremIn CBN, if M ∼ N then M ≡ N , but the converse does not hold.

I A counterexample for CBN is the following:

M = λx.Ω⊕ I N = (λx.Ω)⊕ (λx.I)

It is quite easy to see that M 6∼ N , while M ≡ N .

Page 128: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Full Abstraction?I Is there any correspondence between probabilistic

applicative bisimulation on the one hand and contextequivalence on the other?

I Unfortunately, the situation is not as bright as in thedeterministic case

TheoremIn CBV, M ≡ N iff M ∼ N .

TheoremIn CBN, if M ∼ N then M ≡ N , but the converse does not hold.

I A counterexample for CBN is the following:

M = λx.Ω⊕ I N = (λx.Ω)⊕ (λx.I)

It is quite easy to see that M 6∼ N , while M ≡ N .

Page 129: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Full Abstraction?I Is there any correspondence between probabilistic

applicative bisimulation on the one hand and contextequivalence on the other?

I Unfortunately, the situation is not as bright as in thedeterministic case

TheoremIn CBV, M ≡ N iff M ∼ N .

TheoremIn CBN, if M ∼ N then M ≡ N , but the converse does not hold.

I A counterexample for CBN is the following:

M = λx.Ω⊕ I N = (λx.Ω)⊕ (λx.I)

It is quite easy to see that M 6∼ N , while M ≡ N .

Page 130: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Back to Our Example

EXPFST = λx.λy.ENC x GEN : bool→ bool→ bool;

EXPSND = λx.λy.ENC y GEN : bool→ bool→ bool.

Rσ = Xσ ×Xσ ∪ IDσ;

Xbool = (ENC tt GEN ), (ENC ff GEN );Xbool→bool = (λy.ENC y GEN ), (λy.ENC tt GEN ),

(λy.ENC ff GEN );Xbool→bool→bool = EXPFST ,EXPSND;

Page 131: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Back to Our Example

EXPFST = λx.λy.ENC x GEN : bool→ bool→ bool;

EXPSND = λx.λy.ENC y GEN : bool→ bool→ bool.

Rσ = Xσ ×Xσ ∪ IDσ;

Xbool = (ENC tt GEN ), (ENC ff GEN );Xbool→bool = (λy.ENC y GEN ), (λy.ENC tt GEN ),

(λy.ENC ff GEN );Xbool→bool→bool = EXPFST ,EXPSND;

Page 132: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Section 3

Quantum λ-Calculi

Page 133: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

A Naïve Attempt

I While looking for a quantum generalization of theλ-calculus, one could be tempted to proceed merely byenriching its syntax of terms as follows:

M,N ::= x | λx.M | MN | r | U | new | measwhere:

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

store;I U applies a unitary transform to one (or more) qubits from

the quantum store.I This would be enough to express, e.g., some simple

quantum circuits:

λx.λy.CNOT〈H x, y〉 λx.meas(H(new x))

Page 134: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

A Naïve Attempt

[∅, (λx.λy.CNOT〈H x, y〉)〈new p0q, new p0q〉]

→∗ [|r → 0〉 ⊗ |q → 0〉, (λx.λy.CNOT〈H x, y〉)〈r, q〉]

→ [|r → 0〉 ⊗ |q → 0〉,CNOT〈H r, q〉]

→ [1√2|r → 0, q → 0〉+

1√2|r → 1, q → 0〉,CNOT〈r, q〉]

→ [1√2|r → 0, q → 0〉+

1√2|r → 1, q → 1〉, 〈r, q〉]

Page 135: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

A Naïve Attempt

[∅, (λx.λy.CNOT〈H x, y〉)〈new p0q, new p0q〉]

→∗ [|r → 0〉 ⊗ |q → 0〉, (λx.λy.CNOT〈H x, y〉)〈r, q〉]

→ [|r → 0〉 ⊗ |q → 0〉,CNOT〈H r, q〉]

→ [1√2|r → 0, q → 0〉+

1√2|r → 1, q → 0〉,CNOT〈r, q〉]

→ [1√2|r → 0, q → 0〉+

1√2|r → 1, q → 1〉, 〈r, q〉]

Page 136: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

A Naïve Attempt

[∅, (λx.λy.CNOT〈H x, y〉)〈new p0q, new p0q〉]

→∗ [|r → 0〉 ⊗ |q → 0〉, (λx.λy.CNOT〈H x, y〉)〈r, q〉]

→ [|r → 0〉 ⊗ |q → 0〉,CNOT〈H r, q〉]

→ [1√2|r → 0, q → 0〉+

1√2|r → 1, q → 0〉,CNOT〈r, q〉]

→ [1√2|r → 0, q → 0〉+

1√2|r → 1, q → 1〉, 〈r, q〉]

Page 137: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

A Naïve Attempt

[∅, (λx.λy.CNOT〈H x, y〉)〈new p0q, new p0q〉]

→∗ [|r → 0〉 ⊗ |q → 0〉, (λx.λy.CNOT〈H x, y〉)〈r, q〉]

→ [|r → 0〉 ⊗ |q → 0〉,CNOT〈H r, q〉]

→ [1√2|r → 0, q → 0〉+

1√2|r → 1, q → 0〉,CNOT〈r, q〉]

→ [1√2|r → 0, q → 0〉+

1√2|r → 1, q → 1〉, 〈r, q〉]

Page 138: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

A Naïve Attempt

[∅, (λx.λy.CNOT〈H x, y〉)〈new p0q, new p0q〉]

→∗ [|r → 0〉 ⊗ |q → 0〉, (λx.λy.CNOT〈H x, y〉)〈r, q〉]

→ [|r → 0〉 ⊗ |q → 0〉,CNOT〈H r, q〉]

→ [1√2|r → 0, q → 0〉+

1√2|r → 1, q → 0〉,CNOT〈r, q〉]

→ [1√2|r → 0, q → 0〉+

1√2|r → 1, q → 1〉, 〈r, q〉]

Page 139: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

A Naïve Attempt

I This approach has some fundamental problems,however.

I Take the term (λx.CNOT〈x, x〉)new and suppose, as in theprevious example, to reduce it in CBV:

[∅, (λx.CNOT〈x, x〉)(newp0q)]

→ [|r → 0〉, (λx.CNOT〈x, x〉)r]→ [|r → 0〉,CNOT〈r, r〉]

I Qubits can be freely duplicated or erased!I And this goes against the principles of quantum mechanics.

I We need a way to force qubits to be used exactly oncewhen passed to functions.

Page 140: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

A Naïve Attempt

I This approach has some fundamental problems,however.

I Take the term (λx.CNOT〈x, x〉)new and suppose, as in theprevious example, to reduce it in CBV:

[∅, (λx.CNOT〈x, x〉)(newp0q)]

→ [|r → 0〉, (λx.CNOT〈x, x〉)r]→ [|r → 0〉,CNOT〈r, r〉]

I Qubits can be freely duplicated or erased!I And this goes against the principles of quantum mechanics.

I We need a way to force qubits to be used exactly oncewhen passed to functions.

Page 141: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

A Naïve Attempt

I This approach has some fundamental problems,however.

I Take the term (λx.CNOT〈x, x〉)new and suppose, as in theprevious example, to reduce it in CBV:

[∅, (λx.CNOT〈x, x〉)(newp0q)]

→ [|r → 0〉, (λx.CNOT〈x, x〉)r]→ [|r → 0〉,CNOT〈r, r〉]

I Qubits can be freely duplicated or erased!I And this goes against the principles of quantum mechanics.

I We need a way to force qubits to be used exactly oncewhen passed to functions.

Page 142: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

A Naïve Attempt

I This approach has some fundamental problems,however.

I Take the term (λx.CNOT〈x, x〉)new and suppose, as in theprevious example, to reduce it in CBV:

[∅, (λx.CNOT〈x, x〉)(newp0q)]

→ [|r → 0〉, (λx.CNOT〈x, x〉)r]→ [|r → 0〉,CNOT〈r, r〉]

I Qubits can be freely duplicated or erased!I And this goes against the principles of quantum mechanics.

I We need a way to force qubits to be used exactly oncewhen passed to functions.

Page 143: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Linearity and the λ-CalculusI First of all, let us impose that in any abstraction λx.M , the

variable x occurs exactly once in M .I Copying and erasure not possible, anymore.I But the calculus loses much of its expressive power.

I The idea is to refine the calculus in such a way as toreintroduce erasure and copying, but in a controlled way.

I We mark as !M all those subterms which can be(potentially) copied or erased;

I Besides the usual linear abstraction λx.M , there is anon-linear abstraction λ!x.M .

I 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 notcontain any quantum variable.

Page 144: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Linearity and the λ-CalculusI First of all, let us impose that in any abstraction λx.M , the

variable x occurs exactly once in M .I Copying and erasure not possible, anymore.I But the calculus loses much of its expressive power.

I The idea is to refine the calculus in such a way as toreintroduce erasure and copying, but in a controlled way.

I We mark as !M all those subterms which can be(potentially) copied or erased;

I Besides the usual linear abstraction λx.M , there is anon-linear abstraction λ!x.M .

I 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 notcontain any quantum variable.

Page 145: Introduction to Probabilistic and Quantum Programming ...dallago/BISS2014/slides-III.pdf · WhyisThisaFaithfulModelofFunctional Computation? I Data,conditionals,basicfunctions,andrecursioncanallbe

Thank You!

Questions?