Aggregates in Recursion: Issues and Solutions

Similar documents
Recursive Aggregates in Disjunctive Logic Programs: Semantics and Complexity

Aggregate Functions in Disjunctive Logic Programming: Semantics, Complexity, and Implementation in DLV*

Answer Sets and the Language of Answer Set Programming. Vladimir Lifschitz

Aggregate Functions in DLV

Translation of Aggregate Programs to Normal Logic Programs

Data Integration: Logic Query Languages

Exploiting Unfounded Sets for HEX-Program Evaluation

Web Science & Technologies University of Koblenz Landau, Germany. Stratified Programs

Lecture 9: Datalog with Negation

Constraint Solving. Systems and Internet Infrastructure Security

Conflict-driven ASP Solving with External Source Access

Enhancing ASP by Functions: Decidable Classes and Implementation Techniques

Essential Gringo (Draft)

Efficient Evaluation of Disjunctive Datalog Queries with Aggregate Functions

Aggregate Functions in Disjunctive Logic Programming: Semantics, Complexity, and Implementation in DLV

nfn2dlp: A Normal Form Nested Programs Compiler

8. Negation 8-1. Deductive Databases and Logic Programming. (Sommer 2017) Chapter 8: Negation

Debugging Answer-Set Programs with Ouroboros Extending the SeaLion Plugin

Declarative Semantics for Revision Programming and Connections to Active Integrity Constraints

JWASP: A New Java-Based ASP Solver

A Model-Theoretic Counterpart of Loop Formulas

Disjunctive Logic Programs with Inheritance

Forcing in disjunctive logic programs

Semantic Forcing in Disjunctive Logic Programs

Nonmonotonic Databases and Epistemic Queries*

Exploiting Partial Assignments for Efficient Evaluation of Answer Set Programs with External Source Access

Choice Logic Programs and Nash Equilibria in Strategic Games

Relational Databases

PROBABILISTIC GRAPHICAL MODELS SPECIFIED BY PROBABILISTIC LOGIC PROGRAMS: SEMANTICS AND COMPLEXITY

Logic Programming and Reasoning about Actions

Qualitative Decision Making and Answer Set Programming Extended Abstract

A Backjumping Technique for Disjunctive Logic Programming

Foundations of AI. 9. Predicate Logic. Syntax and Semantics, Normal Forms, Herbrand Expansion, Resolution

Tutorial. Answer Set Programming for the Semantic Web. Thomas Eiter, Roman Schindlauer. (Univ. Rey Juan Carlos, Madrid)

Declarative Semantics of Production Rules for Integrity Maintenance

Representing Argumentation Frameworks in Answer Set Programming

8 NP-complete problem Hard problems: demo

Extending OWL with Finite Automata Constraints

A Visual Interface for Drawing ASP Programs

CSE 20 DISCRETE MATH. Fall

Preferred Arguments are Harder to Compute than Stable Extensions

cf2 Semantics Revisited 1

Integrity Constraints (Chapter 7.3) Overview. Bottom-Up. Top-Down. Integrity Constraint. Disjunctive & Negative Knowledge. Proof by Refutation

Propositional Theories are Strongly Equivalent to Logic Programs

Complete Instantiation of Quantified Formulas in Satisfiability Modulo Theories. ACSys Seminar

arxiv: v1 [cs.db] 23 May 2016

Solving disjunctive fuzzy answer set programs

LTCS Report. Concept Descriptions with Set Constraints and Cardinality Constraints. Franz Baader. LTCS-Report 17-02

Prolog and ASP Inference Under One Roof

Chapter 5: Other Relational Languages.! Query-by-Example (QBE)! Datalog

The DLV Java Wrapper

On Structural Analysis of Non-Ground Answer-Set Programs

Stepping with SeaLion

Advanced BackJumping Techniques for Rule Instantiations

Chapter 5: Other Relational Languages

Towards Logic Programs with Ordered and Unordered Disjunction

Constructive negation with the well-founded semantics for CLP

Towards a Logical Reconstruction of Relational Database Theory

Model checking for nonmonotonic logics: algorithms and complexity

CS 512, Spring 2017: Take-Home End-of-Term Examination

On the Hardness of Counting the Solutions of SPARQL Queries

Principles of AI Planning. Principles of AI Planning. 7.1 How to obtain a heuristic. 7.2 Relaxed planning tasks. 7.1 How to obtain a heuristic

8.1 Polynomial-Time Reductions

CSE 20 DISCRETE MATH. Winter

Order and Negation as Failure

SAT-Based Answer Set Programming

Representing the Language of the Causal Calculator. in Answer Set Programming. Michael Casolary

arxiv:cs/ v1 [cs.ai] 8 Mar 2000

Declarative programming. Logic programming is a declarative style of programming.

Simplifying Logic Programs under Uniform and Strong Equivalence

arxiv: v1 [cs.ai] 5 Aug 2016

Issues in Parallel Execution of Non-monotononic Reasoning Systems

Debugging non-ground ASP programs with Choice Rules, Cardinality and Weight Constraints

Safe Stratified Datalog With Integer Order Does not Have Syntax

Issues in Parallel Execution of Non-monotononic Reasoning Systems

From Database Repair Programs to Consistent Query Answering in Classical Logic (extended abstract)

Logic Programming and Resolution Lecture notes for INF3170/4171

Model theoretic and fixpoint semantics for preference queries over imperfect data

Towards Automated Integration of Guess and Check Programs in Answer Set Programming

Detecting Logical Errors in SQL Queries

Unified Configuration Knowledge Representation Using Weight Constraint Rules

Automata Theory for Reasoning about Actions

Knowledge-Based Systems and Deductive Databases

An integrated Graphical User Interface for Debugging Answer Set Programs

Logic Programs for Consistently Querying Data Integration Systems

Extending Prolog with Incomplete Fuzzy Information

Module 6. Knowledge Representation and Logic (First Order Logic) Version 2 CSE IIT, Kharagpur

Conjunctive queries. Many computational problems are much easier for conjunctive queries than for general first-order queries.

An Interactive Approach to Answer Set Programming

Where Can We Draw The Line?

Scalar Aggregation in Inconsistent Databases

Extending ASPIDE with User-defined Plugins

Thomas Eiter, Michael Fink, Thomas Krennwallner, and Christoph Redl

QUIZ 1 REVIEW SESSION DATABASE MANAGEMENT SYSTEMS

Answer Set Optimization

Logical Aspects of Massively Parallel and Distributed Systems

Logic As a Query Language. Datalog. A Logical Rule. Anatomy of a Rule. sub-goals Are Atoms. Anatomy of a Rule

An Abductive Framework for General Logic Programs and other Nonmonotonic Systems

Building a Knowledge Base System for an integration of Logic Programming and Classical Logic

Lecture 17 of 41. Clausal (Conjunctive Normal) Form and Resolution Techniques

Transcription:

Aggregates in Recursion: Issues and Solutions Alpen-Adria-Universität Klagenfurt RuleML Webinar, 2018-05-25

Outline 1 2 3 4 Coincidence Results Complexity Results

: Aggregates Aggregates facilitate problem representation Standard in database query languages For example: SELECT company.name FROM company,employee WHERE company.id = employee.cid AND COUNT(employee.id) < 10

: Aggregates and Logic Programming In this talk: Combination of Logic Programming and Aggregates For example: SELECT company.name FROM company,employee WHERE company.id = employee.cid AND COUNT(employee.id) < 10 using Logic Programming (here ASP/Datalog): result(n) :- company(n, Y ), #count{x : employee(x, Y )} < 10. Does this look innocent?

Recursion A main feature of Logic Programming is recursion Example: tc(a, B) :- p(a, B). tc(a, B) :- p(a, X), tc(x, B). defines the transitive closure of p Supported also in SQL Recent (since SQL-99) Not particularly well-known Common Table Expressions (CTE)

Recursion and Aggregates Combination of recursion and aggregates? Explicitly forbidden in SQL! Meaning of p(a) :- #count{x : p(x)} > 0. Meaning of p(a) :- #count{x : p(x)} < 1. Meaning of p(1) :- #avg{x : p(x)}! = 1. p( 1) :- #avg{x : p(x)}! = 1.

ASP Herbrand interpretations Reduct for interpretation I: 1 Delete rules whose negative body is true in I. 2 Delete negative body from all other rules. Interpretations I which are minimal models of the reduct for I are answer sets. [Gelfond, Lifschitz 1988] (nondisjunctive) [Przymusinski 1991] (disjunctive) [Gelfond, Lifschitz 1991] (disjunctive, 2 kinds of negation)

ASP Herbrand interpretations Reduct for interpretation I: 1 Delete rules whose negative body is true in I. 2 Delete negative body from all other rules. Interpretations I which are minimal models of the reduct for I are answer sets. [Gelfond, Lifschitz 1988] (nondisjunctive) [Przymusinski 1991] (disjunctive) [Gelfond, Lifschitz 1991] (disjunctive, 2 kinds of negation)

Aggregates Aggregate Functions: Functions over ground term (multi)sets (Multi)sets specified as {A, B : Conj} or { c, d : Conj,...} Evaluate Conj w.r.t. an interpretation Aggregate Atoms: Aggregate Function plus comparison Important: Aggregate atoms depend on truth values of a set of standard atoms!

Aggregates Aggregate Functions: Functions over ground term (multi)sets (Multi)sets specified as {A, B : Conj} or { c, d : Conj,...} Evaluate Conj w.r.t. an interpretation Aggregate Atoms: Aggregate Function plus comparison Important: Aggregate atoms depend on truth values of a set of standard atoms!

Aggregates Aggregate Functions: Functions over ground term (multi)sets (Multi)sets specified as {A, B : Conj} or { c, d : Conj,...} Evaluate Conj w.r.t. an interpretation Aggregate Atoms: Aggregate Function plus comparison Important: Aggregate atoms depend on truth values of a set of standard atoms!

Aggregates Aggregate Functions: Functions over ground term (multi)sets (Multi)sets specified as {A, B : Conj} or { c, d : Conj,...} Evaluate Conj w.r.t. an interpretation Aggregate Atoms: Aggregate Function plus comparison Important: Aggregate atoms depend on truth values of a set of standard atoms!

Outline 1 2 3 4 Coincidence Results Complexity Results

Aggregate Stratification Definition A program P is stratified on an aggregate atom A if there exists a level mapping from its predicates to ordinals, such that for each rule and for each of its head atoms a the following holds: 1 For each predicate b of standard body literals: b a, 2 for each predicate b inside an aggregate body atom: b < a, and 3 for each predicate b in the head: b = a.

Aggregate Stratification Example Note: Stratification is relative to a program Unstratified aggregate atoms occur recursively a :- #count{ t : b } > 0. is stratified on the aggregate atom. a :- #count{ t : b } > 0. b :- a. is not stratified on the aggregate atom.

Answer Sets for Aggregate-stratified Programs Basic Idea: Treat aggregate atoms like negative literals Reduct: 1 Delete rules containing unsatisfied aggregates and negative literals 2 Delete aggregates and negative literals from all other rules [Kemp, Stuckey 1991], [Gelfond 2002], [Dell Armi, F., Ielpa, Leone, Pfeifer 2003] Many programs are aggregate stratified Use of aggregates often yields computational advantages But: Not all programs are aggregate stratified

Answer Sets for Aggregate-stratified Programs Basic Idea: Treat aggregate atoms like negative literals Reduct: 1 Delete rules containing unsatisfied aggregates and negative literals 2 Delete aggregates and negative literals from all other rules [Kemp, Stuckey 1991], [Gelfond 2002], [Dell Armi, F., Ielpa, Leone, Pfeifer 2003] Many programs are aggregate stratified Use of aggregates often yields computational advantages But: Not all programs are aggregate stratified

Answer Sets for Aggregate-stratified Programs Basic Idea: Treat aggregate atoms like negative literals Reduct: 1 Delete rules containing unsatisfied aggregates and negative literals 2 Delete aggregates and negative literals from all other rules [Kemp, Stuckey 1991], [Gelfond 2002], [Dell Armi, F., Ielpa, Leone, Pfeifer 2003] Many programs are aggregate stratified Use of aggregates often yields computational advantages But: Not all programs are aggregate stratified

Outline 1 2 3 4 Coincidence Results Complexity Results

Unstratification What happens when we consider unstratified aggregates? Can we just keep the simple semantic definition?

Company Control Input: Set of companies and shares companies hold of other companies. Output: Companies controlled (direct or indirect shares > 50%) by other companies Encoding from the literature: controlsstk(c1, C1, C2, P) :- ownsstk(c1, C2, P). controlsstk(c1, C2, C3, P) :- controls(c1, C2), ownsstk(c2, C3, P). controls(c1, C3) :- company(c1), company(c3), #sum{p, C2 : controlsstk(c1, C2, C3, P)} > 50.

Company Control, Instance 1 Example (Company Control, Instance 1) 60% b 40% a 30% 15% c 35% d {controlsstk(a,a,b,60), controlsstk(a,a,c,30), controlsstk(a,a,d,15), controlsstk(b,b,d,40), controlsstk(c,c,d,35), controlsstk(a,b,d,40), controls(a,b), controls(a,d)}

Company Control, Instance 1 Example (Company Control, Instance 1) 60% b 40% a 30% 15% c 35% d {controlsstk(a,a,b,60), controlsstk(a,a,c,30), controlsstk(a,a,d,15), controlsstk(b,b,d,40), controlsstk(c,c,d,35), controlsstk(a,b,d,40), controls(a,b), controls(a,d)}

Company Control, Instance 2 Example (Company Control, Instance 2) a 40% 40% b 20% 20% c {controlsstk(a,a,b,40), controlsstk(a,a,c,40), controlsstk(b,b,c,20), controlsstk(c,c,b,20)} But also: {controlsstk(a,b,c,20), controlsstk(a,c,b,20), controls(a,b), controls(a,c)}

Company Control, Instance 2 Example (Company Control, Instance 2) a 40% 40% b 20% 20% c {controlsstk(a,a,b,40), controlsstk(a,a,c,40), controlsstk(b,b,c,20), controlsstk(c,c,b,20)} But also: {controlsstk(a,b,c,20), controlsstk(a,c,b,20), controls(a,b), controls(a,c)}

Company Control, Instance 2 Example (Company Control, Instance 2) a 40% 40% b 20% 20% c {controlsstk(a,a,b,40), controlsstk(a,a,c,40), controlsstk(b,b,c,20), controlsstk(c,c,b,20)} But also: {controlsstk(a,b,c,20), controlsstk(a,c,b,20), controls(a,b), controls(a,c)}

Essence Example a :- #count{ t : a } < 1. No answer sets. a :- #count{ t : a } > 0. Answer sets:, {a}? #count{ t : a } < 1 behaves like not a #count{ t : a } > 0 behaves like a aggregates should not be treated like negative literals, but also not like positive literals

Essence Example a :- #count{ t : a } < 1. No answer sets. a :- #count{ t : a } > 0. Answer sets:, {a}? #count{ t : a } < 1 behaves like not a #count{ t : a } > 0 behaves like a aggregates should not be treated like negative literals, but also not like positive literals

Monotonicity and Antimonotonicity Monotone Literals: truth for interpretation I implies truth for all J I Antimonotone Literals: truth for interpretation J implies truth for all I J Nonmonotone Literals: neither monotone nor antimonotone

Monotonicity: Examples #count{...} 1 is monotone #count{...} < 1 is antimonotone #avg{...} < 3 is nonmonotone Positive standard literals are monotone Negative standard literals are antimonotone

FLP : Novel Reduct Definition Definition of reduct according to [F.,Leone,Pfeifer 2004, F., Leone, Pfeifer 2011]: Delete rules with a false body literal. That s it! Answer Set: Subset-minimal model of the reduct Theorem For aggregate-free programs, answer sets under this definition coincide with the ones defined in [Gelfond, Lifschitz 1991]. (Mostly) equivalent semantics defined in [Ferraris 2005], [Ferraris 2011].

FLP : Novel Reduct Definition Definition of reduct according to [F.,Leone,Pfeifer 2004, F., Leone, Pfeifer 2011]: Delete rules with a false body literal. That s it! Answer Set: Subset-minimal model of the reduct Theorem For aggregate-free programs, answer sets under this definition coincide with the ones defined in [Gelfond, Lifschitz 1991]. (Mostly) equivalent semantics defined in [Ferraris 2005], [Ferraris 2011].

FLP : Novel Reduct Definition Definition of reduct according to [F.,Leone,Pfeifer 2004, F., Leone, Pfeifer 2011]: Delete rules with a false body literal. That s it! Answer Set: Subset-minimal model of the reduct Theorem For aggregate-free programs, answer sets under this definition coincide with the ones defined in [Gelfond, Lifschitz 1991]. (Mostly) equivalent semantics defined in [Ferraris 2005], [Ferraris 2011].

Company Control, Instance 1 Example (Company Control, Instance 1) 60% b 40% a 30% 15% c 35% d {controlsstk(a,a,b,60), controlsstk(a,a,c,30), controlsstk(a,a,d,15), controlsstk(b,b,d,40), controlsstk(c,c,d,35), controlsstk(a,b,d,40), controls(a,b), controls(a,d)}

Company Control, Instance 1 Example (Company Control, Instance 1) 60% b 40% a 30% 15% c 35% d {controlsstk(a,a,b,60), controlsstk(a,a,c,30), controlsstk(a,a,d,15), controlsstk(b,b,d,40), controlsstk(c,c,d,35), controlsstk(a,b,d,40), controls(a,b), controls(a,d)}

Company Control, Instance 2 Example (Company Control, Instance 2) 40% a 40% b 20% c 20% {controlsstk(a,a,b,40), controlsstk(a,a,c,40), controlsstk(b,b,c,20), controlsstk(c,c,b,20)} Only this answer set.

Company Control, Instance 2 Example (Company Control, Instance 2) 40% a 40% b 20% c 20% {controlsstk(a,a,b,40), controlsstk(a,a,c,40), controlsstk(b,b,c,20), controlsstk(c,c,b,20)} Only this answer set.

Small examples Example a :- #count{ t : a } < 1. No answer sets. a :- #count{ t : a } > 0. Answer sets: only

PSP Alternative semantics for unstratified aggregates: [Pelov 2004], [Son, Pontelli 2007], [Shen, Wang 2012] Definitions use different operator-based techniques Evaluate aggregates for a pair of interpretations (I, J) = A iff K = A for all I K J. PSP answer sets are those I that are fixpoints of K I Π Operator KΠ I (X) collects heads of rules for which (X, I) = A for all body atoms

Small examples: PSP Example a :- #count{ t : a } < 1. No answer sets. KΠ ( ) = {a} KΠ ({a}) = {a} K {a} Π ( ) = a :- #count{ t : a } > 0. Answer sets: only KΠ ( ) = K {a} Π ( ) =

Outline Coincidence Results Complexity Results 1 2 3 4 Coincidence Results Complexity Results

FLP and PSP Coincidence Results Complexity Results Example Small examples could suggest that they coincide. But this is not true in general. p(1) :- #avg{x : p(x)} 0. p(1) :- p( 1). p( 1) :- p(1). FLP answer sets: {p(1), p( 1)} PSP answer sets: none In general: each PSP answer set is also FLP, but not necessarily vice versa. Classes on which the semantics coincide?

Aggregate-stratified Programs Coincidence Results Complexity Results Easy observation: Theorem FLP and PSP semantics coincide on aggregate-stratified programs.

Coincidence Results Complexity Results Monotone, antimonotone, convex {a, b, c, d} {a, b, c} {a, b, d} {a, c, d} {b, c, d} 1 #count{a, b, c, d} {a, b} {a, c} {a, d} {b, c} {b, d} {c, d} S is monotone if I = S J = S = K = S K I J {a} {b} {c} {d}

Coincidence Results Complexity Results Monotone, antimonotone, convex {a, b, c, d} {a, b, c} {a, b, d} {a, c, d} {b, c, d} 1 #count{a, b, c, d} {a, b} {a, c} {a, d} {b, c} {b, d} {c, d} S is monotone if I = S J = S = K = S K I J {a} {b} {c} {d}

Coincidence Results Complexity Results Monotone, antimonotone, convex {a, b, c, d} {a, b, c} {a, b, d} {a, c, d} {b, c, d} #count{a, b, c, d} 3 {a, b} {a, c} {a, d} {b, c} {b, d} {c, d} S is antimonotone if I = S J = S = K = S K I J {a} {b} {c} {d}

Coincidence Results Complexity Results Monotone, antimonotone, convex {a, b, c, d} {a, b, c} {a, b, d} {a, c, d} {b, c, d} #count{a, b, c, d} 3 {a, b} {a, c} {a, d} {b, c} {b, d} {c, d} S is antimonotone if I = S J = S = K = S K I J {a} {b} {c} {d}

Coincidence Results Complexity Results Monotone, antimonotone, convex {a, b, c, d} {a, b, c} {a, b, d} {a, c, d} {b, c, d} 1 #count{a, b, c, d} 3 {a, b} {a, c} {a, d} {b, c} {b, d} {c, d} S is convex if I = S J = S = K = S K I J {a} {b} {c} {d}

Coincidence Results Complexity Results Monotone, antimonotone, convex {a, b, c, d} {a, b, c} {a, b, d} {a, c, d} {b, c, d} 1 #count{a, b, c, d} 3 {a, b} {a, c} {a, d} {b, c} {b, d} {c, d} S is convex if I = S J = S = K = S K I J {a} {b} {c} {d}

Convex Programs Coincidence Results Complexity Results Implicit in [Liu, Truszczyński 2006]: Theorem FLP and PSP semantics coincide on programs containing only convex aggregates. Corollary FLP and PSP semantics coincide on programs containing only monotone and antimonotone aggregates.

Outline Coincidence Results Complexity Results 1 2 3 4 Coincidence Results Complexity Results

Problem Coincidence Results Complexity Results Cautious reasoning over variable-free programs and polynomial-time computable aggregate functions. Input: A ground program P and a ground standard atom A. Output: Is A true in all FLP answer sets of P? Similar results for related problems (answer set existence, brave reasoning).

Problem Coincidence Results Complexity Results Cautious reasoning over variable-free programs and polynomial-time computable aggregate functions. Input: A ground program P and a ground standard atom A. Output: Is A true in all FLP answer sets of P? Similar results for related problems (answer set existence, brave reasoning).

Coincidence Results Complexity Results Complexity of Cautious Reasoning {} {not} { } {not, } {M} P co-np co-np Π P 2 {S} P co-np Π P 2 Π P 2 {C} co-np co-np Π P 2 Π P 2 {N} Π P 2 Π P 2 Π P 2 Π P 2 {M}: monotone aggregates {S}: stratified aggregates {C}: convex aggregates {N}: non-convex aggregates

Complexity: FLP and PSP Coincidence Results Complexity Results Results for PSP: analogous to FLP Slight difference for non-convex aggregates [Alviano, F. 2013]: One non-convex aggregate is sufficient to express any problem in Π P 2 with FLP Arbitrarily many are needed to do the same with PSP

Only Aggregates? Coincidence Results Complexity Results All of the results presented here also apply to other extensions of ASP that have constructs that evaluate truth on sets of basic atoms, for example: Abstract Constraint Atoms (U, V ) [Marek, Remmel 2004] HEX programs [Eiter et al. 2005] Nested Expressions [Lifschitz et al. 1999] Generalized Quantifiers [Lindström 1966] Cardinality and Weight Constraints [Simons 2000]

Summary Coincidence Results Complexity Results Aggregates in ASP FLP and PSP : Coincidence and Complexity

More Coincidence Results Complexity Results Example Beyond FLP and PSP? [Alviano, F. 2015] a :- #count{a, b}! = 1. b :- #count{a, b}! = 1. No FLP, no PSP answer sets! Unintuitive? Reduce programs with non-convex aggregates to programs with monotone aggregates in a compact way. [Alviano, F., Gebser 2015] System support: results in [Alviano, F., Gebser 2015] allow for non-convex aggregates in gringo 4.5.