I would like to get a List (ideally a set - drop repetition), but provided that there is no direct way to do this, I just use Union ) of the leaves from this expression.
For example, the expression
ArcTan[(-1 + 2*x)/Sqrt[3]]/Sqrt[3]
has a LeafCount 18:
- -thirteen)
- 2 (3)
- 3 (2)
- x
- Arctan
- Plus
- Power (2)
- Rational (2)
- Time (3)
so I would like something like
{-1, 2, 3, x, ArcTan, Plus, Power, Rational, Times}
Actually, I really need functions, so
{ArcTan, Plus, Power, Rational, Times}
would be ideal - but presumably thereβs not a very complicated way to filter them out when I get them.
I got lucky with
H[s_] := If[LeafCount[s] == 1, s, Head[s]] H /@ Level[expr, 1, Heads -> True] H /@ Level[expr, 2, Heads -> True] (* ... *)
but I feel that there must be a better way.