Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
21 Cards in this Set
- Front
- Back
What is a Prolog program composed of? |
Statements, also called assertions or clauses |
|
What is a procedure in Prolog? |
A grouping of statements |
|
How would you compare Prolog's procedures and their arguments with an object-oriented language's functions and its arguments? |
- Prolog procedures have a certain programmer-defined logical relationship with its arguments - Object-oriented functions does some calculations with its arguments and may or may not return a value |
|
What are the two types of statements? How do you differentiate them? |
- Facts: propositions declared as true - Rules: statement that gives rules of implication between propositions |
|
What is a query? |
The codification of a question |
|
What are the two types of queries? How do you differentiate them? |
Ground queries: Is this statement true?Non-ground queries: Under what conditions, if any, is this statement true? |
|
How do ground queries work? |
1. Search the database from top to bottom, one statement at a time 2. Evaluate if the query matches the currently evaluated statement 3. Repeat step 2 until there is match (return true) or the database is exhausted (return false) |
|
How do non-ground queries work? |
1. Unify with a statement only if substitution can be made for any variables so that the two terms can be made equal 2. Instantiate variable(s) to matching term(s) |
|
What is query unification? |
- When a ground query finds a statement equal to the query - When a non-ground query finds a statement in which the variable substitution matches an existing statement |
|
What is the general form of a rule? |
head :- body |
|
How would you interpret a rule in plain english? |
- The head (of a rule) is true if its body is true. - The head of a rule can succeed, if the body of the rule can succeed. |
|
What is a goal? |
A query that composes the body of a rule |
|
What is a conjunction? |
The logical relation between the goals of a rule |
|
How does a ground query work, in the presence of rules? |
1. Search the database from the top, one statement at a time 2. Unify the query with the head of the rule 3. Instantiate the goals' variables 4. Resolve the n goals that compose the body of the rule 5. Evaluate the queries in the specified order, and return true if all the queries return true, otherwise return false |
|
How do you represent an anonymous variable? |
With _ |
|
In what cases would you use an anonymous variable? |
When you have a rule, but you need a truth value instead of a variable as an answer |
|
How do you represent a list in Prolog? |
- [H|T] where H is the head (first element) and T is the tail (rest of the list) - [] is the empty list |
|
How do you check if an element is a member of a list? |
- Check if the head of the list is equal to the element, return true if it is, false if not - Otherwise, recur on the tail of the list member(X, [X|_]). member(X, [_|T]) :- member(X, T). |
|
How do you check if an element is the last element in a list? |
- Check if the element is equal to the only element in a list, return true if it is, false if not - Otherwise, recur on the tail of the list, chopping off the head as you go until you reach a list with only one element last(L, [L]). last(L, [H|T]) :- last(L, T). |
|
How do you check the size of a list? |
- Base case: length of [] = 0 - Recursive case: Increment a counter for every time you chop off the head of the list size([], 0). size([H|T], N) :- size(T, N1), N is N1+1. |
|
What are some of the built-in utility functions of Prolog, and what do they do? |
- findall(X, P, L): returns a list L with all values for X that satisfy predicate P - list_to_set(L, S): returns a set S, equal to L without its redundancies - length(L, N): returns the length N of list L |