Lists

A list of elements of the form $ f(i)$ , where $ i$ ranges over all integers between $ a$ and $ b$ can be created using the command L:=[[a..b],i->f(i)]; . Here $ f$ is any function whihc can be entered in GAP. For example, $ f$ itself can be a list:

gap> L:=List( [1..10], i -> [i,i^2+1] );
[ [ 1, 2 ], [ 2, 5 ], [ 3, 10 ], [ 4, 17 ], [ 5, 26 ], [ 6, 37 ], [ 7, 50 ], 
  [ 8, 65 ], [ 9, 82 ], [ 10, 101 ] ]

If $ f$ is Boolean-valued then there is another option for creating a list. The Filtered command only lists those elements for which $ f(i)$ is true. Here's an example:

gap> L:=List( [1..10], i -> IsOddInt(i) );
[ true, false, true, false, true, false, true, false, true, false ]
gap> L:=Filtered( [1..10], i -> IsOddInt(i) );
[ 1, 3, 5, 7, 9 ]

Exercise 6.7.2   Find the sequence of primes from $ 2$ to $ 100$ . (Hint: Use the IsPrime command.)



david joyner 2008-04-20