Function: select
Section: programming/specific
C-Name: select0
Prototype: GG
Help: select(f, A): selects elements of A according to the selection function f.
Wrapper: (bG)
Description:
  (gen,gen):gen    genselect(${1 cookie}, ${1 wrapper}, $2)
Doc: Given a vector, list or matrix \kbd{A} and a \typ{CLOSURE} \kbd{f},
 returns the elements $x$ of \kbd{A} such that $f(x)$ is non-zero. In other
 words, \kbd{f} is seen as a selection function returning a boolean value.
 \bprog
 ? select(x->isprime(x), vector(50,i,i^2+1))
 %1 = [2, 5, 17, 37, 101, 197, 257, 401, 577, 677, 1297, 1601]
 ? select(x->(x<100), %)
 %2 = [2, 5, 17, 37]
 @eprog\noindent returns the primes of the form $i^2+1$ for some $i\leq 50$,
 then the elements less than 100 in the preceding result. The following
 function lists the elements in $(\Z/N\Z)^*$:
 \bprog
 ? invertibles(N) = select(x->gcd(x,N) == 1, vector(N,i,i))
 @eprog

 \noindent Finally
 \bprog
 ? select(x->x, M)
 @eprog\noindent selects the non-0 entries in \kbd{M}. If the latter is a
 \typ{MAT}, we extract the matrix of non-0 columns. Note that \emph{removing}
 entries instead of selecting them just involves replacing the selection
 function \kbd{f} with its negation:
 \bprog
 ? select(x->!isprime(x), vector(50,i,i^2+1))
 @eprog

 \synt{genselect}{void *E, long (*fun)(void*,GEN), GEN a}.
