Chapter 4 Flashcards
Prolog is made of..
Knowledge bases, which… (next flashcard)
Knowledge bases are made of…
clauses, which…(next flashcard)
Clauses are made of…
conditionals or atoms.
When writing a Prolog program made of clauses, we have to make sure that these clauses capture:
- the truth of a sentence in the KB (Aristotelian logic)
- the whole truth, explicitly ad implicitly!
- In a form suitable for back-chaining –> we must write high-quality predicates!
Saying that a program is “logically correct”, means..
- correct with regard to grammar and
- capturing the truth –> correct logical entailment
- back-chaining= simply correct
Recursion in Prolog
Recursion breaks down a problem into smaller pieces of the same problem such that we can apply the same algorithm to each piece and then later combining the solutions for the answer
Stack
Data structure that stores each “call” of a procedure: it follows a LIFO strategy
LIFO strategy
Last-in, first-out strategy
When is a predicate considered recursive in Prolog?
When it appears in both the head and body of the clause, but with different arguments.
How can we write clauses in the program that handle recursion?
- Write a clause that handles the n = 0 case, which is, where n is the number of intermediate “blocks” (the smallest natural number).
- Write a clause that handles the n+1 case.
Example: if X is above Y with n+1 boxes between them, then there must be a Z that is directly below X and above Y, with n blocks between them.
Mathematical induction
mathematical proof technique that aims at proving that a mathematical sentence hold for all natural numbers
Example: prove that the sum of the natural numbers up to n is equal to one half of n times (n+1) –> sum = S(n)
- Prove that S(0) is true
2. Prove that for any N, if S(n) is true, then S(n+1) is also true.
Which one of these two sentences is “recursively correct”?
- above (X, Y) :- on(X, Z), above(Z, Y)
- above (X, Y) :- above(Z, Y), on(X, Z)
The first, because when the body of a clause contains a recursive predicate, we have to make sure that its new variables are instantiated by earlier atoms ( on(X, Z) in this case).
What is a requirement for a problem in order for it to get solved by recursion?
To have a base case
What is this query asking?
above(b1, b2) ( see slides of lecture 4)
Is b1 somewhere above b2?