Logic Programming Flashcards
What is logic programming?
A declarative language paradigm that aims to separate a program into it’s logical component and it’s control component.
What is prolog naming convention for functions/relations?
All names start with a smaller case
What is the prolog convention for variable names?
All names start with a capital letter
What is the prolog symbol for left implication?
”:-“
What is universal quantification in prolog?
Variables in heads are universally quantified.
eg. snowy(X) :- rainy(X), cold(x).
What is the prolog symbol for conjunction?
”,”
What is an existential qualification in prolog?
Variables that only appear in the body.
eg. sameIsland(X, Z) :- in(X, Y), in(Z, Y)
How to denote negation in prolog?
”+”
How to denote a list in prolog?
[a, b, c]
[a | [b, c]
How to check list membership in prolog?
member(X, [X | ]).
member([x, [ | T]) :- member(X, T).
How to check if a list is sorted in prolog?
sorted([]).
sorted([_]).
sorted([a, b | T]) :- A =< B, sorted([B | T])
How to append an element in prolog?
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].
What is back chaining in prolog?
Starting with a query and working backwards, attempting to unresolved it in a set of pre-existing clauses
What is ordering in prolog?
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.
What is cut in prolog?
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.