Week 7 Flashcards

(14 cards)

1
Q

What is the “is” operator in Prolog?

A

Arithmetic is carried out by the “is operator in Prolog

eg. R is 14 + 2 (or you could do: 14 +2 = R) so R will be 16

If the left argument is an unbound variable, bind it to the result of evaluating the right argument, then succeed

If the left argument is a number, or a bound variable with a numerical value, succeed if the right argument has the same numerical value

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

What are some Arithmetic Functions of Prolog?

A

abs(N, X) - absolute value of N

sin(N, X) - sine of N (in radians)

cos(N, X) - cosine of N (in radians)

log(N, X) - natural logarithm of N

sqrt(N, X) - square root of N1

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

What are Unification Operators and Algorithm (used in Prolog)?

A

X = Y - X and Y can be unified

X = Y - X and Y cannot be unified

Unified means make the same

The unification algorithm is used for matching

The algorithm considers:

  1. numbers
  2. atoms
  3. variables
  4. compound terms
  5. lists
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How does Unification work with Numbers in Prolog?

A

Two Numbers unify if and only if they are the same

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

How does Unification work with Atoms in Prolog?

A

Two Atoms unify if and only if they are the same (exact same sequence of letters)

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

How does Unification work with Variables in Prolog?

A

Two unbound variables always unify, with the variables bound to each other

An unbound variable and a term that is not a variable always unify, with the variable bound to the term

eg. num = 3

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

How does Unification work with Compund Terms in Prolog?

A

Two compound terms unify if and only if they have the same functor, and the same arity, and their arguments can be unified pairwise, working from left to right

eg.

f(1,4) does not equal g(1,4) different functor

f(1,4) does not equal f(4,5) different arity

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

How does Unification work with Lists in Prolog?

A

Two lists unify if and only if they have the same number of elements and their elements can be unified pairwise, working from left to right

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

What is the Logical Negation Operator in Prolog?

A

The only logical negation operator is:

+ X not X

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

What is the If-then-else construct in Prolog?

A

Like python if statements but in Prolog

eg.

maxOf(X, Y, Z)
:- ( X =< Y
-> Z = Y
; Z = X
).

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

What is Backtracking in Prolog?

A

If any goal fails, the Prolog system tries to find another way of satisfying the most recently satisfied previous goal

This is known as Backtracking

eg.

stings(X)
stings(Y)
stings(Z)

If X is false it evaluate Y and so on. If all of them are false it will return false

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

Closed World Assumption: Things that arent stated to be True are False

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

What is a good property of Permutations in Prolog?

A

Successive permutations of 2-of-three and 3-of-three digits may be obtained by back-tracking

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