Constants
Must start with a lower letter which can be followed by letters, underscores or digits.
It can also be a quoted string.
Quoted string
Any string of characters (other than single quote) enclosed within single quotes
Are these allowed constants in Prolog?
Variables
Can start with uppercase and can be followed by any number of letters, underscores and digits
Atomic sentences (or atoms)
they have the following form:
predicate(argument1, …., argumentN)
where predicate = Prolog constant and
arguments = Prolog constants/variables
We always need parenthesis after the predicate unless it has 0 arguments
Think of two examples of correct Prolog atomic sentences in the KB.
2. my_car(red, ‘bmw’)
Conditional sentences (clauses)
structure –> head :- body1, … , bodyN
head –> Prolog atom (then..)
body –> Prolog atom (if…)
Think of an example of a Prolog conditional sentence
sister(X, Y) :- female(X), person(Y), sibling(X, Y)
What would be a case where an atomic sentence is just a special case of a conditional sentence?
A case where a conditional sentence has an empty body (“if” part)
Example:
sister(X, Y) :- nothing –> in this case, sister(X, Y) is just a special case of a conditional sentence.
A Prolog program is a sequence of …
clauses
Prolog clauses can be …
atomic/conditional sentences
Where can spaces, newlines and comments be inserted in a Prolog program?
2. just before a constant or a variable
Comments can be added followed by the character…
%
What is the goal of Prolog by answering a query?
To establish whether there is a relationship between the query and the KB
Query
Atom with/without variables terminated by a period.
What are the 3 possible outputs when posing a query WITHOUT variables?
Yes - the atom is established by back-chaining
No - the atom cannot be established by back-chaining
Nothing - Prolog is still looking for a relationship
What are the 3 possible outputs when posing a query WITH variables?
If the posed query contains variables and Prolog displays the values of the variables for which the query can be established, the user has two options:
Conjunctive queries
sequences of atoms separated by commas (which play the role of “and”) and terminated by a period. All atoms need to be established in order to return “Yes” by Prolog.
When are conjunctive queries particularly helpful?
When a variable appears in more than one atom in the query
What is this symbol used for in Prolog? “+”
Negation in queries
If a line in Prolog starts with “Call”, what does it mean?
Prolog starts to work on an atomic sentence
If a line in Prolog starts with “Fail”, what does it mean?
An atomic query has failed and Prolog needs to look for alternatives
If a line in Prolog starts with “Exit”, what does it mean?
An atomic query has tentatively succeeded, pending the remaining conjunctive query