Logic Programming and Unification Flashcards
7 cards from real Picat practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Logic Programming and Unification flashcards as text
In Picat, what happens when unification of two terms fails during pattern matching in a clause head?
Answer: Picat backtracks and tries the next matching clause
When a clause head fails to unify with the call, Picat backtracks and attempts the next clause whose head can unify.
Which Picat operator is used to check structural equality without performing unification?
Answer: ==
The == operator tests if two terms are identical in structure and variable bindings without unifying them.
In Picat logic predicates, what does the goal `X = f(Y), Y = 3` result in for X?
Answer: X = f(3)
After Y unifies with 3, the earlier binding X = f(Y) propagates so X becomes f(3).
What is the role of the anonymous variable `_` in Picat unification?
Answer: It matches any term and is never shared across occurrences
Each occurrence of _ is a distinct fresh variable that matches anything but shares no binding with other _ occurrences.
Which of the following Picat goals will succeed?
Answer: f(X,Y) = f(1,2)
f(X,Y) = f(1,2) succeeds by binding X=1 and Y=2; the other options fail due to structural or value mismatches.
In Picat, what does the `not` (or `\+`) operator do in a logic predicate context?
Answer: Succeeds if the goal cannot be proved (negation as failure)
\+ Goal succeeds if Goal fails (negation as failure), with no side-effect bindings retained.
What is the occurs check, and does Picat's default unification perform it?
Answer: Prevents binding X to a term containing X to avoid circular structures; no, not by default
The occurs check prevents creating circular (infinite) terms by checking X โ T before X=T, but Picat (like most Prolog-family systems) skips it by default for performance.