regular programming for quantitative properties of data streams Rajeev Alur Dana Fisman Mukund Raghothaman ESOP 2016 University of Pennsylvania 0
data streams ∙ EOM ∙ P1 ∙ EOM ∙ P2 ∙ P2 ∙ P2 ∙ EOD ∙ P2 ∙ P1 ∙ EOM ∙ P2 ∙ P1 ∙ P2 ∙ P2 ∙ P2 ∙ P1 web-page requests ∙ P2 ∙ P2 ∙ EOD ∙ P2 ∙ P1 ∙ P1 ∙ EOM ∙ P2 ∙ P2 ∙ P2 ∙ P1 ∙ EOD ∙ P2 ∙ P2 ∙ P1 1 ∙ · · ·
max count P1 count P2 data streams web-page requests ∙ What is the maximum number of daily requests for P2? ∙ What is the number of requests for P1 in an average month? iter - avg month - count P1 ∙ What is the total number of requests for P1? count P1 iter - sum day - count P1 ∙ What is the maximum of the total number of requests for P1 and P2? 2 iter - max ( day - count P2 )
max count P1 count P2 data streams web-page requests ∙ What is the maximum number of daily requests for P2? ∙ What is the number of requests for P1 in an average month? ∙ What is the total number of requests for P1? count P1 iter - sum day - count P1 ∙ What is the maximum of the total number of requests for P1 and P2? 2 iter - max ( day - count P2 ) iter - avg ( month - count P1 )
max count P1 count P2 data streams web-page requests ∙ What is the maximum number of daily requests for P2? ∙ What is the number of requests for P1 in an average month? ∙ What is the total number of requests for P1? ∙ What is the maximum of the total number of requests for P1 and P2? 2 iter - max ( day - count P2 ) iter - avg ( month - count P1 ) count P1 = iter - sum ( day - count P1 )
data streams web-page requests ∙ What is the maximum number of daily requests for P2? ∙ What is the number of requests for P1 in an average month? ∙ What is the total number of requests for P1? ∙ What is the maximum of the total number of requests for P1 and P2? 2 iter - max ( day - count P2 ) iter - avg ( month - count P1 ) count P1 = iter - sum ( day - count P1 ) max ( count P1 , count P2 )
quantitative regular expressions Languages Regular expressions Cost functions QREs 3 Σ ∗ → bool ≡ Σ ∗ → R ≡
function combinators
function combinators ∙ Analogue of basic regular expressions 5 basic expressions, a �→ d a �→ d ∙ If w = a , then output d , otherwise undefined ∙ P1 �→ 0 , P1 �→ 1 , EOD �→ 5 , …
function combinators f else g f else g ∙ Analogue of regular expression union 6 ∙ If f ( w ) is defined, then output f ( w ) , otherwise output g ( w )
function combinators op ∙ Analogue of regular expression intersection 7 ∙ f + g : Map w to f ( w ) + g ( w ) ∙ f − g : Map w to f ( w ) − g ( w ) ∙ max ( f , g ) : Map w to max ( f ( w ) , g ( w )) ∙ · · · ∙ op ( f 1 , f 2 , . . . , f k ) : Map w to op ( f 1 ( w ) , f 2 ( w ) , . . . , f k ( w ))
concatenation split - plus f g , split - max f g , …, split - op f g f g Output max op 8 split - op ( f , g ) w 1 w 2
concatenation , split - max f g , …, split - op f g f g Output max op 8 split - op ( f , g ) split - plus ( f , g ) w 1 w 2 +
concatenation , …, split - op f g f g Output max op 8 split - op ( f , g ) split - plus ( f , g ) , split - max ( f , g ) w 1 w 2 +
concatenation f g Output max op 8 split - op ( f , g ) split - plus ( f , g ) , split - max ( f , g ) , …, split - op ( f , g ) w 1 w 2 + · · ·
iteration w k op 9 iter - op ( f ) w k − 1 w 1 w 2
function combinators attempt 1 Conditional choice: f else g ∙ What about non-binary, non-commutative or non-associative operators? ∙ Are these operators “sufficient”? If we add more operators? 10 Basic functions: a �→ d Concatenation: split - op ( f , g ) Function iteration: iter - op ( f ) Cost operations: op ( f 1 , f 2 , . . . , f k )
function combinators attempt 1 Conditional choice: f else g ∙ What about non-binary, non-commutative or non-associative operators? ∙ Are these operators “sufficient”? If we add more operators? 10 Basic functions: a �→ d Concatenation: split - op ( f , g ) Function iteration: iter - op ( f ) Cost operations: op ( f 1 , f 2 , . . . , f k )
function combinators attempt 1 Conditional choice: f else g ∙ What about non-binary, non-commutative or non-associative operators? ∙ Are these operators “sufficient”? If we add more operators? 10 Basic functions: a �→ d Concatenation: split - op ( f , g ) Function iteration: iter - op ( f ) Cost operations: op ( f 1 , f 2 , . . . , f k )
parse trees and computation trees ∙ Attempt 1 annotates the parse tree with cost operations to obtain the computation tree ∙ What if QREs map input streams to computation trees? 11 split - plus ( count P1 , Σ 5 �→ 0)
parse trees and computation trees ∙ Attempt 1 annotates the parse tree with cost operations to obtain the computation tree ∙ What if QREs map input streams to computation trees? 11 split - plus ( count P1 , Σ 5 �→ 0) Σ 5
P1 parse trees and computation trees P2 P2 P1 ∙ Attempt 1 annotates the parse tree with cost operations to obtain the computation tree ∙ What if QREs map input streams to computation trees? 11 split - plus ( count P1 , Σ 5 �→ 0) · Σ 5 ∗ Σ 5 · · ·
1 parse trees and computation trees 0 0 1 ∙ Attempt 1 annotates the parse tree with cost operations to obtain the computation tree ∙ What if QREs map input streams to computation trees? 11 split - plus ( count P1 , Σ 5 �→ 0) + + 0 Σ 5 · · ·
1 parse trees and computation trees 0 0 1 ∙ Attempt 1 annotates the parse tree with cost operations to obtain the computation tree ∙ What if QREs map input streams to computation trees? 11 split - plus ( count P1 , Σ 5 �→ 0) + + 0 Σ 5 · · ·
quantitative regular expressions Key Insight QREs map input streams to terms over the cost domain ∙ Terms contain parameters ∙ Parameter substitution is also an operation 12 ∙ f ( aaab ) = 5 + p , where p is a parameter
quantitative regular expressions Key Insight QREs map input streams to terms over the cost domain ∙ Terms contain parameters ∙ Parameter substitution is also an operation 12 ∙ f ( aaab ) = 5 + p , where p is a parameter
function combinators substitution 13 Parameter subtitution, f [ p / g ] ∙ Say f ( w ) = t f , ∙ and g ( w ) = t g ∙ f [ p / g ]( w ) = t f [ p / t g ]
function combinators concatenation, take 2 f g Output 14 split ( f → p g ) w 1 w 2
function combinators concatenation, take 2 f g Output p 14 split ( f → p g ) w 1 w 2
function combinators concatenation, take 2 f Output p ∙ g w p g w 15 Simulating split - plus ( f , g ) w 1 w 2 g ′ ∙ split - plus ( f , g ) = split ( f → p g ′ )
function combinators concatenation, take 2 f Output p 15 Simulating split - plus ( f , g ) w 1 w 2 g ′ ∙ split - plus ( f , g ) = split ( f → p g ′ ) ∙ g ′ ( w ) = p + g ( w )
function combinators iteration, take 2 w k op f f f f p p p 16 w k − 1 w 1 w 2
function combinators iteration, take 2 w k op f f f f p p p 16 w k − 1 w 1 w 2
quantitative regular expressions Conditional choice: f else g ∙ QREs map string to terms ∙ Structural operators decoupled from cost operators 17 Basic functions: a �→ d , regex �→ term Concatenation: split ( f → p g ) , split ( f ← p g ) Function iteration: iter → ( f ) , iter ← ( f ) Cost operations: op ( f 1 , f 2 , . . . , f k ) , f [ p / g ]
quantitative regular expressions Conditional choice: f else g ∙ QREs map string to terms ∙ Structural operators decoupled from cost operators 17 Basic functions: a �→ d , regex �→ term Concatenation: split ( f → p g ) , split ( f ← p g ) Function iteration: iter → ( f ) , iter ← ( f ) Cost operations: op ( f 1 , f 2 , . . . , f k ) , f [ p / g ]
quantitative regular expressions ∙ Was our choice of combinators ad-hoc? What functions can the formalism express? ∙ Given f and an input stream w , can we efficiently compute 18 f ( w ) ?
expressiveness
regular cost functions [lics 2013] Languages Finite automata Cost functions ? Regular languages have many appealing properties: many natural equi-expressive characterizations, robust closure properties, decidable analysis problems, practical utility 20 Σ ∗ → bool ≡ Σ ∗ → R ≡
cost register automata [lics 2013] start ∙ Finite state space, finitely many registers ∙ Registers hold terms: Parameterized by set of operations ∙ Equivalent to MSO definable string-to-term transducers ∙ Closed under regular lookahead, input reversal, etc 21 d < 0/ bal := bal + d d ≥ 0/ bal := bal + d d ∈ R / bal := bal + d q 0 q 1 d = end m / bal := bal + 10 d = end m
cost register automata Theorem QREs can express exactly the same functions as CRAs 22
Taste of the completeness proof traversing states less than q i DReX expression 23 cras → qres ∙ Piggy-back on DFA to regular expression translation Construct R i ( q , q ′ ) : all strings from q to q ′ while only ∙ Construct f i ( q , q ′ , x ) : express final value of register x as a
Recommend
More recommend