Write two Prolog predicates:
member(X,Y) is provable if X is an element of the list Y.
remove(X,Y,Z) is provable if X is an element of the list Y and Z is Y with one instance of X removed.
These should both be defined so that they can be used with different choices for which argument is unknown.
A swi-prolog session using these predicates is shown below. In the last query using member, the symbols _G2214 and so on are automatically generated symbols that Prolog uses when it needs to make up a list that contains 2. I manually ended this query by typing a period; otherwise it would have happily generated an unlimited number of such lists.
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 6.4.1)
Copyright (c) 1990-2013 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
?- [a7].
% a7 compiled 0.00 sec, 5 clauses
true.
?- member(2, [1,2,3]).
true .
?- member(4, [1,2,3]).
false.
?- member(X, [1,2,3]).
X = 1 ;
X = 2 ;
X = 3 ;
false.
?- member(2, Y).
Y = [2|_G2214] ;
Y = [_G2213, 2|_G2217] ;
Y = [_G2213, _G2216, 2|_G2220] ;
Y = [_G2213, _G2216, _G2219, 2|_G2223] .
?- remove(2, [1,2,3], [1,3]).
true .
?- remove(4, [1,2,3], [1,3]).
false.
?- remove(X, [1,2,3], [1,3]).
X = 2 ;
false.
?- remove(2, Y, [1,3]).
Y = [2, 1, 3] ;
Y = [1, 2, 3] ;
Y = [1, 3, 2] ;
false.
?- remove(2, [1,2,3], Z).
Z = [1, 3] .
?- halt.
All of the above, in a single plain text file a7.pl.