Question: how to find how many occurances a function shows up in an expression (even if repeated?)

I need to count how many times a special function shows up in an expression.

The problem is that indets returns a set. So if the same function shows up more than one time in the original expression, with same arguments, only one of these will show up in the result. So I would not know if there were mmore than one of these.

Here is a simple example, using sin(x) here.

restart;
expr:=sin(x)+3*cos(x)*sin(x)+1/sin(2*x);
indets(expr,'specfunc(anything,sin)')

#gives
#   {sin(x), sin(2*x)}

So when I do nops() on the above, it gives 2 and not 3.

How to obtain number of times a function shows in an expression, even it if is repeated?

Please Wait...