Challenge 3: What the Cut in symbol/2 Actually Prevents — Possible Solution ==================================================================== row_demo.pl (same row_symbols/3, row//4, symbol//2 as the chapter): row_symbols(Queens, Row, Symbols) :- length(Queens, N), phrase(row(Queens, Row, 1, N), Symbols). row(_, _, C, N) --> { C > N }, []. row(Queens, Row, C, N) --> { C =< N, nth1(C, Queens, R) }, symbol(R, Row), { C1 is C + 1 }, row(Queens, Row, C1, N). symbol(Row, Row) --> !, [q]. symbol(_, _) --> [e]. Backtracking query directly into symbol//2, bypassing row_symbols/3's normal single call, to see every reading it's actually capable of producing: ?- phrase(symbol(3, 3), Out). Out = [q] ; Out = [e]. % <-- only reachable WITHOUT the cut -- Explanation -- -- -- With the cut present, phrase(symbol(3, 3), Out) only ever reports -- Out = [q], correctly, and only once -- the cut commits the moment -- Row and the queen's own R unify successfully, so the second clause -- (symbol(_, _) --> [e].) never even gets a chance to run for that -- same call. -- -- If the cut were removed, symbol(3, 3) would ALSO match the second -- clause on backtracking, since symbol(_, _) unifies with any two -- arguments regardless of their values -- producing a second, extra -- result: Out = [e]. That's a genuinely WRONG reading of that -- particular cell -- column 3's queen really is in row 3, so -- reporting it as empty (e) is factually incorrect, not just a -- redundant repeat of the same correct answer. -- -- Because removing the cut would change WHICH results this predicate -- can produce -- adding a genuinely incorrect one, not just an -- inefficient duplicate of the correct one -- this is a RED cut by -- prolog1-8's own test, not a green one. WHY THIS WORKS AS AN ANSWER ------------------------------ This backtracks directly into symbol//2 (rather than only calling it once through the normal row_symbols/3 path) to surface the exact extra result the cut suppresses, then applies prolog1-8's own green-vs-red test explicitly to justify classifying it as a red cut.