0
votes

Hi everyone I'm newbie in prolog and I have such a list: (actually It is output of my predicate not a list )

P = [1/1, 1/3] ;
P = [1/1, 2/3] ;
P = [1/3, 1/1] ;
P = [1/3, 2/1] ;
P = [2/1, 1/3] ;
P = [2/1, 2/3] ;
P = [2/3, 1/1] ;
P = [2/3, 2/1] ;

and I need to remove dublicete terms.For example [1/1,2/3] and [2/3,1/1]is same and I should remove one of them , which one is not important ,How could I do that in prolog ?? Thanks in advance

NOTE I LEARNT THAT findALL should be good way for this but still dont know the answer please help me .

1

1 Answers

0
votes

Unless you actually show us your code, it's never going to be possible to give you precise answers.

I assume you have a predicate f/1 such that:

?- f(P).

produces the interactive result you show above. A simple solution is to change your query:

?- f([X,Y]), X < Y.

This will produce the following result:

X = 1/3, Y = 1/1 ;
X = 1/3, Y = 2/1 ;
X = 2/3, Y = 1/1 ;
X = 2/3, Y = 2/1 ;

findall/3 isn't sufficient to solve this particular situation, because you've defined uniqueness in a way that ignores the position in the list. In Prolog (and everything else) [X,Y] and [Y,X] are not equal, so you'd have to find a trick to get this to give you "unique" results.