Hi,
Even though this is not an elligant solution, but it works.
Here u go.
expand(p(A,B,C),List,Result):-setof([p(A,B,C)], exp(p(A,B,C), List),Result).
exp(p(A,B,C),List):-member(B,List),member(C,List).
?- List=[e,f],expand(p(a,X,Z),List,Result).
List = [e, f]
X = _G167
Z = _G168
Result = [[p(a, e, e)], [p(a, e, f)], [p(a, f, e)], [p(a, f, f)]]
Yes