The trace just backed up what he had already mentioned.
Just to add:
1. In the trace, there are several clues that this is recursive sql, not least of which "recursive_depth=1".
2. Don't think there is a correlation between statement and function as such. Although if you used DBMS_APPLICATION_INFO to set module information in such functions, then you could see it in the APPNAME lines in the raw trace.
3. x here is just an inline view, could also have used subquery factoring - the WITH clause. Expensive operations such as function calls, analytics etc, should be done on as small a dataset as possible - sometimes it might early in the query, sometimes it might be late, it depends. Here, because of the DISTINCT (see again what Carl says about this), it makes sense late.