This is a simple and short question. I have a function which contains a certain number of square roots and 4th powers, lets take this one:
f=Sqrt[x] Sqrt[y] Sqrt[z + 2] b^4 + c^3 + d^4
I want to be able to count the number of occurrences of the square roots (3) and the number of occurences of the 4th power (2). I think it should be possible to use Count
for this, but I can't figure out how. I have tried
Count[f,_Sqrt,Infinity]
and
Count[f, Power[4, _], {0, Infinity}]
but both don't seem to work. Can someone tell me how to achieve this?
FullForm[f]
; sqrt would be matched byPower[_, Rational[1, 2]]
for instance. $\endgroup$FullForm
of this expression first. Besides, patterns of specified types includes_Integer
,_Real
,_Complex
,_List
,_Symbol
and the general_head
, wherehead
is returned byHead
. So there is no_Sqrt
but_Power
,becauseHead[Sqrt[x]]
returnsPower
. $\endgroup$