Scientists and mathematicians get paid by countries and universities to work on things like this, to advance human knowledge.
A lot of maths and physics sounds useless initially, until suddenly you realize it led to the transistor or something. Even AI itself was a field that was getting funded for decades with no results until it exploded in the 2010s and today.