Coinductive Methods in Computer Science Up

advertisement
Coinductive Methods
in Computer Science
(and Beyond)
Filippo Bonchi
CNRS, Ens-Lyon
Udine 10/5/2016
Up-to Techniques
Up-to techniques are enhancements
of the coinduction proof principle
They have been introduced by Robin Milner
to prove equalities between CCS processes
The theory of up-to techniques have been deeply studied by
Davide Sangiorgi and coauthors,
in the setting of concurrency theory
Today we will see that up-to techniques
are extremely useful also in automata theory
Exercises 1
c) Prove that (RE,+0) is
a) Let (X,o,t) be a DFA and x y.
Let R be the relation computed by an idempotent monoid:
e+(f+g) (e+f)+g
Naive(x,y). Let P the partition
computed by Partition Refinement.
e+0 e
Prove that R⊆P
e+e e
b) Execute Naive on the following
D FA . H o w m a n y p a i r s a re
explored?
d) OPTIONAL
Use coinduction to
prove distributivity:
e(f+g) ef+eg
The solutions are due
for the lesson of tomorrow
tuesday 10th!!!!
Solution to Exercise 1.a
By the Kleene Fixpoint Theorem,
the Partition Refinement algorithm return a partition P
which is the greatest fixpoint of B
Since x
y, the relation R computed by Naive(x,y) is a
bisimulation,
that is a post-fixpoint of B
(see the proof of soundness of Naive).
Therefore, by the Knaster-Tarski Fixpoint Theorem,
R⊆P
Equivalence Closure
Id
R
T
S
Eqv: RelX-->RelX
eRf
e Eqv(R) f
e Eqv(R) e
e Eqv(R) f Eqv(R) g
e Eqv(R) g
e Eqv(R) f
f Eqv(R) e
Exercises 1
c) Prove that (RE,+0) is
a) Let (X,o,t) be a DFA and x y.
Let R be the relation computed by an idempotent monoid:
e+(f+g) (e+f)+g
Naive(x,y). Let P the partition
computed by Partition Refinement.
e+0 e
Prove that R⊆P
e+e e
b) Execute Naive on the following
D FA . H o w m a n y p a i r s a re
explored?
d) OPTIONAL
Use coinduction to
prove distributivity:
e(f+g) ef+eg
The solutions are due
for the lesson of tomorrow
tuesday 10th!!!!
Solution to Exercise 1.b
Solution to Exercise 1.b
Solution to Exercise 1.b
Solution to Exercise 1.b
Solution to Exercise 1.b
Solution to Exercise 1.b
Solution to Exercise 1.b
Solution to Exercise 1.b
Solution to Exercise 1.b
Solution to Exercise 1.b
Solution to Exercise 1.b
Solution to Exercise 1.b
Solution to Exercise 1.b
Solution to Exercise 1.b
Solution to Exercise 1.b
Solution to Exercise 1.b
Solution to Exercise 1.b
Solution to Exercise 1.b
Solution to Exercise 1.b
Solution to Exercise 1.b
Solution to Exercise 1.b
Solution to Exercise 1.b
Solution to Exercise 1.b
Naive explores all the pairs (x,y)
with x one of the states in the top row
and y one in the bottom: 20
Hopcroft and Karp algorithm
Hopcroft and Karp algorithm
Hopcroft and Karp algorithm
R is not a bisimulation,
but a bisimulation up-to equivalence
R ⊆B(Eqv(R))
Hopcroft and Karp algorithm
R is not a bisimulation,
but a bisimulation up-to equivalence
R ⊆B(Eqv(R))
Formally, a bisimulation up-to equivalence is a post-fix point of
B∘Eqv
tions up to
oncurrency
ty of CCS
have never
FA.
on bisimus paper, is
algorithm.
t all bisime case that
Z, but not
= [[Z]], we
e the same
context, a
o relate X
ontext can
HK(x, y)
( 1 ) R i s e m p t y ; todo i s e m p t y ;
( 2 ) i n s e r t (x, y) i n todo;
( 3 ) w h i l e todo i s n o t e m p t y d o
( 3 . 1 ) e x t r a c t (x0 , y 0 ) f r o m todo;
( 3 . 2 ) i f (x0 , y 0 ) 2 Eqv(R) t h e n c o n t i n u e ;
( 3 . 3 ) i f o(x0 ) 6= o(y 0 ) t h e n r e t u r n f alse;
( 3 . 4 ) f o r a l l a 2 A,
i n s e r t (ta (x0 ), ta (y 0 )) i n todo;
( 3 . 5 ) i n s e r t (x0 , y 0 ) i n R;
( 4 ) r e t u r n true;
Figure 1: Naive
algorithm for
the equivaSoundness
and completeness
at checking
the black-board
lence of states x and y of a DFA (S, o, t). The code of
HK(x, y) is obtained by replacing the test in step 3.2
with (x0 , y 0 ) 2 e(R).
Hopcroft and Karp algorithm
•
In the worst case, the naive algorithm explores n2 pairs
•
The Hopcroft and Karp algorithm (1971) builds a
bisimulation up-to equivalence: it visits at most n pairs. The
complexity is thus (almost) linear.
•
To handle equivalence classes Hopcroft and Karp
invented a smart data structure known as Union-Find.
That's where the "(almost)" comes from
Exercises 1
c) Prove that (RE,+0) is
a) Let (X,o,t) be a DFA and x y.
Let R be the relation computed by an idempotent monoid:
e+(f+g) (e+f)+g
Naive(x,y). Let P the partition
computed by Partition Refinement.
e+0 e
Prove that R⊆P
e+e e
b) Execute Naive on the following
D FA . H o w m a n y p a i r s a re
explored?
d) OPTIONAL
Use coinduction to
prove distributivity:
e(f+g) ef+eg
The solutions are due
for the lesson of tomorrow
tuesday 10th!!!!
Solution to Exercise 1.c
(RE,+,0) is an idempotent semiring
The proof is analogous to the one of commutativity
We only show idempotency
idempotency: e+e e
R={ (e+e,e) | e,f ∈ RE } is a bisimulation:
1. e+e↓⟺e↓
2. e+e R e
a
e↓
e+f↓
f↓
e+f↓
a
a
e→e'
f→f'
a
e+f→e'+f'
a
e'+e' R e'
Exercises 1
c) Prove that (RE,+0) is
a) Let (X,o,t) be a DFA and x y.
Let R be the relation computed by an idempotent monoid:
e+(f+g) (e+f)+g
Naive(x,y). Let P the partition
computed by Partition Refinement.
e+0 e
Prove that R⊆P
e+e e
b) Execute Naive on the following
D FA . H o w m a n y p a i r s a re
explored?
d) OPTIONAL
Use coinduction to
prove distributivity:
e(f+g) ef+eg
The solutions are due
for the lesson of tomorrow
tuesday 10th!!!!
Solution to Exercise 1.d
Distributivity: e(f+g)
ef+eg
R={ (e(f+g) ,ef+eg ) | e,f,g ∈ RE } is a bisimulation:
a
a
e→e'
f→f'
1. e(f+g)↓⟺ef+eg↓
a
ef→e'f+o(e)f'
2.
e(f+g) R ef+eg
a
a
e'(f+g)+o(e)(f'+g') R (e'f+o(e)f')+(e'g+o(e)g')
a
a
e→e'
f→f'
a
e+f→e'+f'
R is NOT a bisimulation,
but a bisimulation up to Bhv∘Ctx
Behavioural and Contextual
Closure
Bhv: RelRE-->RelRE
Bhv(R)= { (e,f) | e e' R f' f }
Ctx: RelRE-->RelRE
eRf
e Ctx(R) f
0 Ctx(R) 0
1 Ctx(R) 1
a Ctx(R) a
e Ctx(R) e' f Ctx(R) f'
e Ctx(R) e' f Ctx(R) f'
e+f Ctx(R) e'+f'
ef Ctx(R) e'f'
e Ctx(R) f
e* Ctx(R) f*
Up-to Bhv∘Ctx
R={ (e(f+g) ,ef+eg ) | e,f,g ∈ RE }
e(f+g)
R
ef+eg
a
a
e'(f+g)+o(e)(f'+g') Bhv(Ctx(R)) (e'f+o(e)f')+(e'g+o(e)g')
e'(f+g)+o(e)(f'+g') Ctx(R) (e'f+e'g)+(o(e)f'+o(e)g')
(e'f+o(e)f')+(e'g+o(e)g')
R⊆B(Bhv(Ctx(R)))
R is NOT a bisimulation,
but a bisimulation up to Bhv∘Ctx
Arden's rule
Given two regular expressions k and m, the equation
e
ke+m
has solution e=k*m, i.e., k*m
kk*m + m
Moreover:
1. k↓ k*m is the unique solution, i.e., f
2. k*m is the smallest solution, i.e., f
kf+m
kf+m
f
k*m≲f
k*m
Arden's rule
Given two regular expressions k and m, the equation
e
ke+m
has solution e=k*m, i.e., k*m
kk*m + m
Can be proved by coinduction
Moreover:
1. k↓ k*m is the unique solution, i.e., f
2. k*m is the smallest solution, i.e., f
kf+m
kf+m
f
k*m
k*m≲f
language inclusion (≲) is νB'
B':RelX-->RelX is defined as
B'(R)={(x,y) | o(x) ≤ o(y) and for all a∈A t(x)(a) R t(y)(a)}
Arden's rule
To show f
kf+m
k*m≲f
We prove that
S = { (k*m,f) | f kf+m }
is a simulation up-to
1. k*m↓
m↓
kf+m↓
f↓
f
2. k*m
a
(k'k*)m+1m'
a
k'(k*m) +m' Ctx(S) k'f+m' ≲ (k'f +o(k)f')+m'
S⊆B'(Slf(Ctx(S)))
Slf: RelRE-->RelRE
Slf(S)= { (e,f) | e ≲ e' S f' ≲ f }
f'
Proving Soundness
of up-to techniques
We need to prove that these techniques are sound
(they do NOT follow from Knaster-Tarski)
For instance up-to equivalence is sound for B but not B'
Proving soundness is rather complicated and error prone
In Milner's book there are two mistakes:
Weak Bisimulation up to weak bisimilarity
Weak Bisimulation up to equivalence
Equivalence Closure
Id
R
T
S
eRf
Eqv: RelX-->RelX
e Eqv(R) f
e Eqv(R) e
e Eqv(R) f Eqv(R) g
e Eqv(R) g
e Eqv(R) f
f Eqv(R) e
Eqv = (Id∪R∪T∪S)ω
Download