Logic Programming Flashcards
What is the foundation of logic programming?


What is the most widely used logic programming?
Prolog
How can a programmer compute in Prolog?

Give an example of Prolog syntax.

How are databases constructed in Prolog?

Prolog Notes:

Example: Constant Query

Example: Variable Query

Example: Multiple Predicates Query

Example : Assigning one predicate in terms of another predicate

Example: Notations


Example: Sibling Query

How does the interpreter work when searching data?
It is also possible in theory to work forward from the facts trying to see if any of the things you can prove from them are what you were looking for - that can be very time-consuming.
Fancier logic languages use both kinds of chaining, with heuristics or hints from the user to bound the searches.

Example: Resolution Principle

Prolog Unification Rules

List Notation

head(cons(H,T),H) :- isList(T).
tail(cons(H,T),T) :- isList(T).
?- head(cons(2,cons(3,nil)),X).
X = 2
?- head(cons(X,cons(3,nil)),2).
X = 2
Remark: Prolog does not have notion of “input” and “output” variables

Syntactic Sugar For Lists

Example: Stack

Example: Termination

Example: Arithmetic


Example 1: Cut Operator
- Always succeeds as a goal
- “freezes” choice made when encountered
- If cut reached when backtracking, the search of subtrees of the parent node of the cut stops, and the search continues with the grandparent node.
- Cut “prunes” the search tree of all other siblings to the right of the node containing the cut.


Example 2: Cut Operator


Example: Database Manipulation


Example: Non-Monotonic Reasoning
