0% found this document useful (0 votes)
444 views2 pages

Some Simple Prolog Examples

The document provides examples of using Prolog to represent simple facts and relationships between individuals. It includes: 1) Basic facts about who likes what expressed as clauses 2) A more complex family tree represented as clauses defining relationships like parent, male, female between family members like James I, Charles I, etc. 3) Examples of queries to retrieve information from the knowledge base like "Who were Charles I's parents?" 4) An exercise to define additional relationships like mother, father, sibling, aunt, uncle, grandparent, and cousin in terms of the basic parent and gender facts.

Uploaded by

joematiku03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
444 views2 pages

Some Simple Prolog Examples

The document provides examples of using Prolog to represent simple facts and relationships between individuals. It includes: 1) Basic facts about who likes what expressed as clauses 2) A more complex family tree represented as clauses defining relationships like parent, male, female between family members like James I, Charles I, etc. 3) Examples of queries to retrieve information from the knowledge base like "Who were Charles I's parents?" 4) An exercise to define additional relationships like mother, father, sibling, aunt, uncle, grandparent, and cousin in terms of the basic parent and gender facts.

Uploaded by

joematiku03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Some simple Prolog Examples

--------------------------1. Here are some simple clauses.


likes(mary,food).
likes(mary,wine).
likes(john,wine).
likes(john,mary).
The following queries yield the specified answers.
| ?- likes(mary,food).
yes.
| ?- likes(john,wine).
yes.
| ?- likes(john,food).
no.
How do you add the following facts?
1. John likes anything that Mary likes
2. John likes anyone who likes wine
3. John likes anyone who likes themselves
==========================================================================
2. Slightly more complicated family tree.
James I
|
|
+----------------+-----------------+
|
|
Charles I
Elizabeth
|
|
|
|
+----------+------------+
|
|
|
|
|
Catherine
Charles II
James II
Sophia
|
|
|
George I
Here are the resultant clauses:
------------------------------male(james1).
male(charles1).

male(charles2).
male(james2).
male(george1).
female(catherine).
female(elizabeth).
female(sophia).
parent(charles1, james1).
parent(elizabeth, james1).
parent(charles2, charles1).
parent(catherine, charles1).
parent(james2, charles1).
parent(sophia, elizabeth).
parent(george1, sophia).
Here is how you would formulate the following queries:
Was George I the parent of Charles I?
Query: parent(charles1, george1).
Who was Charles I's parent?
Query: parent(charles1,X).
Who were the children of Charles I?
Query: parent(X,charles1).
Now try expressing the following rules:
M is the mother of X if she is a parent of X and is female
F is the father of X if he is a parent of X and is male
X is a sibling of Y if they both have the same parent.
Furthermore add rules defining:
"sister", "brother",
"aunt", "uncle",
"grandparent", "cousin"
====================================================================

You might also like