# How to define a composition of operators?

If I define P[x]=D[#,x]& (derivative operator) How can I define another operator $$Q$$ such that $$Q(f(x))=Pf(x)+a$$ (for example)? Thanks.

• P = D[#, x] &; Q = a + P[#] & Commented Apr 17 at 23:15

A direct nesting of function seems not to be part of Mathematica, because of the central aim to shield functions from evaluations.

So one has to introduce lots of local variables, evaluating and refunctionalize.

To avoid the overhead of symbols, copy math use of 'x' (not Mathematicas x=#, still to be used in the inner machine)

FChain[f_List] := Block[{x},
Function @@ {{x}, Fold[( #2[#1] &), x , Reverse@f]}]

d=FChain[{(1/Sqrt[2 \[Pi] t] #&) ,Exp,( (-#^2)/(2 t)&)}]


$$\{x\}\mapsto \frac{e^{-\frac{x^2}{2 t}}}{\sqrt{2 \pi } \sqrt{t}}$$

For practical purposes, one may include an option with simplifying or representing goals, eg. Simpify, Expand etc, to be applied before the expression is converted into a sealed function body again.

• What is direct nesting of function? Commented Apr 19 at 13:35
• The standard notation $$f \circ g = f @ g$$ Commented Apr 19 at 17:07
• Commented Apr 19 at 19:47
• The Mathematica chain '@' symbol in a@b is the prefix form of a[b], but is executed only as the transport of values through fixed function bodies as expressions, a very slow numerical construct in contrast to the speed available by a construction of the optimized combination of two function bodies. Any function call implies argument streamlining, standard simplification, domain checking and known result searches. Workin by chains of functions inside a pure function goes blind. Commented Apr 19 at 20:11
• @yarchik Composition does not construct the composed function. It's merely a container of @a@.., that evaluates only with an argument supplied. Of course the argument can be #, and then a function can be defined by e.g. Function@@{Compose[a,b][#]} Commented Apr 20 at 10:56