Getting the "root" Head

With a few functions to try, defined in differentfunctions, try this headF:

differentfunctions = {f1[a][x, y], f2[a, b, c], f3[a, 2][3]};
headF = FixedPointList[Head, #][[-3]] &;

headF /@ differentfunctions

(* Out: {f1, f2, f3} *)

It relies on the fact that, at some point, repeated application of Head will return Symbol, and head of Symbol is also Symbol, so repeated application gets to a fixed point. You then extract the last head before Symbol was returned, which is the third-from-last element returned by FixedPointList (the last two always being the same, and equal to the fixed point value).


You may use ReplaceRepeated.

With

differentfunctions = {f1[a][x, y], f2[a, b, c], f3[a, 2][3]};

Then

ReplaceRepeated[h_[___] :> h] /@ differentfunctions
{f1, f2, f3}

Hope this helps.


There is a built-in function BoxForm`UltimateHead that extracts the head wrapped with HoldComplete. So wrapping the output from this function with ReleaseHold gives the desired result:

topHead = ReleaseHold @* BoxForm`UltimateHead;

topHead /@ {f1[a][x, y], f2[a, b, c], f3[a, 2][x, y, g[z][1, 2, 3]]}

{f1, f2, f3}