skip to Main Content

I know this is probably a stupid question, but I’m just reading the first chapter of Bratko Prolog Programming for artificial intelligence.

One of the first programs has clauses like

parent(ann, pat).

My question: parent, is that something that is built in to Prolog? Or is it something that is dealt with dynamically. Can I just go and invent things like:

dog(ann, pluto).

2

Answers


  1. Yes, you can invent things like that. It is called clauses, this type of clauses is called facts. Facts are what your database is made of in Prolog. When you say

    dog(ann, pluto).
    

    you define relationship dog between two objects ann and pluto, these objects are called atoms and they are constant.
    You can then query your database

    | ?- dog(ann, pluto).
    yes
    

    Prolog will tell you if there is no defined relationship in database

    | ?- dog(ann, oleg).
    no
    
    Login or Signup to reply.
  2. Yes. The simple answer is that you can just invent things like.

    dog(ann, pluto).
    

    These are simple FACTS that prolog will hold in its internal database. This is not a relational database. Just a collection of FACTS.

    parent is not build into Prolog.

    What make it interesting and useful is that you can create various rules to expand and confirm relationships for you.

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

    Then you can ask

    grandparent(ann,florence)
    

    which will succeed it it is true, or fail if not.

    Or you could ask

    grandparent(ann,X)
    

    and prolog should try and find and print out all grandparents of ann

    or if you extend your FACTS base to include

    mother(ann, jane)
    father(ann, jim)
    mother(jane, janice)
    etc
    etc
    

    then

    grandmother(X,Z) :-  mother(X,Y), mother(Y,Z).
    

    can be deduced.

    Suggest you keep on reading your book and all will be revealed.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search