 numboccur - Maple Programming Help

Home : Support : Online Help : Programming : Expressions : Structure : numboccur

numboccur

count occurrences of an expression

 Calling Sequence numboccur(f, x)

Parameters

 f - expression x - expression

Description

 • The numboccur(f, x) function returns the number of times that x is found in f.
 • If x is a sum or a product, the counted expressions are those where the sum or product appear with no extra terms or factors in f.  If x is a list or a set, then every element in the list or set is counted.
 • If x is a list or set, numboccur counts and adds together the number of times each member of the list or set occurs in f. In other words, numboccur(f,{x,y}) is equivalent to numboccur(f,x) + numboccur(f,y). Note that if x is a list and contains a given element more than once, it is counted more than once each time it appears in f.
 • If the item that you want numboccur to count is itself a list or set, you must enclose it in a list or set. Otherwise, numboccur will count occurrences of the items in the list or set as described above.

 • The numboccur command is thread-safe as of Maple 15.

Examples

 > $\mathrm{numboccur}\left({x}^{3}+x-1,x\right)$
 ${2}$ (1)
 > $\mathrm{big_expr}≔\mathrm{expand}\left(\mathrm{sin}\left(7x\right)\right)$
 ${\mathrm{big_expr}}{≔}{64}{}{\mathrm{sin}}{}\left({x}\right){}{{\mathrm{cos}}{}\left({x}\right)}^{{6}}{-}{80}{}{\mathrm{sin}}{}\left({x}\right){}{{\mathrm{cos}}{}\left({x}\right)}^{{4}}{+}{24}{}{\mathrm{sin}}{}\left({x}\right){}{{\mathrm{cos}}{}\left({x}\right)}^{{2}}{-}{\mathrm{sin}}{}\left({x}\right)$ (2)
 > $\mathrm{numboccur}\left(\mathrm{big_expr},\mathrm{sin}\left(x\right)\right)$
 ${4}$ (3)
 > $\mathrm{numboccur}\left(\frac{\left(a+b\right)\left(a+b+1\right)}{a+b+c},a+b\right)$
 ${1}$ (4)
 > $\mathrm{numboccur}\left(ax+{x}^{2}+b,\left[a,x,{x}^{2},b\right]\right)$
 ${5}$ (5)
 > $\mathrm{numboccur}\left(ax+{x}^{2}+b,\left[a,a,x,{x}^{2},b\right]\right)$
 ${6}$ (6)
 > $\mathrm{numboccur}\left(\left\{\left[1\right],\left[3\right],\left[2,3\right]\right\},\left[3\right]\right)$
 ${2}$ (7)
 > $\mathrm{numboccur}\left(\left\{\left[1\right],\left[3\right],\left[2,3\right]\right\},\left\{\left[3\right]\right\}\right)$
 ${1}$ (8)