# Find all pattern in expression

Consider this problem: I have a functional $$\mathcal{F}$$ acting on some function $$n(t)$$ such that

$$\mathcal{F}[n(t)]=0$$

$$\mathcal{F}[n^*(s)n(t)]=\alpha(t,s)$$

$$\mathcal{F}[n(s)n(t)]=0$$

Now I want to implement $$\mathcal{F}$$ on an expression, e.g.

expr = (Conjugate[Integrate[f[s] *n[s], {s, 0, t}]] +
g[t]) (Integrate[r[q] *n[q], {q, 0, t}] + n[t]*p[t]) // ExpandAll


This contains 4 terms:

1.

Conjugate[Integrate[f[s]*n[s], {s, 0, t}]]*Integrate[n[q]*r[q], {q, 0, t}]


This should transform to

$$\int_0^t\int_0^tdsdqf^*(s)r(q) n^*(s)n(q) \rightarrow \int_0^t\int_0^tdsdqf^*(s)r(q) \alpha(q,s)$$

2.

 g[t]*Integrate[n[q]*r[q], {q, 0, t}]


which $$\mathcal{F} \rightarrow 0$$ due to rule #1

3.

 Conjugate[Integrate[f[s]*n[s], {s, 0, t}]]*n[t]*p[t]


This transforms as $$\int_0^tds f^*(s)n^*(s)n(t)p(t) \rightarrow \int_0^tds f^*(s)\alpha(t,s)p(t)$$

4.

g[t]*n[t]*p[t]


$$\mathcal{F} \rightarrow 0$$ due to rule 1.

For this expression, I can first deal with the Conjugate and Integrate by

expr = expr //. {Conjugate[Integrate[f_, l_]] :>
Integrate[Conjugate[f], l]} //. {Conjugate[a_*b_] :>
Conjugate[a]*Conjugate[b]} //. {a_*Integrate[f_, l_] :>
Integrate[a*f, l]} //. {Integrate[f1_, l1_] Integrate[f2_,
l2_] :> Integrate[f1*f2, l1, l2]}


followed by, e.g.

expr /. {Conjugate[n[x_]] n[y_] :> a[x, y]}


Then filter out expressions that contains only one $$n(t)$$:

Table[{expr[[i]], Count[expr[[i]], n[x_], 10]}, {i, 1,
Length[expr]}] // TableForm


Is there a more automatic/robust way to do this?