The Unix utility
tsort will do a topological sort. The input to the utility is a text file with two items per line, separated by white space, indicating a directed edge from the first item to the second.
Here is a thumbnail image of a graph of relationships between special functions. See this page for a full-sized image and an explanation of what the arrows represent.
I took the GraphViz file used to create the graph and formatted it for
tsort. Then I randomly shuffled the file with
Gegenbauer_polynomials Legendre_polynomials Gegenbauer_polynomials Chebyshev_polynomials_Second_kind Hypergeometric_2F1 Jacobi_polynomials Error_function Fresnel_S ... Hypergeometric_1F1 Error_function
The lines are not sorted topologically because, for example, the Gegenbauer polynomials are special cases of the Hypergeometric 2F1 functions, so Hypergeometric 2F1 should be listed before Gegenbauer polynomials.
When I ran the shuffled file through
tsort I got
Elliptic_F Hypergeometric_2F1 Elliptic_E Hypergeometric_1F1 .... Beta
and now in this list more general functions always come before special cases. If you think of the direct edges as references, all references in the sorted list are forward references; there are no backward references.