Title: Answer Set Programming
1Answer Set Programming
- Answer Set Programming as a rule based
programming paradigm
Zhang Qi zhangqi_pku_at_hotmail.com
2005-06-13
2Road Map
- A. Logic Programming with Answer Set Semantics
- Answer Set is a novel semantics for logic
programming bearing both declarative programming
paradigm and constraint satisfaction paradigm.
It is proved to be useful in many scenarios.
Integrating Answer Set Programming with
imperative programming language, e.g. Java is
also proposed. - B. Logic and Databases
- A subset of Answer Set Program, Datalog, is
strictly more expressive than relational database
which is de facto a standard data manipulating
technique for industrial usage. It is obvious
that pattern representation with Answer Set
Programming will be of extremely useful because
of its expressiveness and efficiency. - C. Combining Ontology with Logic Programming
- Ontology is very useful in database integration.
It also benefits user query to a higher
abstraction. Ontology mapping need an expressive
mapping language, and Answer Set Programming is
surely a way to go. - D. Data Mining with Inductive Logic Programming
- Inductive logic programming can find new
relations out of extensional database and is an
advanced technique to mine database.
3A. Logic Programming with Answer Set Semantics
- A.1 Logic Programming
- A.2 Answer Set Programming
- A.3 Scenario
- A.4 Java Rule Engine
4Introduction to Logic Programming
- Logic Programming
- The semantics of predicate logic as a programming
language - Use a computer for drawing conclusions from
declarative descriptions - Syntax
- Definite Logic ProgramA0 - A1, , Am
- General Logic ProgramA0 - A1, , Am, not Am1,
, not An - Extended Logic ProgramL0 - L1, , Lm, not Lm1,
, not Ln - Disjunctive Logic ProgramL0 oror Lk - Lk1, ,
Lm, not Lm1, , not Ln - Semantic
- Declarative semantic, e.g. p - p
- Prolog loop forever
- Well-Founded undefined
- Answer Set
- Procedural semantic
- Resolution
- Answer Set Programming
5Practical View
- Logic Program
- by which the programmer attempts to describe the
intended model - containing facts (extensional database) and rules
(intensional database) - Rule Engine
- draws conclusions about the intended model
- guarantees that conclusions must be true in any
model of the logic program - Conclusion
- are guaranteed to be true in the intended model
1
2
3
Conclusions
Logic Program
Rule Engine
Logic Programming
Answer 1q(4,1) q(6,2) q(1,3) q(5,4) q(2,5)
q(8,6) q(3,7) q(7,8) Answer 2q(4,1) q(2,2)
q(8,3) q(5,4) q(7,5) q(1,6) q(3,7)
q(6,8) Answer 92q(7,1) q(2,2) q(4,3) q(1,4)
q(8,5) q(5,6) q(3,7) q(6,8)
8-Queen Puzzle. number(1..8). 1q(I, J)
number(I)1 - number(J). - q(I, J), q(I, J1),
number(IJJ1), JltJ1. - q(I, J), q(I1, J1),
number(II1JJ1), JltJ1, abs(I1-I)J1-J. hide
number(I).
- Least Herbrand Model
- Program Completion
- Well-Founded Semantics
- Answer Set Semantics
6General View
- Logic Program
- by which the programmer attempts to describe the
intended model - containing facts (extensional database) and rules
(intensional database) - Rule Engine
- draws conclusions about the intended model
- guarantees that conclusions must be true in any
model of the logic program - Conclusion
- are guaranteed to be true in the intended model
Indented model
model
model
P
P F
Indented model
model
model
F
7Declarative Programming Paradigm
- Declarative programming is an approach to
computer programming - Involves the creation of a set of conditions that
describe a solution space. - Leaves the interpretation of the specific steps
needed to arrive at that solution up to an
unspecified interpreter. - The programmer can concentrate on stating what is
to be computed, not necessarily how it is to be
computed. In Kowalski's terms where algorithm
logic control, the programmer gives the logic
but not necessarily the control. - Advantages
- The solution can address the problem at an
abstract level without delving into irrelevant
details. This makes the solution easier for
humans to understand. - Complex problem solving is isolated and handled
by the interpreter. - The Reinventing the wheel anti-pattern is avoided
(i.e. one interpreter written years ago can apply
its logic to a wide variety of declarative
specifications). - Re-use/re-interpretation in different contexts is
possible.
8Declarative Programming vs. Imperative Programming
- Procedural Programming Program Algorithm
Data Structure - Imperative Programming Algorithm Logic
Control - 8-Queen problem as an example
Procedural Programming
Declarative Programming
- AlgorithmNeed no effort.
- Data StructureNeed no effort.
- ProgrammingIn several lines of rules and
facts.Write once, run everywhere. - TestingDo not need testing.
- EfficiencyHigh performance because of a general
and advanced rule engine.
- Algorithm Brute Force over NP-complete Back
Tracking Local Search - Data StructureCooperate with algorithm.
- ProgrammingBearing an abrupt learning curve.In
thousands of Java code. - TestingBlack box. White box.
- EfficiencyHighly depends on the programmer.
9Logic Programming with Answer Set Semantics
- A.1 Logic Programming
- A.2 Answer Set Programming
- A.3 Scenario
- A.4 Java Rule Engine
10Prolog revisited
- Prolog programming in logic
- Language
- Function symbols
- List constructors .. used to define high-order
objects - Term-based data structure
- Extensive use of recursive
- Query
- Proof provide answers
- SLD-Resolution
- Unification-based mechanism to manipulate data
structure - Search for proofs is the key
- Understand of the resolution mechanism is
important - Order of rules relevant for query answering
- Termination vs. Non-Termination
- Is this truly declarative programming?
- Desiderata of pure declarative programming
- Order of program rules does not matter
- Order of sub goals in a rule does not matter
11Answer Set Programming
- ASP is a modern form of declarative programming
oriented towards difficult combinational search
problem. - Use a logic based language to describe the domain
- Express various tasks as queries to the resulting
program - Use an inference engine, i.e. a collection of
reasoning algorithm, to answer the queries - Fundamental concept
- Models, not proofs, represent the solution
- Need techniques to compute models, not proofs
- Semantics of programs adhere to the multiple
preferred model approach - Semantics is given as a selection of the
collection of all classical models - Selected models are called answer sets
- Expressive syntax
- Classical Negation
- Default Negation
- Epistemic Disjunction
- Constraint
- Close World Assumption
12Answer Set Semantics
- Syntax
- Rule a0 - a1, , am, not am1, , not an
- ai are atoms
- a0 is the head, a1, , am, not am1, , not an is
the body - Logic program P is a finite set of rules
- Semantics
- Reduct PM on a set of atoms M is
- for each a in M remove rules with not a in the
body - remove literal not(a) from all other rules
- Reduct PM is a horn program that has the least
model LM(PM ) - M is an answer set of P if MLM(PM )
- Intuition
- M makes an assumption about what is true and what
is false - PM derives positive facts under the assumption of
not(a) as by M - If the result is M, then the assumption of M is a
answer set - Programs with variables
- For a logic program P with variables, the answer
sets of P are those of the ground instantiation
PH of P with respect to its Herbrand universe.
13Architecture
- Modeling the problem to a logic program
- Intuitive semantics
- Concise encoding
- Modular programming
- Finite domain without functors
- Constraints
- Reduce the logic program with variable to
propositional form - Logic programming technique
- Database technique
- User rule engine to search the model of the
program - Use LDPP algorithm to guess and check
- Employ modern SAT solvers to solve the
propositional logic problem - Meta-Search will
14Declarative Programming Paradigm
- ASP is an important declarative logic programming
method - Developed in the early 1990s by Gelfond and
Lifschitz in analogy to default logic. - Also referred to as A-Prolog.
- Gains increasing importance for knowledge
representation. - High expressiveness.
- Efficient solvers available
- In Answer Set Programming
- Modeling the problem by giving specification
- Order of program rules does not matter
- Order of sub goals in a rule does not matter
- ASP solver is sound and complete
- ASP solver is generic by keeping the semantics of
the program - ASP is a real declarative programming paradigm.
15Constraint Satisfaction Programming Paradigm
- Constraint Satisfaction Programming Paradigm
- A set of variables with finite domains
- A set of constraints
- Each variable has exactly one value from its
domain and all constraints are satisfied - Examples
- Pigeon Put N pigeons into M holes so that there
is at most one pigeon in a hole. - Queens Place n queens on an n x n board so no
queen checks against any other queen. - Schur Partition the integer N 1,2,...,n into
b boxes such that for any x, y of N, (i) x and 2x
are in different boxes and (ii) if x and y are in
the same box, then x y is in a different box. - ASP brings advantages of knowledge representation
technique by logic programming to constraint
programming in dynamic domains.
16Reasoning with Defaults
- Default
- Is a statement of natural language containing
words like normally, typically or as a
rule. - Is useful since we do not have complete
information about the world, but must still be
able to draw conclusions based on our knowledge
of what is common. - Is one kind of non-monotonic reasoning which
allows removal of previously achieved conclusions
when new information becomes available is called. - Define the complement of a relation
- ancestor(X,Y) - parent(X,Y).
- ancestor(X,Z) - parent(X,Y), ancestor(Y,Z).
- ! ancestor(X,Z) - person(X), person(Y), not
ancestor(Y,Z). - Define exception
- flies(X) - bird(X), not abnormal(X).
- bird(X) - sparrow(X).
- bird(X) - pengiun(X).
- abnormal(X) - pengiun(X).
17Available ASP Systems
- Smodels
- aspps
- dlv
- CMODELS
- ASSAT
- NoMoRe
- XASP
- ccalc
18Logic Programming with Answer Set Semantics
- A.1 Logic Programming
- A.2 Answer Set Programming
- A.3 Scenario
- A.4 Java Rule Engine
19Planning
- Block world
- Kautz and Selman proposed to approach the problem
of plan generation by reducing it to the problem
of finding a satisfying problem of propositional
formulas. - Subrahmanian and Zaniolo reduces a planning
problem to the problem of finding an answer set
for a logic program. - As a new knowledge representation paradigm
- action
- planning
- diagnosis
- ASP runs much faster than many commercial
planners.
Initial State
Goal
3
6
1
3
5
2
5
2
6
1
4
4
20Product configuration
- A rule-based language is
- proposed for product configuration applications.
- equipped with a declarative semantics providing
formal definitions for main concepts in product
configuration, including configuration models,
requirements and valid configurations. - A rule-based language leads to favorable
computational properties - the validity of a configuration can be decided in
linear time - other computational tasks remain in NP
- Use smodels as a computational engine
- ASP runs much faster than many commercial
applications.
21Semantic Web
- Towards the integration of rules and ontologies
in the Semantic Web - Combination of ASP with description logic
- Building rules on top of ontologies
- Building ontologies on top of rules
- Conceptual Logic Programming
- Simulate finite answer set programming
- Simulate reasoning in an expressive class of
description logics, - Play the role of ontology language
- Play the role of rule language
- Has a extremely fast rule engine
22Combinational Graph Problem
- K-colorability
- Finding an assignment of one of k colors to each
vertex of a graph such that vertices connected
with an arc do not have the same color. - col(X, r) or col(X, g) or col(X b) - node(X).
- - edge(X, Y), col(X, C), col(Y, C)
- Hamiltonian Circuits
- Finding a path in a graph that visits each vertex
of the graph exactly once and returns to the
starting vertex. - inPath(X, Y) or outPath(X, Y) - arc(X, Y).
- - inPath(X, Y), inPath(X, Y1), Y ltgt Y1.
- - inPath(X, Y), inPath(X1, Y), X ltgt X1.
- - node(X), not reached(X).
- reached(X) - start(X).
- reached(X) - reached(Y), inPath(Y, X).
23Mathematical Relations
- ASP can be used to define relations that possess
certain properties occurring frequently both in
real life and in mathematics. - Special relations
- Reflexiver(X,X) - t(X).
- Symmetricr(X,Y) - r(Y,X).
- Anti-symmetric- r(X, Y) , r(Y,X), X ltgt Y.
- Transitiver(X,Z) - r(X, Y), r(Y, Z).
- Asymmetric- r(X, Y) , r(Y,X).
- Unlike prolog, ASP will not suffer from
termination problem when dealing with the above
relations.
24Logic Programming with Answer Set Semantics
- A.1 Logic Programming
- A.2 Answer Set Programming
- A.3 Scenario
- A.4 Java Rule Engine
25Motivation
- The complexity and the pace of change of
application are increased - Business rules are complex and voluminous
- Business rules change rapidly
- Lightweight processes are not responsible enough
- Rules should be separate from data and code
- Managing business rules as assets
- Deploying rules from repository to production
need to be defined and supported by tools - Application infrastructure must accommodate
business rule engines without refactoring - Rule Engine
- A standard semantics language for stock analysis
to simplify writing rules - Handle lots of volatile business logic
- Provides an extremely fast decision-making
algorithm - Java rule engine is a way out to integrate
declarative programming paradigm and imperative
programming paradigm.
26Scenario
- IT managers
- Make the most of application development
resources. With rule engines, implementation
teams respond quickly to changing conditions.
Developers concentrate on complex tasks while
business analysts and policy managers perform
rule authoring and editing. Teams leverage faster
decision-making. - Business managers
- Increase agility throughout the enterprise.
Achieve higher levels of operational efficiency,
reduce costs and increase revenue. Relying on
rule engines business rule management, companies
spread best practices throughout the
organization. - Technical managers
- Optimize usability and performance. Leverage
business rule agility without compromising system
integration or interoperability. Rule engine
components can fit into the most popular
application infrastructures, supporting open
architecture and standards. - Policy managers
- Control policy implementation as business rules
in critical applications. Rule engine expresses
policies and regulations as business rules.
Tracing and updating the rules as policies and
regulations change. - Business analysts
- Guide business policies through implementation.
Rule engine expresses policies and regulations as
business rules. Tracing and updating rules as
policies and regulations change, policy owners
retain accountability and responsibility for
implementation. - Developers
- Streamline policy implementation efforts. Rule
engine expresses policy modeling and
implementation as business rules. Rules and code
are kept separate from applications for
management and maintenance, greatly reducing
developer overhead.
27Java Community Process JSR-94 - the Java Rule
Engine API
- JSR-94 is a completed standard and defines a
number of interfaces that a Java developer can
use to interact with a Java rule engine. - creating a stateful interaction with a rule
engine - creating a stateless interaction with a rule
engine - deploying an executable set of rules from a
variety of sources and registering them for
execution - undeploying rules
- Implementation
- ILOG JRules
- Fair Isaac Blaze Advisor
- Yasutech QuickRules
- Computer Associates, CleverPath Aion
- Drools
- OpenRules
- Sandia Labs, Jess
- Pegasystems PEGARules
- Those algorithms of the implementations are less
expressive and efficient than Answer Set
Programming.
28B. Logic and Databases
- B.1 Datalog
- B.2 Relational Databases and Datalog
- B.3 Relational Algebra and Datalog
- B.4 Define Pattern
29Datalog
- Datalog is a subclass of logic programs
- Absence of functors so that has a finite domain.
- Allow only safe rules.
- Consisting of
- Extensional Database stored table.
- Intensional Database relations defined by
rules. - Example
father (peter, adam). father (tom, anne). father
(adam, bill). father (adam, beth). mother (cathy,
adam). mother (mary, anne). mother (anne,
bill). mother (anne, beth). parent (X, Y) -
father (X, Y). parent (X, Y) - mother (X,
Y). ancestor (X, Y) - parent (X, Y). ancestor
(X, Y) - parent (X, Z), ancestor (Z, Y).
30B. Logic and Databases
- B.1 Datalog
- B.2 Relational Database and Datalog
- B.3 Relational Algebra and Datalog
- B.4 Pattern
31Relational Database
- Domain
- Let D1, D2, , Dn be collections of symbols
called domains. - Domains are assumed to be finite.
- The members of the domains are atomic and
indivisible. - Relation
- A relation R over the domains D1, D2, , Dn is a
subset of D1D2Dn. - R is said to be n-ary.
- Relational Database
- A finite number of relations.
- Example
FATHER
MOTHER
32Extensional Database
- Domain
- Datalog has only a single domain.
- Domains are finite because of lacking functors.
- A typed logic program is proposed by Lloyd to
avoid single domain. - Relation
- The notation R(A1, A2, , An) is used to describe
the name, R, and attributes ltA1, A2, , Angt of a
database relation. - Relation scheme.
- Extensional Database portion of Datalog
- Consists solely set of facts called extensional
database (EDB). - Example
father (peter, adam). father (tom, anne). father
(adam, bill). father (adam, beth). mother (cathy,
adam). mother (mary, anne). mother (anne,
bill). mother (anne, beth).
33Relational Databases vs. Datalog
- Datalog have only a single domain consisting of
terms while relational database has a notion of
type. - Despite this difference, it should be clear that
any relational database can be represented as a
Datalog consisting a set of facts.
Relational Database
Logic Program
FATHER
father (peter, adam). father (tom, anne). father
(adam, bill). father (adam, beth). mother (cathy,
adam). mother (mary, anne). mother (anne,
bill). mother (anne, beth).
MOTHER
34B. Logic and Databases
- B.1 Datalog
- B.2 Relational Databases and Datalog
- B.3 Relational Algebra and Datalog
- B.4 Pattern
35Relational Algebra
- View
- A relation that is created by means of operations
on existing database relations and other views. - Query Language
- Described by query language which is compiled
into relational algebra. - Relational Algebra
- Primitive operations are union, set difference,
Cartesian product, projection and selection - Example
- select from father, mother
PARENT View
36Datalog
- View
- Explicit data are called extensional database
whereas implicit data are so-called views. - Logic as a Query Language
- Consists of rules and non-ground facts called
intensional database (IDB). - Logic provides a uniform language for
representing both explicit data and implicit
data. - Logic Deduction
- Logic programs facilitate definition of new
atomic formulas that are deduced from extensional
database. - So logic programs are often referred to deductive
databases, which is a combination of extensional
database and intensional database. - Example
intensional database parent (X, Y) - father
(X, Y). parent (X, Y) - mother (X, Y).
deduced facts parent (peter, adam). parent
(tom, anne). parent (adam, bill). parent (adam,
beth). parent (cathy, adam). parent (mary,
anne). parent (anne, bill). parent (anne, beth).
37Relational Algebra vs. Datalog
- Datalog is strictly more powerful than relational
algebra. - Relational algebra can be used as an operational
semantics of a Datalog without recursive
predicates.
Relational Algebra
Datalog
Union ltx1,, xngt ltx1,, xngt?R1?ltx1,,
xngt?R2 Difference ltx1,, xngt ltx1,, xngt
?R1?ltx1,, xngt!?R2 Cartesian product ltx1,, xn,
y1,, yngt ltx1,, xngt?R1?lty1,, yngt?R2 Natral
Join ltx1,, xi, y1,, yjgt ltx1,,
xigt?R1?lty1,, yjgt?R2?get rid of the same
column Projection ltx1gt ltx1,x2gt?FATHER Selecti
on ltx1,, xngt ltx1,, xngt ?R ?F is true for
ltx1,, xngt
Union r(X1,...,Xn) - r1(X1,...,Xn). r(X1,...,Xn)
- r2(X1,...,Xn). Difference r(X1,...,Xn) -
r1(X1,...,Xn), not r2(X1,...,Xn). Cartesian
product r(X1,...,Xn , Y1,, Yn) - r1(X1,...,Xn),
r2(Y1,...,Yn). Natral Join r(X, Y, Z) - r1(X,
Y), r2(Y,Z). Projection father(X) - father(X,
Y). Selection millionaire(X,Y) - income(X,Y), Y
gt 1000000.
38Recursion
- Datalog with Recursion
- Non-recursive rules are equivalent to the core
relational algebra. - With recursion, Datalog can express more than
these languages. - Yet still not Turing-complete
- Example
- ancestor (X, Y) - parent (X, Y).
- ancestor (X, Y) - parent (X, Z), ancestor (Z,
Y). - Extended Relational Algebra with Recursion
- Recursion has been added to SQL99 by the WITH
statement. - WITH r AS d q, where r is a relation scheme, d a
query defining r and q a query using r. If r
appears in d, then the keyword RECURSIVE is
required after WITH. - Implemented by DB2, Oracle9i release 2, SQL
Server.
39Performance Results - A Chain of Simple Rules
- Simple rules p1 - p0, p2 - p1, ...
- Each predicate fact table contains 1000 values
40Performance Results - A Chain of Complex Rules
- Fibonacci like rules p1 - p0, p2 - p1 v p0, p3
- p2 V p1, ... - Each predicate fact table contains 1000 values
41Performance Results - Recursive Rules
- Compute a transitive predicate
- Predicate fact table contains 1000 values
42B. Logic and Databases
- B.1 Datalog
- B.2 Relational Databases and Datalog
- B.3 Relational Algebra and Datalog
- B.4 Pattern
43Represent Pattern with Answer Set Programming
- Expressiveness of Answer Set Programming
- Logic programs are strictly more powerful than
relational algebra. - Higher level of abstraction than the view of
relational database. - Logic programs have two distinguishing
auto-epistemic operators - not
- or
- Logic program is able to mimic
- Finite Automata, Mealy Machine, Moore Machine
- Pushdown Automata
- Turing Machine
- Efficiency of Answer Set Programming
- Answer Set Programming is very fast by the boost
development of both CSP and SAT techniques. - But few work has been done to deal with massive
data processing. - Based on relational database?
- Can SAT Solver handle quantitative data?
- It is obvious that pattern representation with
Answer Set Programming will be of extremely
useful because of its expressiveness and
efficiency.
44Guarantee of Affiliated Enterprise Pattern
45Security Fraud Pattern
46Money Laundering Pattern
47C. Combining Ontology with Logic Programming
- C.1 Introduction
- C.2 Description Logic Program
- C.3 Mapping Ontology to Logic Programming
48Introduction
- Motivation
- Interoperate, semantically and inferentially,
between the leading Semantic Web approaches to
rules (RuleML Logic Programs) and ontologies
(OWL/DAMLOIL Description Logic) via analyzing
their expressive intersection. - Build rules on top of ontologies.
- Build ontologies on top of rules.
- Enables available efficient LP inference
algorithms to be exploited for reasoning over
large-scale DL ontologies.
49Layering in the Semantic Web Stack
- Semantic Web can be viewed as KR meets the Web.
- A broad consensus has evolved in specifications
of rules and ontologies. - The key is to be able to layer rules on top of
ontologies - Create and reason with rule bases that mention
vocabulary specified by ontological knowledge
bases - In a semantically coherent and powerful manner.
50Knowledge Representation
- Ontology Language
- DAMLOIL
- OWL
- Decidable fragments of FOL closely related to
propositional modal and dynamic logics. - Rule Language
- RuleML
- Horn logic program
- A large fragment of Horn FOL.
51C. Combining Ontology with Logic Programming
- C.1 Introduction
- C.2 Description Logic Program
- C.3 Mapping Ontology to Logic Programming
52Description Logic Program
- Intersection of Description Logic and Horn Logic
Programs - Statements
- Constructors
- Query
First Order Logic
Description Logic
Horn LogicPrograms
Logic Programs
Description Logic Program
naf
procedure
53Mapping Description Logic to Logic Programs
- Expressive Restrictions
- Definite Horn logic program requires that all
variables are universally quantified. - No negation may appear within the body of a rule,
nor within the head. - Mapping Statements
- RDFS Statements
- DAMLOIL statements
- Mapping Constructors
- Conjunction
- Disjunction
- Negation and Cardinality Restrictions (not
general) - Mapping Query
- Class-instance membership queries
- Class subsumption queries
- Class hierarchy queries
- Class satisfiability queries
54C. Combining Ontology with Logic Programming
- C.1 Introduction
- C.2 Description Logic Program
- C.3 Mapping Ontology to Logic Programming
55Mapping Ontology to Logic Programming
56D. Data Mining with Inductive Logic Programming
- D.1 _at_todo
- D.2 _at_todo
- D.3 _at_todo
57E. Java Rule Engine
- E.1 _at_todo
- E.2 _at_todo
- E.3 _at_todo
58E. Architecture
- Rule engine facilitates
- Pattern Engine module
- Pattern module
Data Source
Consolidated Data
Pattern Engine
Pattern
Comecial Database
__________________________________________________
____
Ontology
Rules
Pattern Engine
__________________________________________________
____
Rules
Database
Desktop Database
__________________________________________________
____
Rules
Network Database
__________________________________________________
____
Rules