Chapter 3 Flashcards

1
Q

Constants

A

Must start with a lower letter which can be followed by letters, underscores or digits.
It can also be a quoted string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Quoted string

A

Any string of characters (other than single quote) enclosed within single quotes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Are these allowed constants in Prolog?

  1. George
  2. granny_sarah
  3. ‘Hello world’
  4. ’ _ ‘
A
  1. No
  2. Yes
  3. Yes
  4. Yes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Variables

A

Can start with uppercase and can be followed by any number of letters, underscores and digits

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Atomic sentences (or atoms)

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Think of two examples of correct Prolog atomic sentences in the KB.

A
  1. child(john, sue)

2. my_car(red, ‘bmw’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Conditional sentences (clauses)

A

structure –> head :- body1, … , bodyN
head –> Prolog atom (then..)
body –> Prolog atom (if…)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Think of an example of a Prolog conditional sentence

A

sister(X, Y) :- female(X), person(Y), sibling(X, Y)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What would be a case where an atomic sentence is just a special case of a conditional sentence?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

A Prolog program is a sequence of …

A

clauses

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Prolog clauses can be …

A

atomic/conditional sentences

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Where can spaces, newlines and comments be inserted in a Prolog program?

A
  1. at the end of a program or

2. just before a constant or a variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Comments can be added followed by the character…

A

%

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the goal of Prolog by answering a query?

A

To establish whether there is a relationship between the query and the KB

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Query

A

Atom with/without variables terminated by a period.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the 3 possible outputs when posing a query WITHOUT variables?

A

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

17
Q

What are the 3 possible outputs when posing a query WITH variables?

A
  1. Prolog displays the values of the variables for which the query can be established.
  2. No - the aim cannot be established for any values of the variable
  3. No answer, still looking
18
Q

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:

A
  1. press space/return, which will output “Yes” and complete the query answering
  2. Type semicolon, which will prompt Prolog to look for further variables outcomes
19
Q

Conjunctive queries

A

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.

20
Q

When are conjunctive queries particularly helpful?

A

When a variable appears in more than one atom in the query

21
Q

What is this symbol used for in Prolog? “+”

A

Negation in queries

22
Q

If a line in Prolog starts with “Call”, what does it mean?

A

Prolog starts to work on an atomic sentence

23
Q

If a line in Prolog starts with “Fail”, what does it mean?

A

An atomic query has failed and Prolog needs to look for alternatives

24
Q

If a line in Prolog starts with “Exit”, what does it mean?

A

An atomic query has tentatively succeeded, pending the remaining conjunctive query

25
Q

If a line in Prolog starts with “Redo”, what does it mean?

A

Prolog has gone back to a choice point to reconsider an atomic query

26
Q

When dealing with a negated query, will Prolog consider the negation during the back-chaining or will it drop it?

A

It will drop it and attempt to look for a matching atomic sentence: if it does, the it will return SUCCEED and the negated query will fail. Go back to the most recent choice point and reconsider.

27
Q

Uninstantiated variable

A

It does not have a tentative value yet

28
Q

Instantiated variable

A

Has a tentative value

29
Q

What should we make sure to do when variables appear in a negated query?

A

We should make sure that they are already instantiated at an earlier stage of the back-tracking. Practically, use another atom in the query BEFORE the negated part.

30
Q

When does an equality hold in Prolog?

A

When the two terms (constants or variables) can be made equal by instantiating any variables

31
Q

Is an equality or inequality more useful in Prolog?

A

Inequality

32
Q

How can we interpret this program?

male(X), male(Y), male(Z) , + X = Y, + X = Z, + Y = Z

A

A program that defines a new predicate “male” that holds when three people X, Y and Z are different people and are all males.

33
Q

Unification

A

Clauses in a program are selected during back-chaining via a matching process called unification.

34
Q

Two atoms whose variables are distinct are said to “unify” when…

A

there is a substitution of values for the variables that makes the atoms identical.

35
Q

Will these atoms unify?

  1. p(b, X, b) and p(Y, a, b) for X = a, Y = b
  2. p(X, b, X) and p(a, b, Y) for X = a, Y = a
  3. p(X, b, X, a) and p(Y, Z, Z, Y)
A

yes
yes
no ( the 2 occurrences of X force Y and Z to be equal, but they must also match a and b respectively)

36
Q

Why is it important to rename a variable in a query with a name that is not in the KB?

A

Because we might lose some unifications that would be possible if the name of the variables were different.