2. 4/15/202
0
2
Outline What is a deductive database system?
•Some basic concepts
•Basic inference mechanism for logic programs
•Datalog programs and their evaluation
Nikhil Sharma , ME CSE , UIET
3. 4/15/202
0
Nikhil Sharma , ME CSE , UIET 3
Under the supervision of Subject- Incharge
Dr. Mamta Juneja
(Assistant Professor)
at
Dept. of Computer Science and Engineering,
UIET, PU, Chandigarh 160014
a
power point presentation
created and presented by
Nikhil Sharma ( 19-311)
M.E CSE 1st Year
in
session July – Dec 2019.
4. 4/15/202
0
4
•What is a deductive database system?
A deductive database can be defined as an
advanced database augmented with an inference
system.
Database + Inference
Deductive
database
By evaluating rules against facts, new facts can be derived, which in turn
can be used to answer queries. It makes a database system more powerful.
Nikhil Sharma , ME CSE , UIET
5. 4/15/202
0
5
- term
A term is a constant, a variable or an expression of
the form f(t1, t2, ..., tn), where t1, t2, ..., tn are terms
and f is a function symbol.
- Example: a, b, c, f(a, b), g(a, f(a, b)), x, y, g(x, y)
- n-ary predicate
An n-ary predicate symbol is a symbol p appearing
in an expression of the form p(t1, t2, ..., tn), called an
atom, where t1, t2, ..., tn are terms. p(t1, t2, ..., tn) can
only evaluate to true or false.
- Example: p(a, b), q(a, f(a, b)), p(x, y)
IMPORTANT TERMS
Nikhil Sharma , ME CSE , UIET
6. 4/15/202
0
6
- literal
A literal is either an atom or its negation.
- Example: p(a, f(a, b)), p(a, f(a, b))
- (well-formed) formula
- A well-formed (logic) formula is defined
inductively as follows:
- An atom is a formula.
- If P and Q are formulas, then so are P, (PQ),
(PQ), (PQ), and (PQ).
- If x is a variable and P is a formula containing x,
then (xP) and (xP) are formulas.
Nikhil Sharma , ME CSE , UIET
7. 4/15/202
0
7
- clause
- A clause is an expression of the following form:
A1 A2 ... An B1 ... Bm
where Ai and Bj are atoms.
- The above expression can be written in the
following equivalent form:
B1 ... Bm A1 ... An
or
B1, ..., Bm A1 , ..., An
antecedent
consequent
Nikhil Sharma , ME CSE , UIET
8. 4/15/202
0
8
- clause
A BA B
1 0 0
1 1 1
0 1 1
0 0 1
B AA B
1 0 0
1 1 1
0 1 1
0 0 1
- Horn clause
A Horn clause is a clause with the head containing only
one positive atom.
Bm A1 , ..., An
Nikhil Sharma , ME CSE , UIET
9. 4/15/202
0
9
- fact
- A fact is a special Horn clause of the following form:
B
with all variables in B being instantiated. (B can be
simply written as B.)
- logic program
A logic program is a set of Horn clauses.
Nikhil Sharma , ME CSE , UIET
10. 4/15/202
0
10
Example (a logic program)
Facts:
supervise(franklin, john),
supervise(franklin, ramesh),
supervise(franklin, joyce)
supervise(james, franklin),
supervise(jennifer, alicia),
supervise(jennifer, ahmad),
supervise(james, jennifer).
Rules:
superior(X, Y) supervise(X, Y),
superior(X, Y) supervise(X, Z), superior(Z, Y),
subordinary(X, Y) superior(Y, X).
james
franklin jennifer
john ramesh joyce alicia ahmad
Nikhil Sharma , ME CSE , UIET
11. 4/15/202
0
11
Facts can be considered as the data stored as relations in a
relational database.
Nikhil Sharma , ME CSE , UIET
12. 4/15/202
0
12
•Basic inference mechanism for logic programs
- interpretation of programs (rules + facts)
There are two main alternatives for interpreting the theoretical
meaning of rules:
proof theoretic, and
model theoretic interpretation
proof theoretic interpretation
1. The facts and rules are considered to be true statements,
or axioms.
facts - ground axioms
rules - deductive axioms
2. The deductive axioms are used to construct proofs that
derive new facts from existing facts.
Nikhil Sharma , ME CSE , UIET
14. 4/15/202
0
19
Inference mechanism
In general, there are two approaches to evaluating logical
programs: bottom-up and top-down.
Bottom-up mechanism
(also called forward chaining and bottom-up resolution)
1. The inference engine starts with the facts and applies
the rules to generate new facts. That is, the inference
moves forward from the facts toward the goal.
2. As facts are generated, they are checked against the
query predicate goal for a match.
Nikhil Sharma , ME CSE , UIET
15. 4/15/202
0
20
- Example
query goal: superior(james, Y)?
rules and facts are given as above.
1. Check whether any of the existing facts directly matches the
query.
2. Apply the first rule to the existing facts to generate new facts.
3. Apply the second rule to the existing facts to generate new
facts.
4. As each fact is gnerated, it is checked for a match of the the
query goal.
5. Repeat step 1 - 4 until no more new facts can be found.
All the facts of the form: superior(james, a) are the answers.
Nikhil Sharma , ME CSE , UIET
16. 4/15/202
0
21
- Example:
1. superior(X, Y) supervise(X, Y). (rule 1)
2. superior(X, Y) supervise(X, Z), superior(Z, Y). (rule 2)
known facts:
supervise(franklin, john), supervise(franklin, ramesh),
supervise(franklin, joyce), supervise(james, franklin),
supervise(jennifer, alicia), supervise(jennifer, ahmad),
supervise(james, jennifer).
For all other possible (X, Y) combinations supervise(X, Y) is false.
domain = {james, franklin, john, ramesh, joyce, jennifer, alicia, ahmad}
superior(james, Y)?
applying the first rule: superior(james, franklin), superior(james, jennifer)
Y = {franklin, jennifer}
applying the second rule: Y = {John, Joyce, Ramesh, alicia, ahmad}
Nikhil Sharma , ME CSE , UIET
17. 4/15/202
0
22
Top-down mechanism
(also called back chaining and top-down resolution)
1. The inference engine starts with the query goal and
attempts to find matches to the variables that lead to
valid facts in the database. That is, the inference moves
backward from the intended goal to determine facts that
would satisfy the goal.
2. During the course, the rules are used to generate
sub-goals. The matching of these sub-goals will lead to
the match of the intended goal.
Nikhil Sharma , ME CSE , UIET
18. 4/15/202
0
23
- Example
query goal: ?-superior(james, Y)
rules and facts are given as above.
Query: ?-superior(james, Y)
Rule1: superior(james, Y)
supervise(james, Y)
Rule2: superior(james, Y)
supervise(james, Z),
superior(Z, Y)
supervise(james, Z)
superior(franklin, Y) superior(jennifer, Y)
Y=franklin, jennifer
Z=frankiln Z=jennifer
Nikhil Sharma , ME CSE , UIET
20. 4/15/202
0
25
•Datalog programs and their evaluation
1. A Datalog program is a logic program.
2. In a Datalog program, each predicate contains no
function symbols.
3. A Datalog program normally contains two kinds of
predicates: fact-based predicates and rule-based
predicates.
fact-based predicates are defined by listing all the
combinations of values that make the predicate true.
Rule-based predicates are defined to be the head of one or
more Datalog rules. They correspond to virtual relations
whose contents can be inferred by the inference engine.
Nikhil Sharma , ME CSE , UIET
21. 4/15/202
0
26
•Datalog programs and their evaluation
Example:
- All the programs discussed earlier are Datalog
programs.
superior(X, Y) supervise(X, Y).
superior (X, Y) supervise(X, Z), superior (Z, Y).
supervise(jennifer, ahmad).
supervise(james, jennifer).
- The following is a logic program, but not a
Datalog program:
p(X, Y) q(f(Y), X)
Nikhil Sharma , ME CSE , UIET
22. 4/15/202
0
27
•Datalog programs and their evaluation
two important concepts:
- safety of programs
- predicate dependency graph
Nikhil Sharma , ME CSE , UIET
23. 4/15/202
0
28
•Datalog programs and their evaluation
- Safety of programs
A Datalog program or a rule is said to be safe if it
generates a finite set of facts.
- Condition of unsafety
A rule is unsafe if one of the variables in the rule can range
over an infinite domain of values, and that variable is not
limited to ranging over a finite predicate before it is
instantiated.
- Example:
big_salary(Y) Y > 60000.
big_salary(Y) Y > 60000, employee(X), salary(X, Y).
Nikhil Sharma , ME CSE , UIET
24. 4/15/202
0
29
•Datalog programs and their evaluation
- Example: ?-big_salary(Y)
big_salary(Y) Y > 60000.
big_salary(Y) Y > 60000, employee(X), salary(X, Y).
The evaluation of these rules (no matter whether in bottom-
up or in top-down fashion) will never terminate.
The following is a safe rule:
big_salary(Y) employee(X), salary(X, Y), Y > 60000.
Nikhil Sharma , ME CSE , UIET
25. 4/15/202
0
30
•Datalog programs and their evaluation
A variable X is limited if
(1) it appears in a regular (not built-in) predicate in the body of the
rule.
(built-in predicates: <, >, , , =, )
(2) it appears in a predicate of the form X = c or c = X, where c is
a constant.
(3) it appears in a predicate of the form X = Y or Y = X in the rule
body, where Y is a limited variable.
(4) Before it is instantiated, some other regular predicates containing
it will have been evaluated.
- Condition of safty:
A rule is safe if each variable in it is limited.
A program is safe if each rule in it is safe.Nikhil Sharma , ME CSE , UIET
26. 4/15/202
0
31
What We Have Covered !!
1. Definition
2. Terms- predicate , literal , clause
3. Logical Program
/
/ /
4. Inference Mechanism
/
proof model (theoretic interpretation)
5. Inference Mechanism evaluation
/
bottom-up top-down
6. Datalog Program and evaluation
Nikhil Sharma , ME CSE , UIET
27. 4/15/202
0
Nikhil Sharma , ME CSE , UIET 32
Applications
1. LDL (Logic Data Language)
• This domain involves modeling the structure, processes, and
constraints within an enterprise.
• Hypothesis testing or data dredging
2. NAIL (Not Another Implementation of Logic)
3. CORAL
4. VALIDITY
data model and language called DEL ( Datalog Extended Language),
an engine working along a client-server model and a set of tools for
schema and rule editing, validation, and querying.
Electronic commerce:
Rules-governed processes:
Knowledge discovery:
Concurrent Engineering:
29. 4/15/202
0
Nikhil Sharma , ME CSE , UIET 34
In recent years, deductive databases such as
Datalog have found new application in
1. data integration,
2. information extraction,
3. networking,
4. program analysis,
5. security,
6. cloud computing.
30. 4/15/202
0
Nikhil Sharma , ME CSE , UIET 35
Prolog is a logic programming language associated
with artificial intelligence and computational linguistics.
declarative programming language
Hal karne wala ( Resolver )
قیاسی Also called Quasi ( predictable)
Inference : a conclusion reached on the basis of evidence and reasoning. ( Niskarsh )
Axioms: a statement or proposition which is regarded as being established, accepted, or self-evidently true ( Apne aap mai sahi)
It says that a statement and its opposite cannot both be true at the same time and place
Hard work leads to success.