4

I want to define an operator $(\partial_{t}+1)^{2}=\partial_{t}\partial_{t}+2\partial_{t}+1$. Then, I want it to act on $t$. My code looks like this:

op[t_] := (D[#, {t, 1}] + 1 #)^2 &
op[t][t]

Instead of giving $2+t$, its result is $(1+t)^{2}.$ To verify if $2+t$ is really the answer, I write the right-hand side of the operator in Mathematica. My code looks like this:

op[t_] := (D[#, {t, 2}] + 2*D[#, {t, 1}] + 1 #) &
op[t][t]

And, it gives $2+t$. I want to write the exponent explicitly because I plan to extend it to $5$ (instead of $2$), and act it on another function. Can someone help me on this? Thank you.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
RaymartJay
  • 53
  • 6

2 Answers2

7

(From my answer to the linked question)

Install the DifferentialOperator paclet with:

PacletInstall["https://github.com/carlwoll/DifferentialOperator/releases/download/0.1/DifferentialOperator-0.0.1.paclet"]

and load with:

<<DifferentialOperator`

The paclet defines an input auto replacement for a special partial character, which you must use instead of the normal \[Partial] character. Specifically, you must enter pd and not EscpdEsc. Then, you can define a differential operator and apply it to a function as follows:

enter image description here

Carl Woll
  • 130,679
  • 6
  • 243
  • 355
3

You want to use composition, not powers:

op := (D[#, {t, 1}] + #) &

op[t]

Out[86]= 1 + t

op[op[t]]

Out[87]= 2 + t

Composition[op, op]@t

Out[97]= 2 + t

Apply[Composition, Table[op, 5]]@(t^5)

Out[99]= 120 + 600 t + 600 t^2 + 200 t^3 + 25 t^4 + t^5

Expand[(x + 1)^5]

Out[101]= 1 + 5 x + 10 x^2 + 10 x^3 + 5 x^4 + x^5

ulvi
  • 1,808
  • 10
  • 15
  • 1
    Off topcic note: to play with it one needs to copy it and manually drop/delete In[85] and friends. Consider not pasting them and insert output as e.g. commented code or quoted block (>) – Kuba Mar 27 '18 at 07:05
  • Thank you. I think this is better. – RaymartJay Mar 27 '18 at 07:21