When and how did mathematics come to be abstracted away from the physical world?
At first, mathematics would originate in its simplest form of counting and addition as to keep track of certain supplies in ancient civilizations. At some point it came to be used to describe more complex physical situations, such as ancient astronomy or Archimedes' study of force and buoyancy.
At what point did it come to describe inherently non-physical things; doing math for the sake of math? For example, doing things such as an analytic study of functions, the defining of abstract spaces, or even primitive number theory, etc. The earliest example I can think of is Indian and Greek geometry, but even this had a motivation in engineering and design. And yes, you could argue all of math at its core came from a motivation in physics, but today that's not the case.
In the modern day, mathematicians do beautiful work with no thought of how it may effect or be used in physics or any other science for that matter. So when did this switch happen? How did it come to be "math" rather than a tool for physics?