Atheism is untenable in the 21st Century What do you think about sexual selection, for example? I have always found it weird that there is such a focus on survival advantage when what really matters is not surviving, but passing on your genes.
Concerning the subject of higher cognition, it's possible that higher cognition had a survival value in general, but specific results, like mathematical abilities, are accidental byproducts. — Echarmion
When I say reproductive mechanism, I mean sexual selection. And, yes, I think it's just as important to understanding evolution as mere survival.
I think simple math has huge survival value. I've read a lot of accounts of birds and mammals having basic math skills, understanding when something is more or less, being able to count up to 5 or 10, etc. It seems to me, especially if you're living in groups, it would be beneficial to know how to share resources and how to count how many apples you're trading for how many walnuts, for example. Or how many babies are in your nest, how many members are in your group, etc. etc.
Our developed ability to do higher math, like statistics, or understand the Pythagorean theorem is probably, as you suggest, just a happy coincidence of evolution. Though I think it obviously stems from useful evolutionary traits. Curiosity, innovation, and basic math skills coming together to aid us in our understanding of the world--that sort of thing.