Presentation is loading. Please wait.

Presentation is loading. Please wait.

Weighted Automata and Concurrency Akash Lal Microsoft Research, India Tayssir Touili, Nicholas Kidd and Tom Reps ACTS II, Chennai Mathematical Institute.

Similar presentations


Presentation on theme: "Weighted Automata and Concurrency Akash Lal Microsoft Research, India Tayssir Touili, Nicholas Kidd and Tom Reps ACTS II, Chennai Mathematical Institute."— Presentation transcript:

1 Weighted Automata and Concurrency Akash Lal Microsoft Research, India Tayssir Touili, Nicholas Kidd and Tom Reps ACTS II, Chennai Mathematical Institute

2 Weighted Automata 2 A finite-state machine with weights A normal FSM: word  Bool Weighted Automata: word  Weight a b c a b c w1w1 w2w2 w3w3 w 1 ⨂ w 2 ⨂ w 3

3 Outline Define weights and weighted automata Intersecting weighted automata Application –Generalizes to composition of weighted transducers –Context-Bounded Analysis: Interprocedural dataflow analysis of concurrent programs, under a bound on the number of context switches 3 Earlier talks

4 What are Weights? Weights == Dataflow transformers –Technically, they are elements of a semiring SemiringDataflow AnalysisFinite domains D : set of weights DataFacts  DataFacts V x V ⨂ : extend D x D  D Compose (extends paths)  1 ⨂  2 =  2 ∘  1 Relational composition ⨁ : combine D x D  D Meet (combines paths)  1 ⨁  2 = d.  1 (d) ⊓  2 (d) Union 0 : zeroInfeasible path  ⨁ 0 = ,  ⨂ 0 = 0 Empty set 1 : oneIdentity  ⨂ 1 =  Identity relation w1w1 w2w2 w3w3 (w 1 ⨂ w 2 ⨂ w 3 )  (w 4 ⨂ w 5 ) w4w4 w5w5

5 Weighted Automata 5 Note: extend need not be commutative

6 Weighted Automata Weighted automaton: Transitions have weights –A: Word  D Computing A(s) Examples of what A(s) means. 6

7 Weighted Automata A: word  D A(s) = combine of weights of all accepting paths for s A(s) = ⨁ { v() | is an accepting path for s } A(abc) = (w 1 ⨂ w 2 ⨂ w 3 ) ⨁ (w 4 ⨂ w 5 ⨂ w 6 ) a b c w1w1 w2w2 w3w3 a b c w4w4 w5w5 w6w6

8 Weighted Automata A(s) = ⨁ { v() | is an accepting path for s } AA(s) (Bool, ⨂ is conj, ⨁ is disj) “true” on all edges True iff s is accepted (Nat, ⨂ is plus, ⨁ is min) “1” on all edges Length of shortest accepting path (Distributive) Dataflow AnalysisMeet-Over-All-(accepting)-Paths A(T) = ⨁ { v() | is an accepting path for s ∊ T } ⨁ { A(s) | s ∊ T }

9 Weighted Automata Computing A(T) 9 A(ab*c) = (w 1. w 2 *. w 3 ) x. y = x ⨂ y x* = ( ⨁ i x i ) (x | y) = x ⨁ y A(ab*c) = (w 1. w 2 *. w 3 ) x. y = x ⨂ y x* = ( ⨁ i x i ) (x | y) = x ⨁ y Weight domain properties: Distributivity: x ⨂ (y ⨁ z) = (x ⨂ y) ⨁ (x ⨂ z) Boundedness: All iterations x* converge Weight domain properties: Distributivity: x ⨂ (y ⨁ z) = (x ⨂ y) ⨁ (x ⨂ z) Boundedness: All iterations x* converge A(ab*c) = ⨁ i { w 1 ⨂ w 2 i ⨂ w 3 } = w 1 ⨂ ( ⨁ i w 2 i ) ⨂ w 3 a b c w1w1 w2w2 w3w3

10 Weighted Automata Computing A(T) 10 a b c w1w1 w2w2 w3w3 All iterations x* converge A(ab*c) = (w 1. w 2 *. w 3 ) x. y = x ⨂ y x* = ( ⨁ i x i ) (x | y) = x ⨁ y A(ab*c) = (w 1. w 2 *. w 3 ) x. y = x ⨂ y x* = ( ⨁ i x i ) (x | y) = x ⨁ y

11 Weighted Automata Intersection Given A 1 and A 2, construct A 3 such that for all s, A 3 (s) = A 1 (s) ⨂ A 2 (s) If weight domain is (Bool, ⨂ is conj, ⨁ is disj) then –A 3 = (A 1 ⋂ A 2 ) 11

12 Weighted Automata Intersection A 3 (s) = A 1 (s) ⨂ A 2 (s) 12 a b c A 3 (T) = ⨁ { A 3 (s) | s ∊ T } = ⨁ { A 1 (s) ⨂ A 2 (s) | s ∊ T } ac b c ε ǂ A 1 (T) ⨂ A 2 (T) Given a regular set T, { (s s) | s ∊ T } is not regular

13 Weighted Automata Intersection ∀ s, A 3 (s) = A 1 (s) ⨂ A 2 (s) 13 A 3 (abc) = (w 1 ⨂ w 2 ⨂ w 3 ⨂ u 1 ⨂ u 2 ⨂ u 3 ) a b c [w 1,u 1 ] [w 2,u 2 ] [w 3,u 3 ] ac w1w1 w2w2 w3w3 a b c u1u1 u2u2 u3u3 b

14 Weighted Automata Intersection ∀ s, A 3 (s) = A 1 (s) ⨂ A 2 (s) 14 a b c w 1 ⨂ u 1 w 2 ⨂ u 2 w 3 ⨂ u 3 (w 1 ⨂ u 1 ⨂ w 2 ⨂ u 2 ⨂ w 3 ⨂ u 3 ) ac w1w1 w2w2 w3w3 a b c u1u1 u2u2 u3u3 b A 3 (abc) = (w 1 ⨂ w 2 ⨂ w 3 ⨂ u 1 ⨂ u 2 ⨂ u 3 )

15 Tensor Product Given semiring (D, ⨂, ⨁ ), construct a new semiring (D T, ⨂, ⨁ ) to represent pairs of weights from D 15 Tensor: D x D  D T DeTensor: D T  D 1.Tensor(w 1,w 2 ) ⨂ Tensor(w 3,w 4 ) = Tensor(w 1 ⨂ w 3, w 2 ⨂ w 4 ) 2.DeTensor(Tensor(w 1,w 2 )) = w 1 ⨂ w 2 3.DeTensor(W 1 ⨁ W 2 ) = DeTensor(W 1 ) ⨁ DeTensor(W 2 ) Note that D T can be much bigger than D x D

16 Weighted Automata Intersection ⩝ s, A 3 (s) = A 1 (s) ⨂ A 2 (s) 16 a b c T(w 1,u 1 ) T(w 2,u 2 ) T(w 3,u 3 ) A 3 (abc) = (w 1 ⨂ w 2 ⨂ w 3 ⨂ u 1 ⨂ u 2 ⨂ u 3 ) ac w1w1 w2w2 w3w3 a b c u1u1 u2u2 u3u3 b

17 Weighted Automata Intersection 17 A 3 (abc) = (w 1 ⨂ w 2 ⨂ w 3 ⨂ u 1 ⨂ u 2 ⨂ u 3 ) a b c T(w 1,u 1 ) T(w 2,u 2 ) T(w 3,u 3 ) T(w 1,u 1 ) ⨂ T(w 2,u 2 ) ⨂ T(w 3,u 3 ) Tensor(w 1,w 2 ) ⨂ Tensor(w 3,w 4 ) = Tensor(w 1 ⨂ w 3, w 2 ⨂ w 4 ) DeTensor(Tensor(w 1,w 2 )) = w 1 ⨂ w 2 DeTensor (w 1 ⨂ w 2 ⨂ w 3 ⨂ u 1 ⨂ u 2 ⨂ u 3 ) = T(w 1 ⨂ w 2 ⨂ w 3, u 1 ⨂ u 2 ⨂ u 3 )

18 Weighted Automata Intersection 18 A 3 ({abc, de}) = (w 1 ⨂ w 2 ⨂ w 3 ⨂ u 1 ⨂ u 2 ⨂ u 3 ) ⨁ (w 4 ⨂ w 5 ⨂ u 4 ⨂ u 5 ) a b c T(w 1,u 1 ) T(w 2,u 2 ) T(w 3,u 3 ) T(w 1,u 1 ) ⨂ T(w 2,u 2 ) ⨂ T(w 3,u 3 ) ⨁ T(w 4,u 4 ) ⨂ T(w 5,u 5 ) Tensor(w 1,w 2 ) ⨂ Tensor(w 3,w 4 ) = Tensor(w 1 ⨂ w 3, w 2 ⨂ w 4 ) DeTensor(Tensor(w 1,w 2 )) = w 1 ⨂ w 2 DeTensor(W 1  W 2 ) = DeTensor(W 1 ) ⨁ DeTensor(W 2 ) DeTensor (w 1 ⨂ w 2 ⨂ w 3 ⨂ u 1 ⨂ u 2 ⨂ u 3 ) ⨁ (w 4 ⨂ w 5 ⨂ u 4 ⨂ u 5 ) T(w 4,u 4 )T(w 5,u 5 ) d e = T(w 1 ⨂ w 2 ⨂ w 3, u 1 ⨂ u 2 ⨂ u 3 ) ⨁ T(w 4 ⨂ w 5, u 4 ⨂ u 5 )

19 Weighted Automata Intersection 19 DeTensor(  { A 3 (s) | s  T } ) =  { DeTensor( A 3 (s) ) | s  T } =  { DeTensor(Tensor(A 1 (s),A 2 (s)) ) | s  T } =  {A 1 (s) ⨂ A 2 (s) | s  T } Theorem: For any set of words T, DeTensor(A 3 (T)) = ⨁ {A 1 (s) ⨂ A 2 (s) | s ∊ T }

20 Tensors Tensors are good, but do they exist? –Yes! If (D, ⨂ ) is commutative: –Then D T = D, Tensor(w 1,w 2 ) = w 1 ⨂ w 2, DeTensor is identity If D is the set of matrices over a commutative domain –Extend is matrix multiplication, combine is point-wise –Tensor is Kronecker product 20

21 Tensors Kronecker product 21 a1a1 a2a2 a3a3 a4a4 a1b1a1b1 a1b2a1b2 a2b1a2b1 a2b2a2b2 a1b3a1b3 a1b4a1b4 a2b3a2b3 a2b4a2b4 a3b1a3b1 a3b2a3b2 a4b1a4b1 a4b2a4b2 a3b3a3b3 a3b4a3b4 a4b3a4b3 a4b4a4b4 ⨀= b1b1 b2b2 b3b3 b4b4 a 1 b 1 + a 2 b 3 a 1 b 2 + a 2 b 4 a 3 b 1 + a 4 b 3 a 3 b 2 + a 4 b 4 DeTensor

22 Tensors D is the set of matrices over a commutative domain –Finite relations (matrices over Booleans) –Affine relations (matrices over integers) Q: Does tensor product exist for all (bounded idempotent) semirings? 22

23 Part II: Context-Bounded Analysis

24 Tensors and Concurrency 24 T(w 1, w 2, w 3 )T(w 4, w 5, w 6 ) ⨂ T(w 1 ⨂ w 4, w 2 ⨂ w 5, w 3 ⨂ w 6 )  w 1 ⨂ w 4 ⨂ w 2 ⨂ w 5 ⨂ w 3 ⨂ w 6 w1w1 w2w2 w3w3 w4w4 w5w5 w6w6 T(w 1, 1, 1) T(1, w 2, 1) T(1, 1, w 3 ) T(w 4, 1, 1) T(1, w 5, 1) T(1, 1, w 6 ) Automata are required to do this for all paths in the program Tensors give the necessary shuffling for interleaved executions Thread 1Thread 2 Context bound is determined by the arity of tensor operation

25 Application: Context-Bounded Analysis Context Bounded Analysis: interprocedural analysis of concurrent programs under a bound the number of context switches Weighted Pushdown System: A PDS with weights on rules. –Natural model for recursive programs Theorem: If all threads are modeled using WPDSs, and the weight domain has a tensor product, then for any bound K, one can precisely compute MOP. –Can solve reachability previsely –Can solve dataflow analysis precisely 25

26 What it Means … 26 (Recursive) Concurrent Program (Recursive) Concurrent Program Predicate abstraction Linear equalities Shortest path Finite relational abstraction IFDS Their combinations Others … Predicate abstraction Linear equalities Shortest path Finite relational abstraction IFDS Their combinations Others … Library of Abstractions Abstract Model WPDS Context Bound Precise answer!

27 Context-bounded analysis Abstract model 27 Shared Memory G Shared Memory G T1L1T1L1 T1L1T1L1 T2L2T2L2 T2L2T2L2 TnLnTnLn TnLnTnLn G x L 1 x L 2 x … x L n

28 Context-bounded analysis Transition Systems Transition system for an execution context (g,l i )  Ti (g’,l i ’) ⇒ c equals ⇒ T1 * ⋃ ⇒ T2 * ⋃ … ⋃ ⇒ Tn * 28 TiTi TiTi (g,l 1,…, l i,…, l n ) ⇒ Ti (g’,l 1,…,l i ’,…,l n ) Shared Memory T1T1 T1T1 TiTi TiTi TnTn TnTn

29 Context-bounded analysis Want to check reachability in the transition system: ⇒ c ⇒ c ⇒ c … ⇒ c ⇒ c k+1 times 29

30 Thread Summarization In interprocedural analysis –Procedure re-analyzed for each input –Instead, one can build a summary We create a summary of an entire thread –Mapping starting states (input) to reachable states (output) Transducers: FSMs with an input and a output tape 30

31 Thread Summarization Reachability in a PDS can be modeled using a transducer [Caucal ‘92] Advantage: transducers can be composed (g 1,l 1 )  T * (g 2,l 2 ) iff ((g 1,l 1 ), (g 2,l 2 ))  L(  ) (r 1,r 2 )  L(  1 ) and (r 2,r 3 )  L(  2 ) then (r 1,r 3 )  L(  1 ;  2 ) 31 r 1 : [glob,stack] r 2 : [glob,stack]  

32 Thread Summarization 32 For:Construct: (g,l i )  Ti * (g ’,l i ’ ) ii (g, l 1,…, l i,…, l n ) ⇒ Ti * (g ’,l 1,…,l i ’,…,l n ) ieie ⇒ c equals ⇒ T1 * ⋃ … ⋃ ⇒ Tn *  c =  1 e ⋃  2 e ⋃ … ⋃  n e ⇒ c … ⇒ c ⇒ c  c ; … ;  c ;  c

33 Thread Summarization Context-bounded analysis reduces into a membership query on a transducer We’ll extend these results to Weighted PDSs –Constructing weighted transducers –Composing weighted transducers Weighted Transducer: Given an input word s 1, the transducer can write s 2 with a weight w (combine over all paths that write s 2 ) –(s 1,s 2 ) = w 33

34 Thread Summarization 34 For:Construct: (g,l i )  Ti * (g ’,l i ’ )  i [TACAS’08] (g,l 1,…, l i,…, l n ) ⇒ Ti * (g ’,l 1,…,l i ’,…,l n ) ieie ⇒ c equals ⇒ T1 * ⋃ … ⋃ ⇒ Tn *  c =  1 e ⋃  2 e ⋃ … ⋃  n e ⇒ c … ⇒ c ⇒ c  c ; … ;  c ;  c

35 How Thread Summarization Works 35 For a single thread: –  i (s 1,s 2 ) = Reachable(s 1,s 2 ) –  i (s 1,s 2 ) = MOP(s 1,s 2 ) Definition of composition –  3 (s 1,s 2 ) =  s {  1 (s 1,s)   2 (s,s 2 ) } –  3 (s 1,s 2 ) =  s {  1 (s 1,s) ⨂  2 (s,s 2 ) } Consider the path: –(g 1,l 1,l 2 )  T1 * (g 2,l 1 ’,l 2 )  T2 * (g 3,l 1 ’,l 2 ’ ) s1s1 s2s2 s  1 (s 1,s)  2 (s, s 2 ) ⨂ ss MOP (s 1,s 2 ) =  3 (s 1,s 2 )

36 Composing Transducers 36 a/c 1 w 1 b/d 1 w 2 c 1 /e w 3 d 1 /f w 4 ab  ef w 1 ⨂ w 2 ⨂ w 3 ⨂ w 4  3 (s 1,s 2 ) =  s {  1 (s 1,s) ⨂  2 (s,s 2 ) } ab  c 1 d 1 w 1 ⨂ w 2 c 1 d 1  ef w 3 ⨂ w 4 a/c 2 w 5 b/d 2 w 6 c 2 /e w 7 d 2 /f w 8 ab  c 2 d 2 w 5 ⨂ w 6 c 2 d 2  ef w 7 ⨂ w 8  w 5 ⨂ w 6 ⨂ w 7 ⨂ w 8

37 Composing Transducers 37 a/c 1 w 1 b/d 1 w 2 c 1 /e w 3 d 1 /f w 4  3 (s 1,s 2 ) =  s {  1 (s 1,s) ⨂  2 (s,s 2 ) } a/c 2 w 5 b/d 2 w 6 c 2 /e w 7 d 2 /f w 8 a/e [w 1,w 3 ] b/f [w 2,w 4 ] a/e [w 5,w 7 ] b/f [w 6,w 8 ]

38 Composing Transducers 38  3 (s 1,s 2 ) =  s {  1 (s 1,s) ⨂  2 (s,s 2 ) } a/e T(w 1,w 3 ) b/f T(w 2,w 4 ) a/e T(w 5,w 7 ) b/f T(w 6,w 8 ) T(w 1 ⨂ w 2, w 3 ⨂ w 4 ) DeTensor w 1 ⨂ w 2 ⨂ w 3 ⨂ w 4  T(w 5 ⨂ w 6, w 7 ⨂ w 8 )  w 5 ⨂ w 6 ⨂ w 7 ⨂ w 8

39 Summary 39 We gave an algorithm for intersecting weighted automata –Extend need not be commutative –Requires tensor product for “shuffling” Generalizes to transducer composition Solves Context-Bounded Analysis

40 Comparison with Previous Work 40 QR’05This result [TACAS’08] Data AbstractionFinite Infinite Model of a threadPDS Weighted-PDS Basic resultBuchi’64Caucal’92New Representation of sets of statesAutomataTransducers Weighted Transducers Buchi: Reachable(Regular set) = Regular set Caucal: “Reachability” is itself regular: the pair (c1,c2) is in the language of a transducer iff Reachable(c1, c2)


Download ppt "Weighted Automata and Concurrency Akash Lal Microsoft Research, India Tayssir Touili, Nicholas Kidd and Tom Reps ACTS II, Chennai Mathematical Institute."

Similar presentations


Ads by Google