# 4. Practice

Consider the Prolog database from the previous page:

1. Fact: spouse (john, jane)
2. Fact: spouse (david, mary)
3. Fact: spouse(george, susan)
4. Fact: female (jane)
5. Fact: female (mary)
6. Fact: female (susan)
7. Fact: male (john)
8. Fact: male (david)
9. Fact: male (george)
10. Rule: husband(A,B) IF spouse(A,B) AND male (A)
11. Rule: wife (A,B) IF spouse(A,B) AND female(B)

Now the database will be expanded to include some additional details. The following questions and answers help show how this is done.

Click on each question to see the answer

How would you write the fact 'Sandra is female'
female(sandra)
How could you write the fact 'Sandra and Mary are related'
related(mary,sandra)
Write a rule to check if two people are female family members
female_family(A,B) IF related(A,B) AND female(A) AND female(B)
Write a predicate statement to see if Sandra and Jane are related
female_family(jane,sandra)
False is returned
Write a predicate to find the Sandra's sister
female_family(A,sandra)
The answer is Mary i.e. the argument 'A' is instantiated to 'Mary' and the predicate is True
Click to view completed database
1. Fact: spouse (john, jane)
2. Fact: spouse (david, mary)
3. Fact: spouse(george, susan)
4. Fact: related(mary, sandra)
5. Fact: female (jane)
6. Fact: female (mary)
7. Fact: female (susan)
8. Fact: female(sandra)
9. Fact: male (john)
10. Fact: male (david)
11. Fact: male (george)
12. Rule: husband(A,B) IF spouse(A,B) AND male (A)
13. Rule: wife (A,B) IF spouse(A,B) AND female(B)
14. Rule: female_family(A,B) IF related(A,B) AND female(A) AND female(B)