Prolog ​
New Programming Paradigm: Logical Programming. 💃
Components:
- Knowledge Base: specified by programmer. Logical statements.
- Inference Engine: Given. Derives new knowledge from the knowledge base.
Horn Clauses ​
Logical statements in Prolog are restricted to horn clauses.
Horn Clause
A disjunction (or) of literals with at most 1 positive literal.
For example:
This is equivalent to a conjunction of atoms as the antecedent and a single atom as the conclusion.
Forward Chaining ​
Apply modus ponens to see what can be derived from a set of rules and atomic propositions.
Example
Knowledge Base:
Forward Chaining:
Backward Chaining ​
Starting from the goal and reason backwards. Used In Prolog !
Example
Knowledge Base:
Backward Chaining
- a. (a is the goal, what we want to prove)
- a is true if b and c are true.
- d implies b
- d is true and c is true.
- done.
Backwards Chaining is based on the resolution rule:
Example
Knowledge Base
Resolution
Prolog Syntax ​
Two types of statements:
- Facts: horn clauses consisting of a single positive literal
- ex: p, q
- Rules: horn clauses with one positive literal and one or more negative literals.
- ex:
- in rule form
- ex:
Syntax
- All statements end with a dot
.
- Implication (
) is represented with :-
- Conjunction denoted as comma
,
Example: r :- p, q.
% knowledge base
a :- b,c.
b :- d.
d.
c.
prompt: ?- a.
output: true.