Just do select((x) -> x == 8, a, 1) where flag 1 means the "index mode". In general, your function is as shown below. position = (elt, array) -> select((x) -> x == elt, array, 1); Please note, despite the fact that this stuff does a lambda call per each...

Use the valuation command, like so: valuation(3087, 7) This does not compute the factorization of the number. Alternately, you could write your own function: val(n, p)= { if(n==0, return(+oo)); my(e); while(n%p==0, n /= p; e++ ); e; } ...