well according to me mathematics is both , discovered and invented.
you cant argue with the fact that people at first noticed maths in nature , from the making of the pyramids to the working of a simple wheel , humans observed this trend and then adapted and advanced with this trend .
various fields for example calculus, both differentiation and integration arose from graphs , although very crudely but then it was formed into what it is now .
basically everything that is there today in mathematics started with someone noticing it or in other words discovering it if you may .
maths like many other things are very hard to perfect , even today there are many unsolvable problems in math and gradually news are arising that there are people who are able to now solve 100+ year old unsolved questions implying that how much ever techniques and methods we use there will still be quite a bit more in the future.
i agree with you saying we invent mathematics on the go, its only when we hit a obstacle for which there isn't already a method to overcome it that we sit down and think hard and come up with a way . all forms of science are deeply inter related with maths , physics,biology and chemistry(the major one's ) in fact some of them are like how human bodies are made of a vast majority of water.
__________________
Hey random person who likes removing signatures
