next up previous contents
Next: Adding numbers in a Up: Common data structures Previous: Cartesian products   Contents

Sets

Sets are unordered lists without repeated elements. To construct the set of all squares of integers from $1$ to $10$, you could type

> S:={ 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 };
or you could type
> S:={};
> for i in [1..10] do
for> S:=Include(S,i^2);
for> end for;
as in the case of lists, except we use Include rather than Append. To find the set of all squares of integers Modulo 3 from $1$ to $10$, you
> S:={};
> for i in [1..10] do
for> S:=Include(S,i^2 mod 3);
for> end for;   
> S;
{ 0, 1 }

Exercise 9   Create the set of all integers of the form $n^3\ mod\ 3$, $1\leq n\leq 20$.



David Joyner 2001-08-22