Let's say I have a prolog program to concatenate lists like this:
concat([],X,X).
concat([Head|Tail],X,[Head|R]) :- concat(Tail,X,R).
How can I know which questions will return a finite number of answers? For example, asking
concat(X,Y,[1,2,3,4]).
Will return the finite solution set:
X = [],
Y = [1, 2, 3, 4] ;
X = [1],
Y = [2, 3, 4] ;
X = [1, 2],
Y = [3, 4] ;
X = [1, 2, 3],
Y = [4] ;
X = [1, 2, 3, 4],
Y = [] ;
false.
while making the question
concat(X,[2,3],Z).
will return an infinite set of solutions:
X = [],
Z = [1, 2, 3] ;
X = [_G24],
Z = [_G24, 1, 2, 3] ;
X = [_G24, _G30],
Z = [_G24, _G30, 1, 2, 3] ;
X = [_G24, _G30, _G36],
Z = [_G24, _G30, _G36, 1, 2, 3] ;
X = [_G24, _G30, _G36, _G42],
Z = [_G24, _G30, _G36, _G42, 1, 2, 3] ;
X = [_G24, _G30, _G36, _G42, _G48],
Z = [_G24, _G30, _G36, _G42, _G48, 1, 2, 3] ;
X = [_G24, _G30, _G36, _G42, _G48, _G54],
Z = [_G24, _G30, _G36, _G42, _G48, _G54, 1, 2, 3]
and so on (basically, every possible list ending with [1,2,3].
so how can I reason which questions will end or not on a logic program?