intersection/4

intersection(+ Set1, + Set2, + Set3)*

Succeeds if Set3 unifies with the intersection of Set1 and Set2. Set1 and Set2 are lists without duplicates. Theyneed not be ordered.

The code was copied from SWI-Prolog's list library.