Overlap and Independence in Multiset Comprehension Patterns. Supported by QNRF grants NPRP and

Similar documents
CPSC 121: Models of Computation

CSE507. Satisfiability Modulo Theories. Computer-Aided Reasoning for Software. Emina Torlak

Bachelor/Master Exam Version V3B

AST rewriting. Part I: Specifying Transformations. Imperative object programs. The need for path queries. fromentry, paths, toexit.

Bachelor/Master Exam Version V3B

CPSC 121: Models of Computation. Module 6: Rewriting predicate logic statements

A Logic Programming Approach to Querying and Integrating P2P Deductive Databases

Automated Reasoning Lecture 5: First-Order Logic

First-Order Predicate Logic. Basics

Theory of Computation

Modular Multiset Rewriting in Focused Linear Logic

Towards Algorithmic Synthesis of Synchronization for Shared-Memory Concurrent Programs

Logic and Modelling. Introduction to Predicate Logic. Jörg Endrullis. VU University Amsterdam

Computational Logic Fundamentals (of Definite Programs): Syntax and Semantics

An Approach to Computational Complexity in Membrane Computing

Deductive Verification

Example. Lemma. Proof Sketch. 1 let A be a formula that expresses that node t is reachable from s

Collective resource bounded reasoning in concurrent multi-agent systems

Section Summary. Predicate logic Quantifiers. Negating Quantifiers. Translating English to Logic. Universal Quantifier Existential Quantifier

Predicate Logic - Semantic Tableau

2-4: The Use of Quantifiers

Induction and Recursion

Reasoning About Imperative Programs. COS 441 Slides 10b

Foundations of Logic Programming

Propositional Logic: Models and Proofs

Mid-Semester Quiz Second Semester, 2012

THE AUSTRALIAN NATIONAL UNIVERSITY Second Semester COMP2600 (Formal Methods for Software Engineering)

Chapter 13 Uncertainty

Mathematical Logic Part Three

Why Can t You Behave? Non-Termination Analysis of Direct Recursive Rules with Constraints

Logic (3A) Young W. Lim 12/5/13

PROPOSITIONAL LOGIC. VL Logik: WS 2018/19

Meta-reasoning in the concurrent logical framework CLF

Undecidability. Andreas Klappenecker. [based on slides by Prof. Welch]

CS 4110 Programming Languages & Logics. Lecture 25 Records and Subtyping

CS 220: Discrete Structures and their Applications. Predicate Logic Section in zybooks

Paucity, abundance, and the theory of number: Online Appendices

CSE 241 Class 1. Jeremy Buhler. August 24,

A Modular Rewriting Semantics for CML

Proof techniques (section 2.1)

Loop Formulas for Description Logic Programs

One Year Later. Iliano Cervesato. ITT Industries, NRL Washington, DC. MSR 3.0:

INTRODUCTION TO LOGIC

ON1 Big Mock Test 4 October 2013 Answers This test counts 4% of assessment for the course. Time allowed: 10 minutes

Lecture Notes on Call-by-Value and Call-by-Name

Logic Part I: Classical Logic and Its Semantics

Introduction to Answer Set Programming

Predicate Logic. CSE 191, Class Note 02: Predicate Logic Computer Sci & Eng Dept SUNY Buffalo

CS156: The Calculus of Computation Zohar Manna Winter 2010

2/2/2018. CS 103 Discrete Structures. Chapter 1. Propositional Logic. Chapter 1.1. Propositional Logic

Scalable and Accurate Verification of Data Flow Systems. Cesare Tinelli The University of Iowa

Symmetry Breaking for Relational Weighted Model Finding

Lecture 20: PSPACE. November 15, 2016 CS 1010 Theory of Computation

First Order Logic (FOL) 1 znj/dm2017

What is Probability? Probability. Sample Spaces and Events. Simple Event

LING 501, Fall 2004: Quantification

Spiking Neural P Systems with Anti-Spikes as Transducers

Isomorphism of Finitary Inductive Types

CSE541 Class 22. Jeremy Buhler. November 22, Today: how to generalize some well-known approximation results

Outline. Formale Methoden der Informatik First-Order Logic for Forgetters. Why PL1? Why PL1? Cont d. Motivation

Engineering Self-Organization and Emergence: issues and directions

Predicate Logic: Sematics Part 1

Notes. Corneliu Popeea. May 3, 2013

ISTITUTO DI ANALISI DEI SISTEMI ED INFORMATICA

Advanced Topics in LP and FP

MATH 341, Section 001 FALL 2014 Introduction to the Language and Practice of Mathematics

Meta-Reasoning in a Concurrent Logical Framework

Discrete Mathematics and Its Applications

MSR 3.0: The Logical Meeting Point of Multiset Rewriting and Process Algebra. Iliano Cervesato. ITT Industries, NRL Washington, DC

Satisfiability Modulo Theories (SMT)

Philosophy 240 Symbolic Logic Russell Marcus Hamilton College Fall 2014

GATE 2015 A Brief Analysis (Based on student test experiences in the stream of CS on 8th February, 2015 (Morning Session)

Formal Modeling with Propositional Logic

Notes slides from before lecture. CSE 21, Winter 2017, Section A00. Lecture 16 Notes. Class URL:

CS 250/251 Discrete Structures I and II Section 005 Fall/Winter Professor York

Part 2: First-Order Logic

INDUCTIVE DEFINITION

COMPUTER SCIENCE TRIPOS

First-order resolution for CTL

3. The Logic of Quantified Statements Summary. Aaron Tan August 2017

1. Consider the conditional E = p q r. Use de Morgan s laws to write simplified versions of the following : The negation of E : 5 points

Propositional Fragments for Knowledge Compilation and Quantified Boolean Formulae

CS540 ANSWER SHEET

Answer Set Programming: an Introduction

CS839: Probabilistic Graphical Models. Lecture 2: Directed Graphical Models. Theo Rekatsinas

Abstract model theory for extensions of modal logic

Solutions to Exercises (Sections )

Topics in Concurrency

Logical reasoning - Can we formalise our thought processes?

Checking System Compliance by Slicing and Monitoring Logs

Equalities and Uninterpreted Functions. Chapter 3. Decision Procedures. An Algorithmic Point of View. Revision 1.0

ICS141: Discrete Mathematics for Computer Science I

Automated Program Verification and Testing 15414/15614 Fall 2016 Lecture 8: Procedures for First-Order Theories, Part 2

Simply Typed Lambda Calculus

Complexity Classes in Membrane Computing

Laws of Parallel Synchronised Termination

CS 4110 Programming Languages & Logics. Lecture 16 Programming in the λ-calculus

Top-Down Execution CS240B Notes

Combinations of Theories for Decidable Fragments of First-order Logic

Mathematical Logic Part Three

Transcription:

Overlap and Independence in Multiset Comprehension Patterns Edmund S.L. Lam sllam@qatar.cmu.edu Iliano Cervesato iliano@cmu.edu Supported by QNRF grants NPRP 4-1593-1-260 and 4-341-1-059

Outline 1 The Context 2 The Problem 3 The (Partial) Solution 4 The Conclusions

Comingle A programming language for distributed mobile apps Designed to implement mobile apps that run across Android devices Enables high-level system-centric abstraction species distributed computations as one declarative program compiles into node-centric fragments, executed by each node Typed multiset rewriting with decentralization comprehension patterns time synchronization modularity Declarative, concise, roots in linear logic

Comingle A programming language for distributed mobile apps Designed to implement mobile apps that run across Android devices Enables high-level system-centric abstraction species distributed computations as one declarative program compiles into node-centric fragments, executed by each node Typed multiset rewriting with decentralization comprehension patterns time synchronization modularity Declarative, concise, roots in linear logic

Example: Swap Data between X and Y up to Threshold P

Example: Swap Data between X and Y up to Threshold P In math: pivotswap : [X ]swap(y, P) [X ]item(d) D P D Xs [Y ]item(d) D Xs [Y ]item(d) D P D Ys [X ]item(d) D Ys

Example: Swap Data between X and Y up to Threshold P In math: pivotswap : [X ]swap(y, P) [X ]item(d) D P D Xs [Y ]item(d) D Xs [Y ]item(d) D P D Ys [X ]item(d) D Ys In code: predicate swap :: (loc,int) -> trigger. predicate item :: int -> fact. predicate display :: (string,a) -> actuator. rule pivotswap :: [X]swap(Y,P), {[X]item(D) D->Xs. D >= P}, {[Y]item(D) D->Ys. D <= P} --o [X]display(Msg,size(Ys),Y), {[X]item(D) D<-Ys}, [Y]display(Msg,size(Xs),X), {[Y]item(D) D<-Xs} where Msg = "Received %s items from %s".

Example: pivotswap Execution [X]swap(Y,P) {[X]item(D) D->Xs.D>=P} --o [X]display(Msg,size(Ys),Y), {[X]item(D) D<-Ys} {[Y]item(D) D->Ys.D<=P} [Y]display(Msg,size(Xs),X), {[Y]item(D) D<-Xs} where Msg = "Received %s items from %s". Let s = swap, i = item and d = display Node: n1 s(n2, 5), i(4), i(6), i(8) Node: n2 i(3), i(20) Node: n3 s(n2, 10), i(18)

Example: pivotswap Execution [X]swap(Y,P) {[X]item(D) D->Xs.D>=P} --o [X]display(Msg,size(Ys),Y), {[X]item(D) D<-Ys} {[Y]item(D) D->Ys.D<=P} [Y]display(Msg,size(Xs),X), {[Y]item(D) D<-Xs} where Msg = "Received %s items from %s". Let s = swap, i = item and d = display Node: n1 s(n2, 5), i(4), i(6), i(8) Node: n2 i(3), i(20) Node: n3 s(n2, 10), i(18)

Example: pivotswap Execution [X]swap(Y,P) {[X]item(D) D->Xs.D>=P} --o [X]display(Msg,size(Ys),Y), {[X]item(D) D<-Ys} {[Y]item(D) D->Ys.D<=P} [Y]display(Msg,size(Xs),X), {[Y]item(D) D<-Xs} where Msg = "Received %s items from %s". Let s = swap, i = item and d = display Node: n1 s(n2, 5), i(4), i(6), i(8) Node: n2 i(3), i(20) Node: n3 s(n2, 10), i(18) Node: n1 d( 1 from n2 ) i(3), i(4) Node: n2 d( 2 from n1 ) i(6), i(8), i(20) Node: n3 s(n2, 10), i(18)

Example: pivotswap Execution [X]swap(Y,P) {[X]item(D) D->Xs.D>=P} --o [X]display(Msg,size(Ys),Y), {[X]item(D) D<-Ys} {[Y]item(D) D->Ys.D<=P} [Y]display(Msg,size(Xs),X), {[Y]item(D) D<-Xs} where Msg = "Received %s items from %s". Let s = swap, i = item and d = display Node: n1 Node: n2 Node: n3 s(n2, 5), i(4), i(6), i(8) i(3), i(20) s(n2, 10), i(18) Node: n1 d( 1 from n2 ) i(3), i(4) Node: n2 d( 2 from n1 ) i(6), i(8), i(20) Node: n3 s(n2, 10), i(18)

Example: pivotswap Execution [X]swap(Y,P) {[X]item(D) D->Xs.D>=P} --o [X]display(Msg,size(Ys),Y), {[X]item(D) D<-Ys} {[Y]item(D) D->Ys.D<=P} [Y]display(Msg,size(Xs),X), {[Y]item(D) D<-Xs} where Msg = "Received %s items from %s". Let s = swap, i = item and d = display Node: n1 s(n2, 5), i(4), i(6), i(8) Node: n2 i(3), i(20) Node: n3 s(n2, 10), i(18) Node: n1 d( 1 from n2 ) i(3), i(4) Node: n2 d( 2 from n1 ) i(6), i(8), i(20) Node: n3 s(n2, 10), i(18) Node: n1 d( 1 from n2 ) i(4), i(3) Node: n2 d( 2 from n1 ) d( 1 from n3 ) i(18), i(20) Node: n3 d( 2 from n2 ) i(6), i(8)

Try it Yourself! Download from https://github.com/sllam/comingle Show your support, please STAR Comingle GitHub repository! Networking over Wi-Direct, NFC, LAN and Bluetooth support for drop-in/drop-out Proof-of-concept apps Drag Racing Battleship Wi-Direct directory Musical shares Swarbble Maa CoDoodle Racing cars across mobile devices Traditional maritime war game, multi-party Maintaining IP table for Wi-Direct Bounce a musical piece between devices Real-time team-based scrabble Traditional party game, with a mobile twist Interactive presentation tool

Outline 1 The Context 2 The Problem 3 The (Partial) Solution 4 The Conclusions

Syntax (A Comingle program P is a set of rules r : Ē g B where B is also a multisets of expressions; we are also ignoring locations and types) A head pattern Ē g consists of a multiset of expressions Ē a Boolean guard g An expression E is either a fact: p( t) a comprehension: p( t) g x T Multiset of all p( t) in the state that satisfy g x bound in g and t Comprehension range T is the multiset of all bindings x

Matching Semantics A state St is a multiset of ground facts Matching a head pattern H = with residual St : St H St Ē g against a state St Holds if St = St +, St and there is a ground substitution θ such that θē matches St + St does not match any comprehension in θē θg is valid θē head St + θē head St = θg St +, St Ē g St Comprehensions in Ē g match maximal portions of St

Pattern Interactions When do two head patterns interfere with each other? Useful for debugging implementation reasoning cost analysis Interference? One's consumed facts may prevent the other from being applicable... possibly concurrently

Overlap and Independence H 1 = Ē 1 g 1 and H 2 = Ē 2 g 2 without variables in common overlap if there is a state St such that St St H 1 St 1 for some St 1 and H 2 St 2 for some St 2, but there is no St such that St H 1 H 2 St. E.g., H 1 = p(a, X ), q(x ) and H 2 = p(y, Y ), r(z) Take St = (a, a), q(a), r(b) are independent if they don't overlap E.g., H 1 and H 2 = p(b, Y ), r(z) Are there algorithmic criteria?

Outline 1 The Context 2 The Problem 3 The (Partial) Solution 4 The Conclusions

Case: Plain Multisets H = F : empty guard and no comprehensions H 1 and H 2 overlap i one contains a fact uniable in the other: Notes: H 1 = p( t 1 ), F 1 H 2 = p( t 2 ), F 2 there is θ such that θ t 1 = θ t 2 p( t 1 ) and p( t 2 ) may not be unique Polynomial complexity... for well-behaved term languages Implemented using term-language unication

Case: Guarded Multisets H = F g : no comprehensions found in most rule-based languages H 1 and H 2 overlap i H 1 = p( t 1 ), F 1 H 2 = p( t 2 ), F 2 there is θ such that θ t 1 = θ t 2 and = θg 1 and = θg 2 Examples: H 1 = p(x ) X > 3 and H 2 = p(y ) Y < 10 overlap E.g., in state p(7) H 1 and H 2 = p(y ) Y < 3 are independent Implementation: compute uniers θ for p( t 1 ) and p( t 2 ), and then pass θg 1 and θg 2 to an SMT solver

Case: Open-ended Multisets H = Ē g : comprehension ranges is never used p(x ), p(x) x > 0 x Xs but not p(x ), p(x) x > 0 x Xs size(xs) = 0 H 1 and H 2 overlap exactly as in last case! Open-ended comprehensions can never fail At most return the empty multiset Consider H 1 = p(x ) and H 2 = p(x) x Xs : p(a) H 1 p(a) H 2 p(a) H 1 H 2 because H 2

General Case Unsolved!

General Case Unsolved! H 1 = p(x) x Xs, q(y ) Y Xs and H 2 = p(z) are overlapping: Succeed separately on St = p(a), q(a) Composition fails as guard of H 2 fails

General Case Unsolved! H 1 = p(x) x Xs, q(y ) Y Xs and H 2 = p(z) are overlapping: Succeed separately on St = p(a), q(a) Composition fails as guard of H 2 fails But H 1 = p(x) x < 3 x Xs, q(y ) Y Xs and H 2 = p(z) Z > 5 are independent: because no fact p(n) can match both patterns

General Case H 1 = p(x) x Xs size(xs) > 0 and H 2 = p(z)

General Case H 1 = p(x) x Xs size(xs) > 0 and H 2 = p(z) are overlapping: Succeed separately on St = p(a) Composition fails as Xs set to, violating guard

General Case H 1 = p(x) x Xs size(xs) > 0 and H 2 = p(z) are overlapping: Succeed separately on St = p(a) Composition fails as Xs set to, violating guard H 1 = p(x) x Xs size(xs) 8 and H 2 = p(z)

General Case H 1 = p(x) x Xs size(xs) > 0 and H 2 = p(z) are overlapping: But Succeed separately on St = p(a) Composition fails as Xs set to, violating guard H 1 = p(x) x Xs size(xs) 8 and H 2 = p(z) are independent: because it has an upper bound on the comprehension range, not a lower bound

General Case H 1 = p(x) x Xs size(xs) > 0 and H 2 = p(z) are overlapping: But Succeed separately on St = p(a) Composition fails as Xs set to, violating guard H 1 = p(x) x Xs size(xs) 8 and H 2 = p(z) are independent: because it has an upper bound on the comprehension range, not a lower bound Negation-as-absence: H 1 = p(x) x Xs size(xs) = 0 and H 2 = p(z)

General Case H 1 = p(x) x Xs, q(y) y Xs and H 2 = p(z) are overlapping: Succeed separately on St = p(a), q(a) Composition fails

General Case H 1 = p(x) x Xs, q(y) y Xs and H 2 = p(z) are overlapping: Succeed separately on St = p(a), q(a) Composition fails H 1 = p(x) x Xs, q(y) y Xs y Ys and H 2 = p(z) are independent: because it lters out values for Ys rather than requiring that some terms be present

Outline 1 The Context 2 The Problem 3 The (Partial) Solution 4 The Conclusions

Future Work Lots more work to be done!

Questions?

Comingle Example: Drag Racing Inspired by Chrome Racer (www.chrome.com/racer) Race across a group of mobile devices Purely local communications

Implementing Drag Racing in Comingle rule init :: [I]initRace(Ls) --o {[A]next(B) (A,B)<-Cs}, [E]last(), {[I]has(P), [P]all(Ps), [P]at(I), [P]rendTrack(Ls) P<-Ps} where (Cs,E) = makechain(i,ls), Ps = list2mset(ls). rule start :: [X]all(Ps) \ [X]startRace() --o {[P]release() P<-Ps}. rule tap :: [X]at(Y) \ [X]sendTap() --o [Y]recvTap(X). rule trans :: [X]next(Z) \ [X]exiting(Y), [Y]at(X) --o [Z]has(Y), [Y]at(Z). rule win :: [X]last() \ [X]all(Ps), [X]exiting(Y) --o {[P]decWinner(Y) P <- Ps}. + 862 lines of properly indented Java code 700++ lines of local operations (e.g., display and UI operations) < 100 lines for initializing Comingle run-time