110 likes | 273 Views
Temporal Rules. Vijay Saraswat IBM TJ Watson July 27, 2012. Central Problem. Need a powerful language for event processing that permits event correlation, detects absence of events (negative information), and permits aggregative queries. Declarative Synchronous Programming:
E N D
Temporal Rules Vijay Saraswat IBM TJ Watson July 27, 2012
Central Problem Need a powerful language for event processing that permits event correlation, detects absence of events (negative information), and permits aggregative queries. Declarative Synchronous Programming: Combines temporality with streaming Temporal (Relational) Databases: Facts are associated with valid-time and transaction-time Streaming Databases: Streams are infinite tables, with windowed operations
Timed Concurrent Constraint Programming Environment System TCC Concurrent system, agents interact with each other by posting constraints on shared store. A ::= c | if c then A | A,A | new X in A | a A ::= next A | if c else A else allows detection of negative information Gentzen: Constraint system is just database of facts. Synchronous Languages System lies inert. Environment supplies stimulus, at time and rate of its choosing. System computes instantaneous reaction and resumption (future behavior). Physical time is realized by driving on the beat of a physical clock (add a new time(M) fact to store at each instant). Synchrony Hypothesis: Computation happens “instantaneously”.
Example Programs The agent "Every hour checkpoint state" can be formulated as: every hour do checkPointState() This relation holds if p is the price of the most recent (in the past) time instant at which there is a stock(s,_) event. (If there is more than one stock(s,_) event at that time instant, p is the lowest such price.) prevPriceOfStock(s:Stock, p:Price) :- last (some q=> stock(s,q)) do p=(min q=>stock(s,q)). priceDropped(s:Stock) :- some p:Price => some q:Price stock(s,p), prevPriceOfStock(s,q), p < q. Every tenth time the price drops within an hour emit volatility warning. priceDropTenthTime(s:Stock) -: every hour dotime next^10 emitVolatilityWarning on always priceDropped(s) watching hour.
TCC temporal constructs TCC permits a large number of temporal constructs (including pre-emption based constructs) to be defined always A = A, next always A every c do A = every time c is true, run A first c do A = at the first instant at which c is true, run A do A watching c = run A, and abort it as soon as c is true time A on B = run A on a clock defined by B ... Basic Results (93-96): Language is declarative – computation in linear temporal logic Programs can be compiled to finite state automata System can be extended to continuous time (Large number of additional papers since then, on proof systems, abstract interpretation, expressiveness etc)
Complex Event Processing: TCC with History Environment Future, operated on by agents Past, fully formed, queried in guard System Technical Challenges Compile complex queries about the past to incremental “forward” rules (flat TCC) Share conditions across multiple rules. Conceptually, a “Rete” over time. Key Idea Do not forget the past – store records constraints at all past time instants Use TCC constructs to move back and forth in the past. G::= c | G,G | if A then G | past G | ...
Business Rules Rich declarative rules in TCC very suitable for a business logic presentation. Plan: Develop a business language (working with WODM team), using BDSL framework. Business language compiled down into an intermediate representation based on TCC with Past, further compiled into FSMs where appropriate.
Constraint system: Examples Gentzen Herbrand Lists Finite domain Propositional logic (SAT) Arithmetic constraints Naïve Linear Nonlinear Interval arithmetic Orders Temporal Intervals Hash-tables Arrays Graphs Constraint systems are ubiquitous in computer science Type systems (checking, inference) Static analysis Symbolic computation Concurrent system analysis
Concurrent Constraint Programming Use constraints for communication and control between concurrent agents operating on a shared store. Two basic operations Tell c: Add c to the store Ask c then A: If the store is strong enough to entail c, reduce to A. (Agents) A ::= c if (c) A A,B {x:T; A} (Config) G ::= A,…,A G,{x:T;A}G,A (x not free in G) G, if (c) AG,A (s(G) |- c) [[A]] = set of fixed points of a closure operator Operational semantics is complete for logical entailment of constraints. Saraswat 89; POPL 87, POPL 90, POPL 91