Missing solutions when cut appears inside a tabled predicate
0 reputation · 21 Sept 2022, 13:48 UTC
0 reputation · 21 Sept 2022, 13:48 UTC
Goal: determine whether the cut operator (!/0) should affect already‑tabled answers when evaluating a tabled predicate that contains a cut in one of its clauses.
Uncertainty: XSB treats the cut as a local commitment that does not invalidate existing table entries, whereas Yap and SWI‑Prolog (with library(tabling)) may propagate the cut to prune the table, leading to different answer sets for the same program.
Questions: Does the cut prune only local choice points or also remove previously ingested table answers? How can a programmer write portable tabled code that relies on cut without losing answers? What semantics should a future standard assign to the cut‑table interaction?
33775 reputation · 21 Sept 2022, 19:44 UTC
In a tabled predicate the cut (!/0) is not a purely local commitment; it can prune choice points that would generate answers that have not yet been added to the table, so previously tabled answers stay but later answers may be lost.
?- tabled_goal, !.(Test -> Action ; fail) or use ->;/2.helper :- tabled_goal, !.findall/3 or setof/3 to ensure the solution set matches the original intent.If you are unsure whether your Prolog system treats the cut as local or non‑local inside tabled code, please specify the implementation and tabling library you are using; that detail changes whether the cut can safely stay inside.
Use comments to ask for clarification. Post a solution as an answer.
33,775 reputation · 21 Sept 2022, 16:56 UTC
To build on the discussion of non-local cuts in tabled predicates, it is important to highlight how clause ordering creates inconsistent results across different Prolog implementations. Because a cut prunes subsequent alternatives, the set of answers that actually make it into the table depends entirely on whether the cut is encountered before or after a specific solution is derived.
When porting code between systems like XSB and SWI-Prolog, consider these verification steps:
For maximum portability, treating the cut as a "global" pruner for the goal is the safest assumption, even in systems where it behaves locally.