Can somebody help me with a function f
such that it extract all sub expressions (i.e. looking down the expression tree) from any expression given to it and also a list of heads it encounters as it moves down the expression tree.
For example, f@(Sin[Log[Cos[a], Tan[Log[a, b]]]] // Inactivate)
gives { { Inactive[Sin][Inactive[Log][Inactive[Cos][a], Inactive[Tan][Inactive[Log][a, b]]]], Inactive[Log][Inactive[Cos][a], Inactive[Tan][Inactive[Log][a, b]]], Inactive[Cos][a], Inactive[Tan][Inactive[Log][a, b]], a, Inactive[Log][a,b], a, b }, { Inactive[Sin], Inactive[Log], Inactive[Cos], Inactive[Tan], Inactive[Log] } }
Note: order of occurrence and duplicacy must be maintained