Logic Programming Flashcards

1
Q

What is logic programming?

A

A declarative language paradigm that aims to separate a program into it’s logical component and it’s control component.

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

What is prolog naming convention for functions/relations?

A

All names start with a smaller case

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

What is the prolog convention for variable names?

A

All names start with a capital letter

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

What is the prolog symbol for left implication?

A

”:-“

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

What is universal quantification in prolog?

A

Variables in heads are universally quantified.
eg. snowy(X) :- rainy(X), cold(x).

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

What is the prolog symbol for conjunction?

A

”,”

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

What is an existential qualification in prolog?

A

Variables that only appear in the body.
eg. sameIsland(X, Z) :- in(X, Y), in(Z, Y)

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

How to denote negation in prolog?

A

”+”

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

How to denote a list in prolog?

A

[a, b, c]
[a | [b, c]

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

How to check list membership in prolog?

A

member(X, [X | ]).
member([x, [
| T]) :- member(X, T).

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

How to check if a list is sorted in prolog?

A

sorted([]).
sorted([_]).
sorted([a, b | T]) :- A =< B, sorted([B | T])

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

How to append an element in prolog?

A

append([], A, A).
append([H |T], A, [H |L]) :- append(T, A, L).
?- append([a, b, c], [d, e], L).
L = [a, b, c, d, e].
?- append(X, [d, e], [a, b, c, d, e]).
X = [a, b, c].

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

What is back chaining in prolog?

A

Starting with a query and working backwards, attempting to unresolved it in a set of pre-existing clauses

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

What is ordering in prolog?

A

During search, prolog considers clauses int he fixed order from first to last. Prolog programs do not have the same semantics as first order logic. Programmers must be careful with the order of clauses to ensure recursive programs will terminate.

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

What is cut in prolog?

A

The cut ! is a zero-argument predicate:
- as a subgoal, it is always satisfied,
- Side-effect: It commits the interpreter to whatever choices have been made since unifying the parent goal with the left-hand side of the current rule, including the choices of that unification itself.

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

What is arithmetic in prolog?

A

Arithmetic symbols are predicate symbols, not arithmetic operators. To add:
- is(5, 2+3).
- X is 2+3

16
Q

How to enumerate all natural numbers?

A

natural(l).
natural(N) :- natural(M), n is M+1.
my_loop(N) :- nautral(I), write(I), nl, I=N, !.