[Skip Navigation] [CSUSB] / [CNS] / [Comp Sci Dept] / [R J Botting] / [Samples] / prolog.semantics
[Index] [Contents] [Source Text] [About] [Notation] [Copyright] [Comment/Contact] [Search ]
Tue Sep 18 15:26:48 PDT 2007

Contents


    Prolog Semantics

    SEMANTICS

    1. QUESTIONS \ GOALS

    PROLOG statements are used to describe facts and rules that describe the relationships among these facts. Propositions are what the system tries to prove. PROLOG calls these proposition goals. A goal is true if, under the given database, the facts and relationships have been proven to be true. For example, mother(jill,jack) would receive the response "yes" or "no". The "yes" response tells us the goal has been proven true.

    2. VARIABLES

    When Prolog binds a value to a variable, this is called instantiation. All variables begin unbounded (i.e. not assigned a value). As Prolog attempts to satisfy a truth, variables previously unbounded become bounded. These instantiations last as long as it takes to satisfy one goal. If we want to ask a program "Who does John like", we express this with a variable like X, Y. The query is ?- likes(john,X). If the database contains likes(john,flowers) then the system will respond with X = flowers.

    3. CONJUNCTIONS

    We can ask the program "Is there anything that both John and Mary like" by using ?- likes(mary,X),likes(john,X) where the comma stands for "and". PROLOG attempts to find an entry in the form of likes(mary,Something) and links X to "Something". The system tries to find an entry in the database: likes(john,Something). If no such entry is found, then the system backtracks and tries to find another fact that satisfies "likes(mary,Something)". If it finds one, then a new value of X is instantiated and the system tries to find "likes(john,X)" for the new value of X. It is important to be aware that the system performs all of this automatically.

    4. RULES

    Prolog uses the "B :- A" for "B if A". Rules have the form "consequence 'IF'condition(s)". This means that a certain consequence follows if the conditions hold. For example, the relationship "sister_of(X,Y)" can be defined as:

  1. sister_of(X,Y):-female(X),parents(X,M,F),parents(Y,M,F),X<>Y.

    which states that X is the sister of Y if X is a female and if X and Y have the same parents and are not the same person.

    5. FACTS

    likes(mary,john)

    valuable(gold)

    owns(john,gold)

    father(john,mary)

    6. BUILT-IN PREDICATES Prolog has a set of built-in predicates that enable the programmer to perform functions without spending unacceptable amounts of time trying to carry out procedures that are not efficient.

    They are listed in the file 'predicates' in my cs320/prolog directory.

    7. STRUCTURES WITH ARITHMETIC MEANINGS

    See the file 'expressions' in my cs320/prolog directory.

End