Prolog Knowledge Base

Terminology

·       Prolog expressions include terms, predicates, and queries.

expression ::= term | predicate | query

Think of predicates a terms as nouns, predicates as sentences, and queries as questions.

·       There are three types of terms: literals, variables, and structures.

term ::= literal | variable | structure

·       There are two types of predicates: facts and rules.

predicate ::= fact | rule

·       Terms denote entities in some domain such as a hospital, warehouse, or bank.

·       Predicates denote relationships in the domain.

·       A Prolog program, called a knowledge base (K-Base), is a list of facts and rules about the domain.

Example

The Simpsons Domain:

·       Entities = {Bart, Lisa, Maggie, Homer, Marge}

·       Relationships = {Male, Female, Parent, Father, Mother, Son, Daughter}

A Simpsons knowledge base:

male(homer).
male(bart).
male(abe).

female(marge).
female(lisa).
female(maggie).
female(mona).

parent(homer, bart).
parent(homer, lisa).
parent(homer, maggie).
parent(marge, bart).
parent(marge, lisa).
parent(marge, maggie).
parent(abe, homer).
parent(mona, homer).

mother(X, Y) :- parent(X, Y), female(X).
father(X, Y) :- parent(X, Y), male(X).
son(X, Y) :- parent(Y, X), male(X).
daughter(X, Y) :- parent(Y, X), female(X).

grandparent(X, Y) :- parent(X, Z), parent(Z, Y).

Notes:

1. The literal terms bart, lisa, maggie, homer, and marge respectively denote the domain entities Bart, Lisa, Maggie, Homer, and Marge.

2. The predicate names male, female, parent, father, mother, son, and daughter respectively denote the domain relationships Male, Female, Parent, Father, Mother, Son, and Daughter.

3. Predicates and literals always begin with lowercase letters. Variables begin with uppercase letters.

4. Male and Female are unary relationships. The others are binary relationships.

5. The fact parent(homer, bart) asserts that Homer is the Parent of Bart. Or more formally, that the pair of entities (Homer, Bart) is an element of the binary Parent relationship.

6. A rule has the form:

fact :- fact, ..., fact

The fact to the left of the "if" symbol (":-") is called the conclusion or head of the rule. The facts on the right are called the conditions or tail of the rule. We interpret comma to mean "and".

For example, the rule

mother(X, Y) :- parent(X, Y), female(X).

asserts that for any entities X and Y, X is the Mother of Y if X is the parent of Y and X is female.

7. Variables appearing in a rule-conclusion are universal (all), while variables appearing only in the condition of a rule are existential (some).

For example, the rule:

grandparent(X, Y) :- parent(X, Z), parent(Z, Y).

Asserts:

For all X and Y, grandparent(X, Y) if for some Z parent(X, Z) and parent(Z, Y).