Picat Tabling for Memoization 4 — Questions and Answers
Question 1: What does the `table` mode specifier `max` do when applied to an argument in Picat?
- It keeps only the answer with the largest value for that argument, useful for maximization problems. (Correct answer)
- It sets an upper bound on the argument's value.
- It stores the maximum number of answers for that predicate.
- It makes the argument optional with a default maximum.
Correct answer: It keeps only the answer with the largest value for that argument, useful for maximization problems.
The `max` mode retains only the answer maximizing that argument, enabling optimal-value dynamic programming.
Question 2: When solving the 0/1 knapsack problem with Picat tabling, which two parameters typically form the call pattern?
- The item index and the cumulative value so far.
- The current item index and the remaining capacity. (Correct answer)
- The item value and the bag weight limit.
- The total weight and the item count.
Correct answer: The current item index and the remaining capacity.
Knapsack tabling indexes subproblems by item index and remaining capacity, the two dimensions of the DP table.
Question 3: In Picat, which loop construct can serve as an alternative to tabling for simple iterative DP problems?
- while loops with assert/retract
- findall/3 with sort
- between/3 with cut
- foreach loops combined with arrays (Correct answer)
Correct answer: foreach loops combined with arrays
Picat's imperative foreach loops over arrays can implement iterative DP directly, avoiding recursive overhead.
Question 4: What does it mean for a tabled predicate in Picat to have reached a 'fixpoint'?
- The predicate has been called exactly as many times as it has answers.
- The predicate body has been fully unfolded without recursion.
- No new answers are generated by further evaluation; the table is complete. (Correct answer)
- The recursion depth equals the number of table entries.
Correct answer: No new answers are generated by further evaluation; the table is complete.
Fixpoint means iterative tabled evaluation has stabilized: another pass adds no new answers.
Question 5: Which Picat built-in can be used to inspect or clear the tabling store at runtime?
- reset_cache/1
- drop_table/1
- clear_memo/1
- abolish_table_pred/1 (Correct answer)
Correct answer: abolish_table_pred/1
`abolish_table_pred/1` removes all tabled results for a specified predicate from the tabling store.
Question 6: How does Picat's tabling interact with Picat's constraint solving module?
- Tabling can be combined with constraint solving, but constrained variables in table entries require careful mode declarations. (Correct answer)
- Tabling and constraint solving are mutually exclusive in Picat.
- Constraint variables are automatically grounded before tabling.
- Tabling always disables constraint propagation for tabled predicates.
Correct answer: Tabling can be combined with constraint solving, but constrained variables in table entries require careful mode declarations.
Mixing tabling and constraints requires that output arguments be sufficiently instantiated or use appropriate modes to avoid storing unresolved constraints.
Question 7: In Picat tabling, what distinguishes 'variant tabling' from 'subsumption-based tabling'?
- Variant tabling indexes by exact call structure, while subsumption-based tabling reuses answers from more general calls. (Correct answer)
- Subsumption-based tabling requires explicit programmer annotations.
- Variant tabling stores fewer answers by merging similar calls.
- Variant tabling is faster but only works for deterministic predicates.
Correct answer: Variant tabling indexes by exact call structure, while subsumption-based tabling reuses answers from more general calls.
Subsumption-based tabling allows a specific call to reuse answers from a pre-existing more general tabled call, reducing redundancy.
What does the `table` mode specifier `max` do when applied to an argument in Picat?