Mathematics and logic are indispensable in science, yet how they are deployed and why they are so effective, especially in the natural sciences, is poorly understood. In this paper, I focus on the how by analysing Jean Piaget's application of mathematics to the empirical content of psychological experiment; however, I do not lose sight of the application's wider implications on the why. In a case study, I set out how Piaget drew on the stock of mathematical structures to model psychological content, namely, the operations of thought involved in reasoning. In particular, I show how operations of thought form structured wholes that initially resisted modelling by either lattices or groups but could be modelled adequately by modifications of these mathematical structures. Piaget coined the term 'grouping' for the modified structure, I conclude that it represents a non-canonical application of mathematics to the empirical content of experimental psychology. I also touch on the role external factors played in Piaget's development of the grouping.According to the genetic epistemology conceived by Piaget, the origin of intelligence lies in the biological organism and develops in stages over time, and, via the grouping, Piaget established a genetic relationship between two stages of reasoning. I show how this relationship explains why mathematics and logic fit the psychological content of reasoning whilst simultaneously making their successful deployment in the natural sciences more mysterious. Finally, I turn to the explanation Piaget envisaged for the unreasonable effectiveness of mathematics in the natural sciences and consider some consequences for naturalism and Pythagoreanism.