I made a mistake. np(K, X) when integer(X), integer(K), X >= K -> {X}; %%%% HERE np(_, _) -> false. should of course be np(K, X) when integer(X), integer(K), X >= K -> {X - K}; np(_, _) -> false. Fix that and all is well. The real trick with view patterns is to compile them so that you do not do too much repeated work.