I don't think this is a problem for machine solution. It's up to
us to decide how the thing is organized. What depends on what,
which parts are foundational, and which parts are built on
top of those? Then we should organize the code so it
expresses that.
I was just thinking that it's not always obvious what the dependencies
are. For example, the special functions depend on linear algebra
(through the Mathieu function, which needs to compute some
eigenvalues) and there may be some other cases like that.