Lindo Systems

! Illustrating set operations such as union, intersection in LINGO;
! Keywords: Sets, Union, Intersection;
sets:
   people;   ! The base or ground set;
! Various sets derived from the people set;
   suppliers( people); ! Some are suppliers;
   customers( people); ! Some are customers;
! Some are at least a supplier or a customer  ( union);
   active( people) | @in(customers, &1) #or# @in(suppliers, &1);
! Some are both (intersection);
   both( people) | @in(customers, &1) #and# @in(suppliers, &1);
endsets
data:
   people = p1..p20; ! The current base set;
   suppliers = p1 p3 p4 p7 p9;
   customers = p4 p9 p11 p17 p19 p20;   
enddata

calc:
  @write(' The people with whom we do business are: ', @newline(1));
  @for( active( j):
     @write( '   ', active( j), @newline(1));
      );
  @write(' The people who are both buyers and sellers are: ', @newline(1));
  @for( both( j):
     @write( '   ', both( j), @newline(1));
      );

! For more complicated set construction operations, 
    the  @INSERT( derivedSet, setElement) operator may be of use;
endcalc