Picat General 3 — Questions and Answers
Question 1: In Picat's constraint module `cp`, which predicate declares an integer decision variable with a domain?
- X :: Lo..Hi (Correct answer)
- domain(X, Lo, Hi)
- int_var(X, Lo, Hi)
- var(X, Lo..Hi)
Correct answer: X :: Lo..Hi
The `::` operator assigns a finite-domain range to a decision variable, e.g., `X :: 1..10` constrains X to integers 1 through 10.
Question 2: What does `solve([ff], Vars)` do in Picat's constraint solver?
- Searches for values satisfying constraints using the first-fail heuristic (Correct answer)
- Solves a system of linear equations
- Finds all solutions and returns a list
- Applies forward-checking only
Correct answer: Searches for values satisfying constraints using the first-fail heuristic
`solve` with option `ff` (first-fail) selects the variable with the smallest remaining domain first, improving search efficiency.
Question 3: Which Picat built-in computes the length of a list?
- length(List, Len) (Correct answer)
- list_length(List)
- size(List)
- count(List, Len)
Correct answer: length(List, Len)
`length(List, Len)` unifies Len with the number of elements in List, and can also generate a list of free variables when Len is given.
Question 4: How does Picat's tabling differ from standard Prolog memoization libraries?
- Tabling is built into the language with the `table` directive and handles cycles automatically (Correct answer)
- It caches only ground answers
- It requires explicit hash maps managed by the programmer
- It only works for functions, not predicates
Correct answer: Tabling is built into the language with the `table` directive and handles cycles automatically
Picat's `table` directive enables SLG-resolution tabling that correctly handles cyclic calls and avoids infinite loops without programmer intervention.
Question 5: What is the output of `writeln(2 ** 10)` in Picat?
- 1024 (Correct answer)
- 20
- 210
- 1024.0
Correct answer: 1024
The `**` operator in Picat performs integer exponentiation when both operands are integers, so 2**10 evaluates to 1024.
Question 6: In Picat, which construct allows pattern matching directly in a function/predicate head?
- Multiple clauses with different head patterns (Correct answer)
- A single clause with if-then-else
- The match() built-in
- Guard expressions after =>
Correct answer: Multiple clauses with different head patterns
Picat allows multiple clauses for the same predicate/function, each with a distinct head pattern that is tried in order, enabling structural pattern matching.
Question 7: Which keyword in Picat is used to import a module at the top of a file?
- import (Correct answer)
- use_module
- require
- include
Correct answer: import
The `import` declaration at the top of a Picat file makes predicates from a named module available in the current file.
In Picat's constraint module `cp`, which predicate declares an integer decision variable with a domain?