# Distribute operator

I have an operator defined by \[ScriptCapitalN] and want to Expand a term and then use Distribute in order to apply the operator \[ScriptCapitalN] to every term individually. However,

Distribute[
Map[Expand,
1/(1 + x) \[ScriptCapitalN][(DiracDelta[om - om1 - om2 - om3] f[
om1] + DiracDelta[om - om1 - om2 - om3] f[om2])/(4 om)],
Infinity]]


doesn't seem to work.

The desired output is supposed to be

\[ScriptCapitalN][(DiracDelta[om - om1 - om2 - om3] f[om1])/(4 om)]/(
1 + x) + \[ScriptCapitalN][(
DiracDelta[om - om1 - om2 - om3] f[om2])/(4 om)]/(1 + x)


That's indeed a bit annoying. Try to use MapAll; this will Distribute at every level:

exp = Map[Expand,
1/(1 + x) \[ScriptCapitalN][(DiracDelta[om - om1 - om2 - om3] f[
om1] + DiracDelta[om - om1 - om2 - om3] f[om2])/(4 om)],
∞
]
MapAll[Distribute[#, Plus, \[ScriptCapitalN]] &, exp]


A probably faster alternative for complex expression would be to use ReplaceAll (/.):

exp /. x_\[ScriptCapitalN] :> Distribute[x, Plus, \[ScriptCapitalN]]


Maybe ReplaceRepeated (//.) is needed for deeply nested expression.

• Yeah, I was experimenting with MapAll as well but should have used the pure function in your code (otherwise also the DiracDelta will be distributed since you cannot specify the options in Distribute). Wrapping around a Apart at the very end does the intended job. Thank you for your help! – Display Name Sep 10 '18 at 11:03
• It certainly takes a long time now for the actual term where I want to use it. More than two minutes for 344 separated terms in the end. The time consumption might be an issue because I need to apply the procedure to a term which contains even more subexpression in the end (order of magnitude more). – Display Name Sep 10 '18 at 11:10
• You're welcome. Please try also the new approach added. Maybe it is faster. – Henrik Schumacher Sep 10 '18 at 11:36
• It is indeed faster. Do you know by chance a way to reverse the action of distribute? A similar function like Together but for operators, such that in the end, one has wrapped again \[ScriptCapitalN] around the different subexpressions? – Display Name Sep 10 '18 at 12:32
• Yes you're right, trial and error can be daunting but probably it's the best way. Also in this way you apply it to real problems and not just these exemplary examples in the books. – Display Name Sep 10 '18 at 13:12