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,

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

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)

1 Answer 1


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.

  • $\begingroup$ 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! $\endgroup$
    – NeverMind
    Sep 10, 2018 at 11:03
  • $\begingroup$ 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). $\endgroup$
    – NeverMind
    Sep 10, 2018 at 11:10
  • $\begingroup$ You're welcome. Please try also the new approach added. Maybe it is faster. $\endgroup$ Sep 10, 2018 at 11:36
  • $\begingroup$ 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? $\endgroup$
    – NeverMind
    Sep 10, 2018 at 12:32
  • 1
    $\begingroup$ 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. $\endgroup$
    – NeverMind
    Sep 10, 2018 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.