SLIDE 1
Product rules and distributive laws Joost Winter University of - - PowerPoint PPT Presentation
Product rules and distributive laws Joost Winter University of - - PowerPoint PPT Presentation
Product rules and distributive laws Joost Winter University of Warsaw April 2, 2016 Overview Main goal of this paper: a categorical framework for a two-step determinization process in which product rules, such as Brzozowskis rule ( xy ) a
SLIDE 2
SLIDE 3
Distributive laws
Given:
- 1. A monad (T, ηT, µT).
- 2. Either a monad (S, ηS, µS), an endofunctor S or a copointed
endofunctor (S, ǫ).
- a. λ ◦ ηTS
= SηT
- c. λ ◦ µTS
= SµT ◦ λT ◦ Tλ
- b. λ ◦ TηS
= ηST
- d. λ ◦ TµS
= µST ◦ Sλ ◦ λS
- e. ǫT ◦ λ
= Tǫ
◮ A distributive law between monads satisfies a., b., c., and d. ◮ A distributive law of a monad over an endofunctor satisfies a.
and c.
◮ A distributive law of a monad over a copointed endofunctor
satisfies a., c., and e.
SLIDE 4
Product rules – three examples
(frequently featured in work by Rutten and many others as coinductive definitions)
◮ Brzozowski rule – convolution product:
- (1)
= 1 1a =
- (xy)
=
- (x)o(y)
(xy)a = xay + o(x)ya
◮ Leibniz rule – shuffle product:
- (1)
= 1 1a =
- (x ⊗ y)
=
- (x)o(y)
(x ⊗ y)a = xa ⊗ y + x ⊗ ya
◮ Pointwise rule – Hadamard product:
- (1)
= 1 1a = 1
- (x ⊙ y)
=
- (x)o(y)
(x ⊙ y)a = xa ⊙ ya
SLIDE 5
Deteriminizing a nondeterministic automaton, bialgebraically
X ηX ✲ Pω(X) − ✲ P(A∗) 2 × Pω(X)A (o, δ)
❄
2 × −A
✲ ✛
(ˆ
- , ˆ
δ) 2 × Pω(X ∗)A (O, ∆)
❄
Categorically well-understood (see e.g. the work by Bartels, Jacobs/Silva/Sokolova and many others) via bialgebras and distributive laws. (ˆ
- , ˆ
δ) can be obtained from (o, δ) using the distributive law.
SLIDE 6
The general picture
X ηX ✲ TX − ✲ νF FTX δ
❄
F−
✲ ✛
ˆ δ FνF ∆
❄
Given a distributive law λ : TF ⇒ FT (monad over endofunctor) the extension ˆ δ is obtained by: ˆ δ = FµX ◦ λTX ◦ Tδ The distributive law can be seen as defining a T-algebra structure
- n the final F-coalgebra.
SLIDE 7
Determinization for context-free languages (one step)
X ηX✲ Pω(X ∗) − ✲ P(A∗) 2 × Pω(X ∗)A (o, δ)
❄
2 × −A
✲ ✛
(ˆ
- , ˆ
δ) 2 × Pω(X ∗)A (O, ∆)
❄
Various variants, most involving a distributive law of a monad over a (cofree) copointed functor. See e.g. Winter/Bonsangue/Rutten, and Bonsangue/Hansen/Kurz/Rot. Can also be generalized from (context-free) languages to (constructively) algebraic power series. When we regard the distributive law as defining an algebra structure on the final coalgebra, we can see it also as defining the convolution product on power series (together with linearity of derivative). Similarly, there are laws for the shuffle and Hadamard products/product rules.
SLIDE 8
Determinization for context-free languages (two steps)
X η0
X ✲ X ∗
η1
X ∗ ✲ Pω(X ∗) − ✲ P(A∗)
2 × Pω(X ∗)A (o, δ)
❄
2 × −A
✲ ✛
(ˆ
- , ˆ
δ)
✛
(o♯, δ♯) 2 × Pω(X ∗)A (O, ∆)
❄
This can again be generalized from languages to power series. But, can we understand this diagram categorically, too?
SLIDE 9
Semimodules and algebras for a semiring
Given a semiring (S, ¯ 0, ¯ 1, ⊕, ·), a (left) S-semimodule is a tuple (X, 0, +, ×):
- 1. (X, 0, +) is a commutative monoid,
- 2. × : S × X → X (left-scalar product) satisfies:
(s ⊕ t) × x = s × x + t × x ¯ 0 × x = s × (x + y) = s × x + s × y s × 0 = s × (t × x) = (st) × x ¯ 1 × x = x Given a commutative semiring S, a (unital, associative) S-algebra (see e.g. Eilenberg 1974) is a tuple (X, 0, 1, +, ·, ×):
- 1. (X, 0, 1, +, ·) is a semiring.
- 2. (X, 0, +, ×) is a S-semimodule.
- 3. Satisfying: s × (xy) = (s × x)y = x(s × y).
SLIDE 10
. . . via distributive laws (between monads)
Recall:
- 1. Algebras for the monad −∗ are monoids.
- 2. Algebras for the monad LinS defined by
LinS(X) = {f ∈ SX | supp(f ) is finite} with the ‘expected’ (see e.g. Jacobs/Silva/Sokolova 2012) multiplication (on the left/right) are left/right S-semimodules. If S is commutative, there is a distributive law of −∗ over LinS, creating a monad structure on S− := LinS(−∗). Its algebras are the S-algebras as just defined.
SLIDE 11
. . . via distributive laws (between monads) (2)
The distributive law λ : (LinS(−))∗ ⇒ LinK(−∗) can be given by: λX
- n
- i=1
mi
- j=1
kij × xij
- =
m1
- j1=1
· · ·
mn
- jn=1
- n
- i=1
kiji ×
n
- i=1
xiji
- (see e.g. Beck ’69 for the case S = Z)
S S-semimodules S-algebras B (join) semilattices idempotent semirings N commutative monoids semirings Z Abelian groups rings
SLIDE 12
Combining distributive laws (acc. to Cheng)
Let S, T, and U be monads, and let λ0 : UT ⇒ TU, λ1 : US ⇒ SU, and λ2 : TS ⇒ ST be distributive laws.
Theorem
T.f.a.e.:
- 1. The diagram of natural transformations
UTS Uλ2
✲ UST
λ1T✲ SUT TUS λ0S
❄
Tλ1
✲ TSU
λ2U✲ STU Sλ0
❄
(the Yang Baxter diagram) commutes.
- 2. λ2U ◦ Tλ1 is a dist. law of the composite monad TU over S.
- 3. Sλ0 ◦ λ1T is a dist. law of U over the composite monad ST.
SLIDE 13
Same result for dist. laws over endofunctors
Now, let S and T be monads, and F and endofunctor... λ0 dist. law between monads, λ1 and λ2 dist. law of monad over endofunctor
Theorem
T.f.a.e.:
- 1. The diagram of natural transformations
TSF Tλ2
✲ TFS
λ1S✲ FTS STF λ0F
❄
Sλ1
✲ SFT
λ2T✲ FST Fλ0
❄
(the Yang Baxter diagram) commutes.
- 2. λ2T ◦ Sλ1 is a dist. law of the composite monad ST over F.
(also works for copointed)
SLIDE 14
Instance: the Hadamard product
We can use the framework of the previous page with the following instances (assume S to be commutative):
◮ S = LinS(−), the monad for S-semimodules ◮ T = −∗, the list monad ◮ F = S × −A, the endofunctor for Moore machines with
- utput in S.
Take λ0 : TS ⇒ ST as defined before (making ST the monad for S-algebras), make λ2 the pointwise distributive law for S-weighted automata, and define λ1 : (S × −A)∗ ⇒ (S × (−∗)A) again pointwise, as follows: λ1(ǫ) = (1S, (a → ε)) λ1((o, a → da)w) = let (p, a → ea) = λ1(w) in (op, a → daea)
SLIDE 15
How about convolution and shuffle product
◮ λ1 in the previous slide can be seen as defining, coinductively,
the product rule 1a = 1, (xy)a = xaya on the final coalgebra.
◮ How about other rules, such as (xy)a = xay + o(x)ya or
(xy)a = xay + xya?
SLIDE 16
How about convolution and shuffle product
◮ λ1 in the previous slide can be seen as defining, coinductively,
the product rule 1a = 1, (xy)a = xaya on the final coalgebra.
◮ How about other rules, such as (xy)a = xay + o(x)ya or
(xy)a = xay + xya?
◮ Because of the presence of addition on the right hand side of
the equations, it seems this will not work, and we need a law
- f the type
λ : TF ⇒ FST
SLIDE 17
Distributive laws into a composite monad
Given:
- 1. A monad (T, ηT, µT), a monad (S, ηS, µS), a distributive law
between monads λ0 : TS ⇒ ST, and an endofunctor F, A natural transformation λ : TF ⇒ FST is a distributive law of T
- ver F into the composite monad ST whenever:
λ ◦ ηTF = FηST λ ◦ µTF = FµST ◦ λST ◦ Tλ If (F, ǫ) is a copointed endofunctor, additionally: ǫST ◦ λ = ηS ◦ Tǫ
SLIDE 18
The other two product rules
Brzozowski/convolution rule: λX(1) = (1, 1, a → 0) λX(x, o, a → da)w = let (y, p, a → ea) = λX(w) in (xy, op, a → day + oea) Leibniz/shuffle rule: λX(1) = (1, 1, a → 0) λX(x, o, a → da)w = let (y, p, a → ea) = λX(w) in (xy, op, a → day + xea)
SLIDE 19
Another coherence condition (1)
TSF Tλ2
✲ TFS
λ1S
✲ FSTS FSλ0 ✲ FSST
STF λ0F
❄
Sλ1
✲ SFST λ2ST ✲ FSST FµST✲ FST
FµST
❄
Theorem
Given monads (T, ηT, µT) and (S, ηS, µS), and an endofunctor F such that:
◮ λ0 is a distributive law of the monad T over the monad S. ◮ λ1 is a distributive law of the monad T over the endofunctor
F into the composite monad ST. . .
◮ λ2 is a distributive law of the monad S over the endofunctor
F.
SLIDE 20
Another coherence condition (1)
TSF Tλ2
✲ TFS
λ1S
✲ FSTS FSλ0 ✲ FSST
STF λ0F
❄
Sλ1
✲ SFST λ2ST ✲ FSST FµST✲ FST
FµST
❄
Theorem
. . . ˆ λ : STF → FST, given by STF Sλ1
✲ SFST λ2ST ✲ FSST FµST ✲ FST
is a distributive law of the composite monad ST over F iff the coherence condition holds. (again works for copointed)
SLIDE 21
Two-step determinization: general
X ηT
X ✲ TX
ηS
TX✲ STX
− ✲ νF FSTX δ
❄
F−
✲ ✛
ˆ δ
✛
δ
♯
FνF ∆
❄
δ♯ and ˆ δ can now be expressed in terms of the various distributive laws and δ: δ♯ = FµST
X
- λ1
STX ◦ Tδ
ˆ δ = FµS
TX ◦ λ2 STX ◦ Sδ♯
δ♯ can also be obtained, equivalently, in terms of the distributive law ˆ λ of ST over F.
SLIDE 22