Chapter 3 Flashcards
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?
- George
- granny_sarah
- ‘Hello world’
- ’ _ ‘
- No
- Yes
- Yes
- Yes
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.
- child(john, sue)
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?
- at the end of a program or
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?
- Prolog displays the values of the variables for which the query can be established.
- No - the aim cannot be established for any values of the variable
- No answer, still looking
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:
- press space/return, which will output “Yes” and complete the query answering
- Type semicolon, which will prompt Prolog to look for further variables outcomes
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