Upload
others
View
7
Download
0
Embed Size (px)
Citation preview
A Monad For Randomized Algorithms
Tyler BarkerTulane University1
Domains XIIAugust 26, 2015
1Supported by AFOSRTyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 1 / 30
Introduction
Randomized Algorithms
A randomized algorithm can be represented by a probabilistic Turingmachine.
A probabilistic Turing machine is a Turing machine that can use randomcoin flips to choose transitions.
The goal is to provide a domain-theoretic monad to use in denotationalsemantics for randomized algorithms.
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 2 / 30
Introduction
Related Work: Probabilistic Powerdomain
The probabilistic powerdomain of Jones and Plotkin gives a monad overdomains.
However, there is no Cartesian closed category of domains known to beinvariant under the probabilistic powerdomain.
Also, the probabilistic powerdomain does not share a distributive law withany of the nondeterministic powerdomains.
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 3 / 30
The Functor
Motivation for the Functor
One of most well known randomized algorithms is the Miller-Rabinprimality test.
The algorithm is in the complexity class randomized polynomial time(RP).
This means that it always runs in polynomial time and has a one-sidederror probability.
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 4 / 30
The Functor
Motivation for the Functor
To test whether a given number n is prime, a random number is chosenbetween 2 and n− 2.
Tests using modular arithmetic are performed with this number beforereturning false or probably true.
A test on a prime number will always return probably true.
A test on a composite number will sometimes return probably true.
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 5 / 30
The Functor
Motivation for the Functor
For a composite number, at most 14 of the possible random choices
between 2 and n− 2 will result in the test returning probably true.
To minimize the error probability, we can repeat the test (choosing a newrandom number) only when the test returns probably true.
Running the test m times results in an error probability of at most 14m .
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 6 / 30
The Functor
Simplified View of Miller-Rabin - One Iteration
F F F ⊥
Here F represents “composite” while ⊥ represents “probably prime”, or“not sure”.
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 7 / 30
The Functor
Simplified View of Miller-Rabin - Two Iterations
F F F
F F F ⊥
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 8 / 30
The Functor
Simplified View of Miller-Rabin - Three Iterations
F F F
F F F
F F F ⊥
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 9 / 30
The Functor
The Functor Defined
Definition
An antichain of {0, 1}∞ is a subset of words such that no two distinctwords are comparable (no word is a prefix of another word).
Definition
An antichain M is full if {0, 1}ω ⊆↑M , or equivalently, M vEM {0, 1}ω.Denote the full antichains by AC({0, 1}∞).
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 10 / 30
The Functor
The Functor Defined
For a category of domains, D, the functor of random choice, RC, isdefined on objects by
RC(D) ={(M,f) | M ∈ AC({0,1}∞), f :M →D
}where f is Scott continuous (giving M the subspace topology from theScott topology of {0, 1}∞).
For a : D → D′ and (M,f) ∈ RC(D), we define
RC(a)(M,f) = (M,a ◦ f)
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 11 / 30
The Functor
The Functor Defined
(M,f) v (N, g) iff
M vEM N
w ≤ z⇒ f(w) v g(z),∀w ∈M,z ∈N
Since the antichains are required to be full, M vEM N is equivalent toM ⊆↓N , or dually, N ⊆↑M .
Another characterization for the order on functions is∀z ∈ N, f ◦ πM (z) v g(z), where πM (z) sends z to the unique element ofM below z.
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 12 / 30
The Functor
The Functor Defined
Proposition
If D is a dcpo, then so is RC(D).
Proposition
If D is a bounded complete domain, then so is RC(D).
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 13 / 30
The Monad
The Monad
A monad can be formed exhibiting a unit, η : D → RC(D), and for anymorphism, h : D → RC(E), a Kleisli extension, h† : RC(D)→ RC(E).
The unit is defined byη(d) = (ε,χd)
where ε is the antichain only containing the empty word, with the constantfunction whose value is d.
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 14 / 30
The Monad
Motivation for the Kleisli Extension
One function of the Kleisli extension is to lift binary operations.
If we have a binary operation ∗ : D×E → F , the Kleisli extension lifts thisoperation to ∗† : RC(D)×RC(E)→ RC(F ). This is achieved by setting
∗† = (λa.RC(λb.a ∗ b))†
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 15 / 30
The Monad
Motivation for the Kleisli Extension
Suppose these are Miller-Rabin tests for two different composite numbers.
F F F ⊥ ⊥ F F F
How should the or operation be lifted?
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 16 / 30
The Monad
Motivation for the Kleisli Extension
It may seem natural to perform the two tests one after the other. Thiswould result in:
⊥ F F F ⊥ F F F ⊥ F F F ⊥ ⊥ ⊥ ⊥
The probability of error in this case is 716 .
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 17 / 30
The Monad
Motivation for the Kleisli Extension
However, this approach has two main problems.
What do we do in the infinite case?
The Kleisli extension that results in this behavior is not monotone inour order.
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 18 / 30
The Monad
Motivation for the Kleisli Extension
Instead of performing the tests one after the other, we will perform themconcurrently, feeding the result of each coin flip to both tests. This resultsin:
⊥ F F ⊥
This results in an error probability of 12 . However, this only uses two coin
flips.
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 19 / 30
The Monad
Motivation for the Kleisli Extension
Using four coin flips gives:
F F
⊥ F F F F F F ⊥
which only has an error probability of 18 .
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 20 / 30
The Monad
The Kleisli Extension Defined
Consider h : D → RC(E). To define the extension h† : RC(D)→ RC(E)on (M,f), h ◦ f(w) must be considered for each w ∈M .
π1 ◦ h ◦ f(w) gives an antichain, but the entire antichain is not used.
Instead, the Kleisli extension only considers the part of π1 ◦ h ◦ f(w) thatis on the same “branch” of the tree as w, namely ↑w ∪ ↓w.
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 21 / 30
The Monad
The Kleisli Extension Defined
• •
•
e2
e0 e1
e3
e4 e5 e6 e7
h◦f
))h◦f
//
h◦f..
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 22 / 30
The Monad
The Kleisli Extension Defined
e0 •
•
e2
e0 e1
e3
e4 e5 e6 e7
h◦f//
h◦f..
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 23 / 30
The Monad
The Kleisli Extension Defined
e0 e3
•
e2
e0 e1
e3
e4 e5 e6 e7
h◦f..
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 24 / 30
The Monad
The Kleisli Extension Defined
e0 e3 e6 e7
e2
e0 e1
e3
e4 e5 e6 e7
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 25 / 30
The Monad
The Kleisli Extension Defined
h† is defined as
π1 ◦ h†(M,f) =⋃⋃⋃
w∈M
Min(↑w∩ ↑π1 ◦ h ◦ f(w))
((π2 ◦ h†)(M,f))(z) = g(πN(z)) where (N,g) = h ◦ f ◦ πM(z)
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 26 / 30
The Monad
The Monad
Theorem
RC forms a monad in the category of bounded complete domains.
Proposition
RC shares a distributive law with the Hoare powerdomain.
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 27 / 30
The Monad
Relation to Scott’s Stochastic Lambda Calculus
Scott has added random variables to his P(N) model to form a stochasticlambda calculus.
Definition
A random variable is a function X : [0, 1]→ P(N) where{t ∈ [0, 1] | n ∈ X(t)} is Lebesgue measurable for all n in P(N).
Compare this to infinite elements in our monad, which are of the form{0, 1}ω → D.
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 28 / 30
The Monad
Relation to Scott’s Stochastic Lambda Calculus
The lambda calculus has an application operation that must be lifted tothese random variables.
Definition
Given two random variables X,Y : [0, 1]→ P(N), the application operationis defined by
X(Y)(t) = X(t)(Y(t))
This coincides with how our Kleisli extension would lift the applicationoperation.
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 29 / 30
Conclusion
Concluding Remarks
Alterations can be made to the monad to obtain distributive laws with theSmyth and Plotkin powerdomains.
We have used the monad to give a semantics for a randomized PCF.
An interpreter for rPCF has been implemented in SML along with aprogram to perform the Miller-Rabin test.
For an operational version of our monad, the monad laws andmonotonicity of the Kleisli extension have been formally proven in Isabelle.
Tyler Barker Tulane University A Monad For Randomized Algorithms Domains XII August 26, 2015 30 / 30