Upload
others
View
20
Download
0
Embed Size (px)
Citation preview
Synthesis of Mealy Machines Using Derivatives
Helle Hvid Hansen1,2 David Costa2 Jan Rutten1,2
1Section Theorectical Computer ScienceVrije Universiteit Amsterdam (VUA)
2SEN3Centrum voor Wiskunde en Informatica (CWI)
March 25, 2006 / Coalgebraic Methods in Computer Science
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 1 / 25
Introduction
Introduction
Main reference:J. Rutten, Algebraic specification and coalgebraic synthesis of Mealyautomata, FACS 2005.
Mealy machines are coalgebras.Abstract implementation via final Mealy coalgebra.Symbolic computation of derivatives.
Our contributions:Implementation (Haskell),Decision procedure for deciding equivalence of expressions,Results on rational 2-adic stream functions
automaton size,complexity.
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 2 / 25
Introduction
Outline
1 Mealy Machines and Coalgebras
2 Synthesis Using Derivatives (I)Main Idea
3 Arithmetic Bitstream Specifications2-Adic Bitstream AlgebraMod-2 Bitstream Algebra
4 Synthesis Using Derivatives (II)Deciding Equivalence
5 Rational 2-Adic Functions
6 Mealy Synthesis Tool (incl. Demo)
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 3 / 25
Mealy Machines and Coalgebras Structures and Morphisms
Mealy Machines
Finite State Machine (FSM): states, I/O-transitions:
sa|b // t
In state s, reading input a, the machine produces an output b, andmoves to a new state t .Example:
b|b
a|a
b|aa|b
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 4 / 25
Mealy Machines and Coalgebras Structures and Morphisms
Mealy Coalgebras
Mealy coalgebra (input in A, output in B):Set-functor M(X ) = (B × X )A
δ : S −→ (B × S)A
s 7→ (os, ds)
o : S × A → B is the output function,d : S × A → Q is the next-state function.Mealy homomorphism h : (S, δ) → (U, ρ):
for all s, t ∈ S : sa|b // t iff h(s)
a|b // h(t) .
Mealy machine (S, δ, s0) = (finite) Mealy coalgebra + initial state.
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 5 / 25
Mealy Machines and Coalgebras Behaviour and Finality
Causal Behaviour
..., b, b, a ..., a, b, ba|b b|a
a|a
b|b
Behaviour of (S, δ, s0): deterministic transformation of inputstream to output stream (transducer).Behaviour of a state s0 in (S, δ): Beh(s0) : Aω → Bω.For σ = (a0, a1, a2, . . .) ∈ Aω, Beh(s0)(σ) = (b0, b1, b2, . . .) ∈ Bω
where
s0a0|b0 // s1
a1|b1 // . . .ak−1|bk−1// sk
ak |bk // sk+1 . . .
Beh(s0) : Aω → Bω is causal (bn depends only on a0, . . . , an).
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 6 / 25
Mealy Machines and Coalgebras Behaviour and Finality
Final Mealy Coalgebra
Let Γ = {f : Aω → Bω | f causal }.
Theorem[Rutten]: Γ carries a final Mealy coalgebra structure.
For f ∈ Γ define π(f ) = 〈of , df 〉 : A → B × Γ asinitial output of f (on input a):
of (a) := f [a] = f (a : σ)(0) = head f (a : σ)
(stream function) derivative of f (on input a):
df (a) := fa : Aω → Bω
σ 7→ f (a : σ)′ = tail f (a : σ)
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 7 / 25
Mealy Machines and Coalgebras Behaviour and Finality
Abstract Implementations
States s, t in (S, δ) are equivalent (s ∼ t) iff Beh(s) = Beh(t).Mealy machine (S, δ, s0) implements f : Aω → Bω iff Beh(s0) = f .
Generating Abstract Implementations
Let 〈f 〉 be the subcoalgebra generated by f in (Γ, π);i.e., f ∈ 〈f 〉 ⊆ Γ is minimal, derivative-closed.Then by finality of (Γ, π):
〈f 〉 implements f . (Because Beh(f ) = f .)〈f 〉 is a minimal-state implementation.If (S, s) implements f , then Beh[〈s〉] = 〈f 〉.
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 8 / 25
Synthesis Using Derivatives (I) Main Idea
Synthesis of Mealy Machines Using Derivatives
Basic Idea:Symbolic computation of 〈f 〉.
Specify causal stream functions algebraically (language L).Define output and derivatives of expressions (cf. Brzozowski).
L〈o,d〉 // (B × L)A.
θ ∈ L defines/specifies a function Beh(θ) = fθ : Aω → Bω.Compute representation of 〈fθ〉 as least fixpoint.
Questions:Specification language? Arithmetic bitstream algebra.Realisability: is 〈f 〉 finite? Rational bitstream functions.Equivalence: how to decide θ ∼ φ? Normal forms.
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 9 / 25
Synthesis Using Derivatives (I) Main Idea
Synthesis of Mealy Machines Using Derivatives
Basic Idea:Symbolic computation of 〈f 〉.
Specify causal stream functions algebraically (language L).Define output and derivatives of expressions (cf. Brzozowski).
L〈o,d〉 // (B × L)A.
θ ∈ L defines/specifies a function Beh(θ) = fθ : Aω → Bω.Compute representation of 〈fθ〉 as least fixpoint.
Questions:Specification language? Arithmetic bitstream algebra.Realisability: is 〈f 〉 finite? Rational bitstream functions.Equivalence: how to decide θ ∼ φ? Normal forms.
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 9 / 25
Arithmetic Bitstream Specifications
Outline
1 Mealy Machines and Coalgebras
2 Synthesis Using Derivatives (I)Main Idea
3 Arithmetic Bitstream Specifications2-Adic Bitstream AlgebraMod-2 Bitstream Algebra
4 Synthesis Using Derivatives (II)Deciding Equivalence
5 Rational 2-Adic Functions
6 Mealy Synthesis Tool (incl. Demo)
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 10 / 25
Arithmetic Bitstream Specifications
Arithmetic Bitstream Specifications
Semantic Domain:Bitstreams 2ω (i.e. A = B = 2 = {0, 1}),Bitstream functions f : 2ω → 2ω.
Arithmetic Bitstream Expressions:
Constants [0] = (0, 0, 0, 0, . . .),[1] = (1, 0, 0, 0, . . .),X = (0, 1, 0, 0, . . .),X n = (0, . . . , 0︸ ︷︷ ︸
n times
, 1, 0, 0, . . .);
Bitstream variable σ;Arithmetic operations: addition, multiplication, minus, division.
2-Adic: infinitary binary arithmetic.Mod-2: infinitary modulo-2 arithmetic.
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 11 / 25
Arithmetic Bitstream Specifications
Stream Behaviour of Expressions
Mimic semantics:
Recall in final Mealy coalgebra: of (a) = f (a : σ)(0)df (a) = f (a : σ)′
– Instantiating σ with bit a ∈ 2 (later),– Stream behaviour (head, tail).
Stream behaviour of constants:
initial value(head) derivative(tail)[0](0) = 0 [0]′ = [0][1](0) = 1 [1]′ = [0]X (0) = 0 X ′ = [1]
X n(0) = 0 (X n)′ = X n−1 , n ≥ 1, (X 0 = [1])
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 12 / 25
Arithmetic Bitstream Specifications
Stream Behaviour of Expressions
Mimic semantics:
Recall in final Mealy coalgebra: of (a) = f (a : σ)(0)df (a) = f (a : σ)′
– Instantiating σ with bit a ∈ 2 (later),– Stream behaviour (head, tail).
Stream behaviour of constants:
initial value(head) derivative(tail)[0](0) = 0 [0]′ = [0][1](0) = 1 [1]′ = [0]X (0) = 0 X ′ = [1]
X n(0) = 0 (X n)′ = X n−1 , n ≥ 1, (X 0 = [1])
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 12 / 25
Arithmetic Bitstream Specifications 2-Adic Bitstream Algebra
2-Adic Bitstream Algebra
2ω as the 2-adic integers:
(a0, a1, a2, . . .) ∈ 2ω ! a0 + a12 + a222 + a323 + . . . = Σ∞i=0ai2i .
2-adic operations (signature Σ2adic = {+,×,−, /}):infinitary binary addition (carry-bits propagate indefinitely):
E.g. (1, 0, 0, . . .)+(1, 1, 1, . . .) = (0, 0, 0, . . .).
stream differential equation:
(α + β)(0) = α(0)⊕ β(0)(α + β)′ = (α′ + β′) + [α(0) ∧ β(0)]
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 13 / 25
Arithmetic Bitstream Specifications 2-Adic Bitstream Algebra
2-Adic Bitstream Algebra
2ω as the 2-adic integers:
(a0, a1, a2, . . .) ∈ 2ω ! a0 + a12 + a222 + a323 + . . . = Σ∞i=0ai2i .
2-adic operations (signature Σ2adic = {+,×,−, /}):Cauchy product:
(α×β)(n) = Σni=0α(i) ∧ β(n − i) (2-adic sum).
stream differential equation:
(α× β)(0) = α(0) ∧ β(0)(α× β)′ = α′ × β + [α(0)]× β′
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 13 / 25
Arithmetic Bitstream Specifications 2-Adic Bitstream Algebra
2-Adic Bitstream Algebra
2ω as the 2-adic integers:
(a0, a1, a2, . . .) ∈ 2ω ! a0 + a12 + a222 + a323 + . . . = Σ∞i=0ai2i .
2-adic operations (signature Σ2adic = {+,×,−, /}):infinitary two’s complement:
E.g. −(1, 0, 0, . . .) = (1, 1, 1, . . .).
stream differential equation:
(−α)(0) = α(0)(−α)′ = −(α′ + [α(0)])
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 13 / 25
Arithmetic Bitstream Specifications 2-Adic Bitstream Algebra
2-Adic Bitstream Algebra
2ω as the 2-adic integers:
(a0, a1, a2, . . .) ∈ 2ω ! a0 + a12 + a222 + a323 + . . . = Σ∞i=0ai2i .
2-adic operations (signature Σ2adic = {+,×,−, /}):multiplicative inverse: β × (1/β) = [1] (well-def’d if β(0) = 1).division:
α/β = α× (1/β)
stream differential equation:
(α/β)(0) = α(0)(α/β)′ = (α′ − [α(0)]× β′)/β
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 13 / 25
Arithmetic Bitstream Specifications 2-Adic Bitstream Algebra
2-Adic Bitstream Algebra
2ω as the 2-adic integers:
(a0, a1, a2, . . .) ∈ 2ω ! a0 + a12 + a222 + a323 + . . . = Σ∞i=0ai2i .
2-adic operations (signature Σ2adic = {+,×,−, /}):(2ω,+,×,−, /, [0], [1]) is integral domain,(i.e. commutative ring with no zero divisors).Since X = (0, 1, 0, 0, . . .)! 2, we have for α ∈ 2ω:
α + α ∼ X × α,X n + X n ∼ X n+1.
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 13 / 25
Arithmetic Bitstream Specifications Mod-2 Bitstream Algebra
Mod-2 Bitstream Algebra
2ω as formal power series over Mod2-ring (2,⊕,∧, id , 0, 1):
(a0, a1, a2, . . .) ∈ 2ω ! Σ∞n=0anxn
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 14 / 25
Arithmetic Bitstream Specifications Mod-2 Bitstream Algebra
Mod-2 Bitstream Algebra
2ω as formal power series over Mod2-ring (2,⊕,∧, id , 0, 1):
(a0, a1, a2, . . .) ∈ 2ω ! Σ∞n=0anxn
Mod-2 operations (signature Σmod2 = {⊕,⊗,,�}):bitwise mod-2 sum: (α⊕ β)(n) = α(n)⊕ β(n),cauchy product w.r.t. mod-2 sum.minus = id: α = α (since α⊕ α = (0, 0, 0, . . .)),multiplicative inverse: 1� α
fraction: α� β = α⊗ (1� β) (well-def’d when α(0) = 1).
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 14 / 25
Arithmetic Bitstream Specifications Mod-2 Bitstream Algebra
Mod-2 Bitstream Algebra
2ω as formal power series over Mod2-ring (2,⊕,∧, id , 0, 1):
(a0, a1, a2, . . .) ∈ 2ω ! Σ∞n=0anxn
Mod-2 operations (signature Σmod2 = {⊕,⊗,,�}):(2ω,⊕,⊗,,�, [0], [1]) is integral domain in whichα⊕ α ∼ [0] (nilpotent).operations definable using stream differential equations.
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 14 / 25
Synthesis Using Derivatives (II)
Outline
1 Mealy Machines and Coalgebras
2 Synthesis Using Derivatives (I)Main Idea
3 Arithmetic Bitstream Specifications2-Adic Bitstream AlgebraMod-2 Bitstream Algebra
4 Synthesis Using Derivatives (II)Deciding Equivalence
5 Rational 2-Adic Functions
6 Mealy Synthesis Tool (incl. Demo)
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 15 / 25
Synthesis Using Derivatives (II)
Compute output and derivative on input a ∈ 2:
Instantiating with bit a ∈ 2:
Recall in final Mealy coalgebra: of (a) = f (a : σ)(0)df (a) = f (a : σ)′
We have for all α ∈ 2ω:
0 : α = X × α = X ⊗ α1 : α = [1] + X × α = [1]⊕ X ⊗ α
For θ(σ) ∈ Σ2adic(σ):
oθ(0) = (θ[X × σ])(0) dθ(0) = (θ[X × σ])′
oθ(1) = (θ[[1] + X × σ])(0) dθ(1) = (θ[[1] + X × σ])′
Similarly, for θ ∈ Σmod2(σ).
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 16 / 25
Synthesis Using Derivatives (II) Deciding Equivalence
Deciding Equivalence of Expressions
Normal forms in integral domains:
Normal form of θ ∈ ExprΣ(σ) is NF(θ) = pq where p, q in distributive
polynomial normal form (PNF).
Reducing Constant Coefficients:2-Adic: Use numeric interpretation: signed, binary expansion. E.g.
X × ([1]− X 2) ! 2(1− 4) = −6NF (X × ([1]− X 2)) = −(X + X 2).
Mod-2: Use ring laws and nilpotency: E.g.
X ⊗ ([1] X 2)⊕ X = X X 3 ⊕ X = X 3.
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 17 / 25
Synthesis Using Derivatives (II) Deciding Equivalence
Deciding Equivalence of Expressions
Normal forms in integral domains:
Normal form of θ ∈ ExprΣ(σ) is NF(θ) = pq where p, q in distributive
polynomial normal form (PNF).
Example
θ =[1]
[1] + X+ σ + [1]
([1] + [1] + X ) + ([1] + X ) · σ[1] + X
normal form in 2-adic algebra:X 2 + ([1] + X )× σ
[1] + X
normal form in mod-2 algebra:X ⊕ ([1]⊕ X )⊗ σ
[1] + X
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 17 / 25
Synthesis Using Derivatives (II) Deciding Equivalence
Deciding Equivalence of Expressions
Equivalence in integral domains:
Given two expressions in normal form, θ1 = p1q1
and θ2 = p2q2
,
θ1 ∼ θ2 iff p1q1∼ p2
q2
iff PNF (p1 × q2) = PNF (p2 × q1)
Complexity:
computing PNF(θ) is exponential: 2O(|θ|).deciding θ ∼ φ is exponential: 2O(|θ|+|φ|).
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 18 / 25
Synthesis Using Derivatives (II) Deciding Equivalence
Synthesis Example: θ(σ) = 6×σ9
θ(σ) =(X + X 2)× σ
[1] + X 3 !6× σ
9
θ = 6σ9 = (X+X 2)×(σ)
1+X 3
θ1 = 3+6σ9 = (1+X)+(X+X 2)×(σ)
1+X 3
θ10 = −3+6σ9 = −(1+X)+(X+X 2)×(σ)
1+X 3
θ100 = −6+6σ9 = −(X+X 2)+(X+X 2)×(σ)
1+X 3
θ1001 = 6+6σ9 = (X+X 2)+(X+X 2)×(σ)
1+X 3
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 19 / 25
Rational 2-Adic Functions
Rational 2-Adic Functions
Rational 2-adic function:f (σ) =
nm× σ
where n, m are constant, polynomial (i.e. integers), m odd.Example specification:
θ(σ) =1− X 2
1− X + X 3 × σ
(−3
7× σ
)Note: In NF (θ) = p×σ
q , denominator q is constantall derivatives have denominator q,((α/β)′ = (α′ − [α(0)]× β′)/β),equivalence of derivatives in linear time,(syntactic equality of numerators).
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 20 / 25
Rational 2-Adic Functions
Rational 2-Adic Automaton Size and Complexity
Theorem:
For rational 2-adic stream function f (σ) =nm× σ,
AutSize( n
m× σ
)≤
|n|+ |m|gcd(n, m)
− 1 ifnm
> 0
|n|+ |m|gcd(n, m)
ifnm≤ 0
Conjecture (based on experiments): Upper bound is also lower bound.Corollary: A Mealy machine implementing a rational 2-adicspecification θ(σ) =
nm× σ can be constructed in time 2O(|θ|).
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 21 / 25
Mealy Synthesis Tool (incl. Demo)
Mealy Synthesis Tool (Haskell)
Input specifications θ in:2-adic arithmeticmod-2 arithmetic
Output:LaTeX-document: automaton states and transitions,DOT-file: graph representation of automaton
Source code, executable, documentation:http://www.cwi.nl/˜costa/diffcal
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 22 / 25
Mealy Synthesis Tool (incl. Demo)
Tool Demo
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 23 / 25
Summary
Related Work
Derivative ConstructionsRaney (1958): stream function derivative (semantics only).Brzozowski (1964): DFA from regex.Antimirov (1996): NFA from regex (partial derivatives).Redziejowski (1999): ω-DFA from ω-regex (related to Safra).Sakarovitch (2005): Generalises [Antimirov] to formal powerseries.
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 24 / 25
Summary
Related Work
Logic Synthesis
Buchi&Landweber (1969): S1S.Pnueli&Rosner (1989): LTL.Kupferman&Vardi (2004):
distributed synthesis from LTL and CTL specs.imperfect information.
Uses theory of automata, alternation, games:determinization,constructive non-emptiness test.
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 24 / 25
Summary
Concluding
SummaryMealy synthesis using derivatives: direct symbolic construction ofdeterministic automaton.2-Adic and Mod-2 equivalence is decidable.Synthesis for rational (2-adic) functions:– EXPTIME in size |θ| of specification θ,– Automaton size.Haskell tool available.
Future work:Extend approach to more general types of transducers andstream functions,Closer investigation of logic vs coalgebraic synthesis,Develop coinductive stream languages.
Hansen, Costa, Rutten (VUA, CWI) Synthesis of Mealy Machines... CMCS 2006 25 / 25