Weighted Automata and Concurrency Akash Lal Microsoft Research, India Microsoft Research, India Tayssir Touili, Nicholas Kidd and Tom Reps ACTS II, Chennai Mathematical Institute
Weighted Automata • A finite-state machine with weights b c a w 2 a b c w 3 w 1 ⨂ w 2 ⨂ w 3 w 1 • A normal FSM: word → Bool • Weighted Automata: word → Weight 2
Outline • Define weights and weighted automata • Intersecting weighted automata • Application arlier talks – Generalizes to composition of weighted transducers – Context-Bounded Analysis: Interprocedural – Context-Bounded Analysis: Interprocedural Ea dataflow analysis of concurrent programs, under a bound on the number of context switches 3
What are Weights? • Weights == Dataflow transformers – Technically, they are elements of a semiring Semiring Dataflow Analysis Finite domains D : set of weights DataFacts → DataFacts V x V ⨂ : extend Compose (extends paths) Relational composition τ 1 ⨂ τ 2 = τ 2 ∘ τ 1 D x D → D ⨁ : combine Meet (combines paths) Union τ 1 ⨁ τ 2 = λ d. τ 1 (d) ⊓ τ 2 (d) D x D → D 0 : zero Infeasible path Empty set w 1 w 2 w 3 (w 1 ⨂ w 2 ⨂ w 3 ) τ ⨁ 0 = τ , τ ⨂ 0 = 0 ⊕ (w 4 ⨂ w 5 ) w 4 w 5 1 : one Identity Identity relation τ ⨂ 1 = τ
Weighted Automata Note: extend need not be commutative 5
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 } b c a w 2 w 3 A(abc) = (w 1 ⨂ w 2 ⨂ w 3 ) ⨁ w 1 (w 4 ⨂ w 5 ⨂ w 6 ) w 4 w 6 a w 5 c b
Weighted Automata • A(s) = ⨁ { v(�) | � is an accepting path for s } A A(s) (Bool, ⨂ is conj, ⨁ is disj) True iff s is accepted “true” on all edges (Nat, ⨂ is plus, ⨁ is min) ⨂ is plus, ⨁ is min) Length of shortest accepting path “1” on all edges (Distributive) Dataflow Analysis Meet-Over-All-(accepting)-Paths • A(T) = ⨁ { v(�) | � is an accepting path for s ∊ T } ⨁ { A(s) | s ∊ T }
Weighted Automata • Computing A(T) i ⨂ w 3 } A(ab*c) = ⨁ i { w 1 ⨂ w 2 i ) ⨂ w 3 = w 1 ⨂ ( ⨁ i w 2 b w 2 a c A(ab*c) = (w 1 . w 2 * . w 3 ) A(ab*c) = (w 1 . w 2 * . w 3 ) w 1 w w 3 w 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 9
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
Weighted Automata Intersection • A 3 (s) = A 1 (s) ⨂ A 2 (s) b a c a c ε b c A 3 (T) = ⨁ { A 3 (s) | s ∊ T } = ⨁ { A 1 (s) ⨂ A 2 (s) | s ∊ T } ǂ A 1 (T) ⨂ A 2 (T) Given a regular set T, { (s s) | s ∊ T } is not regular 12
Weighted Automata Intersection • ∀ s , A 3 (s) = A 1 (s) ⨂ A 2 (s) b w 2 c b u 3 a c a w 3 u 2 w 1 u 1 A 3 (abc) = (w 1 ⨂ w 2 ⨂ w 3 ⨂ u 1 ⨂ u 2 ⨂ u 3 ) b a c [w 2 ,u 2 ] [w 1 ,u 1 ] [w 3 ,u 3 ] 13
Weighted Automata Intersection • ∀ s , A 3 (s) = A 1 (s) ⨂ A 2 (s) b w 2 c b u 3 a c a w 3 u 2 w 1 u 1 A 3 (abc) = (w 1 ⨂ w 2 ⨂ w 3 ⨂ u 1 ⨂ u 2 ⨂ u 3 ) b a c w 2 ⨂ u 2 w 3 ⨂ u 3 (w 1 ⨂ u 1 ⨂ w 2 ⨂ u 2 ⨂ w 3 ⨂ u 3 ) w 1 ⨂ u 1 14
Tensor Product • Given semiring (D, ⨂ , ⨁ ), construct a new semiring (D T , ⨂ , ⨁ ) to represent pairs of weights from D Tensor: D x D → D T DeTensor: D T → D 1. Tensor(w ,w ) ⨂ Tensor(w ,w ) = Tensor(w ⨂ w , w ⨂ w ) 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 15
Weighted Automata Intersection • ⩝ s , A 3 (s) = A 1 (s) ⨂ A 2 (s) b w 2 c b u 3 a c a w 3 u 2 w 1 u 1 A 3 (abc) = (w 1 ⨂ w 2 ⨂ w 3 ⨂ u 1 ⨂ u 2 ⨂ u 3 ) b a c T(w 2 ,u 2 ) T(w 1 ,u 1 ) T(w 3 ,u 3 ) 16
Weighted Automata Intersection A 3 (abc) = (w 1 ⨂ w 2 ⨂ w 3 ⨂ u 1 ⨂ u 2 ⨂ u 3 ) T(w 1 ,u 1 ) ⨂ T(w 2 ,u 2 ) ⨂ T(w 3 ,u 3 ) b = T(w 1 ⨂ w 2 ⨂ w 3 , u 1 ⨂ u 2 ⨂ u 3 ) a c T(w 2 ,u 2 ) T(w 1 ,u 1 ) DeTensor T(w 3 ,u 3 ) (w 1 ⨂ w 2 ⨂ w 3 ⨂ u 1 ⨂ u 2 ⨂ 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 17
Weighted Automata Intersection A 3 ({abc, de}) = (w 1 ⨂ w 2 ⨂ w 3 ⨂ u 1 ⨂ u 2 ⨂ u 3 ) ⨁ (w 4 ⨂ w 5 ⨂ u 4 ⨂ u 5 ) T(w 1 ,u 1 ) ⨂ T(w 2 ,u 2 ) ⨂ T(w 3 ,u 3 ) b ⨁ T(w 4 ,u 4 ) ⨂ T(w 5 ,u 5 ) a c T(w 2 ,u 2 ) T(w 1 ,u 1 ) = T(w 1 ⨂ w 2 ⨂ w 3 , u 1 ⨂ u 2 ⨂ u 3 ) ⨂ ⨂ ⨂ ⨂ T(w 3 ,u 3 ) d d e e ⨁ T(w 4 ⨂ w 5 , u 4 ⨂ u 5 ) ⨁ T(w 4 ⨂ w 5 , u 4 ⨂ u 5 ) T(w 4 ,u 4 ) T(w 5 ,u 5 ) DeTensor (w 1 ⨂ w 2 ⨂ w 3 ⨂ u 1 ⨂ u 2 ⨂ u 3 ) ⨁ (w 4 ⨂ w 5 ⨂ u 4 ⨂ 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 ) 18
Weighted Automata Intersection Theorem: For any set of words T, DeTensor(A 3 (T)) = ⨁ {A 1 (s) ⨂ A 2 (s) | s ∊ T } DeTensor( ⊕ { A 3 (s) | s ∈ T } ) = ⊕ { DeTensor( A 3 (s) ) | s ∈ T } = ⊕ { DeTensor(Tensor(A (s),A (s)) ) | s ∈ T } = ⊕ { DeTensor(Tensor(A 1 (s),A 2 (s)) ) | s ∈ T } = ⊕ {A 1 (s) ⨂ A 2 (s) ⨂ | s ∈ T } 19
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 – Extend is matrix multiplication, combine is point-wise – Tensor is Kronecker product 20
Tensors • Kronecker product a 1 b 1 a 1 b 2 a 2 b 1 a 2 b 2 a 1 b 3 a 1 b 4 a 2 b 3 a 2 b 4 a 1 a 2 b 1 b 2 ⨀ = a 3 b 1 a 3 b 2 a 4 b 1 a 4 b 2 a 3 a 4 b 3 b 4 a 3 b 3 a 3 b 4 a 4 b 3 a 4 b 4 DeTensor 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 21
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
Part II: Context-Bounded Analysis Part II: Context-Bounded Analysis
Tensors and Concurrency Tensors give the necessary shuffling for interleaved executions Thread 1 Thread 2 w 1 T(w 1 , 1, 1) T(w 4 , 1, 1) w 4 Automata are w 2 w T(1, w , 1) T(1, w 2 , 1) required to do required to do w 5 w T(1, w 5 , 1) T(1, w , 1) this for all paths in the program w 3 T(1, 1, w 3 ) w 6 T(1, 1, w 6 ) Context bound is determined by the arity of tensor operation ⨂ ⨂ T(w 1 , w 2 , w 3 ) ⨂ ⨂ T(w 4 , w 5 , w 6 ) ⨂ w 6 ) � w 1 ⨂ T(w 1 ⨂ ⨂ ⨂ ⨂ w 4 , w 2 ⨂ ⨂ ⨂ ⨂ w 5 , w 3 ⨂ ⨂ ⨂ ⨂ ⨂ w 4 ⨂ ⨂ ⨂ w 2 ⨂ ⨂ ⨂ ⨂ ⨂ w 5 ⨂ ⨂ ⨂ w 3 ⨂ ⨂ ⨂ ⨂ ⨂ w 6 ⨂ 24
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 – 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
Context-bounded analysis • Abstract model Shared Memory G T 1 T 2 T n L 1 L 2 L n G x L 1 x L 2 x … x L n 27
Context-bounded analysis • Transition Systems (g,l i ) → Ti (g’,l i ’) T i (g,l 1 ,…, l i ,…, l n ) ⇒ Ti (g’,l 1 ,…,l i ’,…,l n ) Shared Memory T 1 T i T n • Transition system for an execution context ⇒ c equals ⇒ T1 * ⋃ ⇒ T2 * ⋃ … ⋃ ⇒ Tn * 28
Context-bounded analysis • Want to check reachability in the transition system: ⇒ c ⇒ c ⇒ c … ⇒ c ⇒ c k+1 times k+1 times 29
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) – Mapping starting states (input) to reachable states (output) • Transducers: FSMs with an input and a output tape 30
Thread Summarization • Reachability in a PDS can be modeled using a transducer [Caucal ‘92] (g 1 ,l 1 ) → T * (g 2 ,l 2 ) iff ((g 1 ,l 1 ), (g 2 ,l 2 )) ∈ L( τ ) r 1 : [glob,stack] 1 τ r 2 : [glob,stack] 2 • Advantage: transducers can be composed (r 1 ,r 2 ) ∈ L( τ 1 ) and (r 2 ,r 3 ) ∈ L( τ 2 ) then (r 1 ,r 3 ) ∈ L( τ 1 ; τ 2 ) 31
Thread Summarization For: Construct: (g,l i ) → Ti * (g ’ ,l i ’ ) τ i (g, l 1 ,…, l i ,…, l n ) ⇒ Ti * (g, l 1 ,…, l i ,…, l n ) ⇒ Ti * τ e e τ i (g ’ ,l 1 ,…,l i ’ ,…,l n ) ⇒ c equals τ c = e ⋃ … ⋃ τ n ⇒ T1 * ⋃ … ⋃ ⇒ Tn * e ⋃ τ 2 e τ 1 ⇒ c … ⇒ c ⇒ c τ c ; … ; τ c ; τ c 32
Recommend
More recommend