(Not that) Old and New Results on
Probabilistic Intersection Type Systems
Flavien BREUVART, Ugo Dal Lago
Focus, Inria team, Bologna
GdR-LL: June 12-13 2016
Randomized Programming
Motivations
Randomized Algorithmics Efficiency analysis
Cryptography Security Machine Learning
Modeling
Probabilistic
λ-calculus (Weak head-reduction)
M,N := x|λx.M|M N|M⊕N (λx.M)N 1 M[N/x]
M⊕N
M N
1 2
1 2
YA0 ∗• I
YA1 ∗•
• I
YA2 ∗• •
• I
YA3
A:=λux.x(λy.(u(Sx)⊕y)I Prob(YA0⇓)<1
1 1 2
1 2
1 1 2
1 2
1 2 1 2
1 1 2
1 2
1 1 2 2
1 2
Probability of Normalization:
A difficult problem
Problem PConv:
What is the probability pof convergence of a given programM?
PConv is
Π02-complete:
one derivation is insufficient
The following(and any variation) isimpossibleto getfrom r.e. type systems:
Prob(M⇓)=p ⇔ π
`M:p·α
Probabilistic dependency is not type dependency
Probabilistic Dependency non-uniform; randomized;
only propagate dependency Type Dependency uniform; non-deterministic;
waiting for data to propagate
Some Recursion Theory
The lower-bound problem is
Σ01-complete
Asking whether Prob(M⇓)>p is recursively enumerable.
The upper-bound problem is
Σ02-complete
Asking whether Prob(M⇓)<p is a problem of the form:
∃x∀y,φ(x,y)
The exact bound problem (PConv) is
Π02-complete
Asking whether Prob(M⇓)=p is a problem of the form:
∀x∃y,φ(x,y)
Non deterministic IT systems:
Idempotent Intersection Types
Grammar
(types) α,β := ∗ |a→α (intersections) a,b finite sets of types
(weight) p,q ∈{0, ...,1}
(context) Γ,∆ := _ | x:a,Γ (sequent) s := Γ`M:α
Weak head reduction Rule furnishing a type toλx.Ω
Γ,x:{
[
α
]
}`x:
1·
α
Γ`M:
p·
α Γ`M⊕N:
p 2·
α
Γ`N:α Γ`M⊕N:
p 2·
α Γ`λx.M:
1·
∗ Γ;x:a`M:
p·
α Γ`λx.M:
1·(
a→
p·
α
)
Γ`M:
p·(
a→
q·
β
)
nΓ
h∆α
`N:
rα·
α¯
¯
¯α∈a
i
o
Γ
+P∆α
`M N:
pq(Qiri)·
β
Non-deterministic IT systems:
Non-idempotent IT [De Carvalho]
Grammar
(types) α,β := ∗ |a→α
(intersections) a,b finite multisets of types
(weight) p,q ∈ {0, ...,1}
(context) Γ,∆ := _ | x:a,Γ (sequent) s := Γ`M:α
Multisets of intersections Multiplicities corresponding to
different uses
Γ,
x: [α]`x:
1·
α
Γ`M:
p·
α Γ`M⊕N:
p 2·
α
Γ`N:α Γ`M⊕N:
p 2·
α
Γ
`λx.M:
1·
∗ Γ;x:a`M:
p·
α Γ`λx.M:
1·(
a→
p·
α
)
Γ`M:
p·(
a→
q·
β
)
h∆α`N:
rα·
α¯
¯
¯α∈ai Γ+P∆α`M N:
pq(Qiri)·
β
Probabilistic IT systems:
Weight monad [Ehrhard et al]
Grammar
(types) α,β := ∗ |a→p·α
(intersections) a,b finite multisets of types (weight) p,q ∈ {0, ...,1}
(context) Γ,∆ := _ | x:a,Γ (sequent) s := Γ`M:p·α
Probability for the function to get
this result Sums weighted but non-deterministic
Γ,
x: [α]`x:1·α
Γ`M:p·α Γ`M⊕N:p2·α
Γ`N:α Γ`M⊕N:p2·α
Γ
`λx.M:1·∗
Γ;x:a`M:p·α Γ`λx.M:1·(a→p·α)
Γ`M:p·(a→q·β) h∆α`N:rα·α¯¯¯α∈ai Γ+P∆α`M N:pq(Qiri)·β
Probabilistic IT systems:
Weight monad [Ehrhard et al]
Grammar
(types) α,β := ∗ |a→p·α
(intersections) a,b finite multisets of types (weight) p,q ∈ {0, ...,1}
(context) Γ,∆ := _ | x:a,Γ (sequent) s := Γ`M:p·α
A derivation is an execution the weight is the probability to get this
execution
M: 1
23·α •
•
•
•
•
•
•
λx.N:1·α
•
1
1 2
1 2
1 2
1 2
1
1 2
1 2
Summing all possible executions?
The (naive) theorem
Prob(M⇓) = Xhp¯¯¯ π
`M:p·α i
Not summing too much
Issue:
`λx.x:1·∗
x: [α]`x:1·α
`λx.x:1·([α]→1·α)
Solution:
Ph
p¯¯¯ π
`M:p·∗
i
Summing all of them
Issue:
M: [α,α]→∗
N1:1·α N1⊕N2:12α
N2:1·α N1⊕N2:12α M (N1⊕N2) :14·∗
Solution:
Use keyed-multisets
Theorem and implications
The theorem
Prob(M⇓) = XW(M) whereW(M)=hp¯¯¯ π
`M:p·∗
i
Lower-bound problem (
Σ01)
Prob. of conv. ofM >q iff
∃P⊆f W(M), X p∈P
p>q
Upper-bound problem (
Σ02)
Prob. of conv. ofM <q iff
∃q0,∀P⊆fW(M), X p∈P
p <q0 < q
The exact bound problem is
Π02Sketching the proof
Cut Elimination
π
`M:p·∗
π0
`M0:pq·∗
such that:
•
M→q M0,•
is normalizing and deterministicSmall-step distrib.
ΛR ΠR
Λ Π
deriv.
deriv.
red red
Value determinism
∀normal formV, Unicity of derivation
`V:1·∗
`λx.M:1·∗
Big-step distribution
Λ Π
Λv ΠV
deriv.
deriv.
eval eval
Conclusion
X
V
P(M→V)=XW(M)
Toward distributions of derivations
Unsatisfactory completeness
Uninformative derivations Each derivation carries the
information regarding onepossible execution.
Quantifying over ALL derivations Distinguishing derivations and looking for new one is not really
computationally-friendly.
A monad of probabilistic distributions over types
(types) α,β := ∗ |a→τ
(intersections) a,b finite multisets of types (monadic distributions) ρ,τ finite distribution over types
A comonad of probabilistic distributions over intersections
(types) α,β := ∗ |A→p·α
(intersections) a,b finite multisets of types
(comonadic distributions) A,B finite distribution over intersections
Toward distributions of derivations
Unsatisfactory completeness
Uninformative derivations Each derivation carries the
information regarding onepossible execution.
Quantifying over ALL derivations Distinguishing derivations and looking for new one is not really
computationally-friendly.
A monad of probabilistic distributions over types
(types) α,β := ∗ |a→τ
(intersections) a,b finite multisets of types (monadic distributions) ρ,τ finite distribution over types
A comonad of probabilistic distributions over intersections
(types) α,β := ∗ |A→p·α
(intersections) a,b finite multisets of types
(comonadic distributions) A,B finite distribution over intersections
An unavoidable issue:
Probabilistic dependency
x : 1 2 []
+1
2 [
β]
`c
α⊕x : 1 2
α+1 2
β`λ
x
.c
α⊕x :
n1 2 []
+1
2 [
β]
o→n1 2
α+1 2
βo
`
c
β⊕Ω: 1 2
β`
(
λx
.c
α⊕x ) (c
β⊕Ω) : 1 2
α+1 4
βNo such a rule
No reasonable and systematic rule can perform this step.
Forgotten dependency
An unavoidable issue:
Probabilistic dependency
x : 1 2 []
+1
2 [
β]
`c
α⊕x : 1 2
α+1 2
β`λ
x
.c
α⊕x :
n1 2 []
+1
2 [
β]
o→n1 2
α+1 2
βo
`
c
β⊕Ω: 1 2
β`
(
λx
.c
α⊕x ) (c
β⊕Ω) : 1 2
α+1 4
βNo such a rule
No reasonable and systematic rule can perform this step.
Forgotten dependency
An unavoidable issue:
Probabilistic dependency
x : 1 2 []
+1
2 [
β]
`c
α⊕x : 1 2
α+1 2
β`λ
x
.c
α⊕x :
n1 2 []
+1
2 [
β]
o→n1 2
α+1 2
βo
`
c
β⊕Ω: 1 2
β`
(
λx
.c
α⊕x ) (c
β⊕Ω) : 1 2
α+1 4
βNo such a rule
No reasonable and systematic rule can perform this step.
Forgotten dependency
An unavoidable issue:
Probabilistic dependency
x : 1 2 []
+1
2 [
β]
`c
α⊕x : 1 2
α+1 2
β`λ
x
.c
α⊕x :
n1 2 []
+1
2 [
β]
o→n1 2
α+1 2
βo
`
c
β⊕Ω: 1 2
β`
(
λx
.c
α⊕x ) (c
β⊕Ω) : 1 2
α+1 4
βNo such a rule
No reasonable and systematic rule can perform this step.
Forgotten dependency
Distributions over sequents
Grammar
(types) α,β := ∗ |a→α
(intersections) a,b finite multisets of types (context) Γ,∆ := _ | x:a,Γ
(logical sequent) l := Γ`α
(sequent distributions) L Distributions over logical sequents (type sequent) s := (~x,M)D
(x,x){[α]`α}
MD NE
M⊕N12D+12E M{}
M{pi·(Γi;x:ai`αi)|i≤n}
λx.M{pi·Γi`ai→αi|i≤n}+{(1−Pipi)· ∗} M©p·(Γ`[αi,1, ...,αi,mi]→β)¯¯i≤nª ∀i,j, NDi,j M NPi≤n
n(piQj≤miDi,j(∆i,j`αi,j))·(Γ+Pj∆i,j`:βi)¯¯∀(∆ij)jo
Distributions over sequents
Grammar
(types) α,β := ∗ |a→α
(intersections) a,b finite multisets of types (context) Γ,∆ := _ | x:a,Γ
(logical sequent) l := Γ`α
(sequent distributions) L Distributions over logical sequents (type sequent) s := (~x,M)D
Theorem
Prob(M⇓) = SupnD(` ∗)¯¯¯ π MD
o
Conclusion
Past
[Ehr,Pag,Tas]
A fully abstract model for Λ⊕.
Sketched intersection type
system.
Now
Refinment of the ITS.
Combinatorial and simpler proof of
completeness.
Collapsed intersection type system.
future
Fixpoint/coninductive proofs
unbounded terms:
while coin continue Σ01, cherckable or
inferenceable fragments