Strange behavior of Pick when named constants appear in its arguments
No, a support response like
I could reproduce the issue and it does appear that Pick[] is behaving strangely in certain cases. I have forwarded a report to the appropriate members of our development team.
should not be taken as confirmation of an actual bug.
Why should
Pick[{2 E, 2 E }, {0, 2 E}, 0]
return {2 E, 1}
?
Well, 2 E
is clearly there because of the first part of the selector, which matches the test 0
.
What is more interesting is the second, non-atomic part of the selector. The head Times
does not really matter, only the structure does, so it is treated effectively as List
. The result is the same as from
Pick[{2 E, 2 E}, {0, {2, E}}, 0]
In other words, the nested second part will now act similarly to Pick[f[x, y], g[a, b], False]
or
Pick[f[x, y], {a, b}, False]
(* f[] *)
where the selector parts did not match the test, so x
and y
weren't picked and we were left with nothing, or Sequence[]
inside f
, analogously to a {}
result.
Of course, in our example, x
and y
happen to be 2
and E
, while Times[]
is by definition 1
.