I have my own version of Dot
called mydot
, and it behaves quite similar to the built-in version in that it represents the non-commutative product of a string of objects. Also, mydot
is supposed to support differentiation that behaves in the same way as Dot
. But I am unable to get D
to operate on mydot
the same way D
works on built-in Dot
:
D[Dot[x, (x + a y), z], y]
But
D[mydot[x, (x + a y), z], y]
I tried:
Derivative[ndiff__][mydot][x__] :=
ReplaceAll[Derivative[ndiff][Dot][x], Dot :> mydot];
D[mydot[x, (x + a y), z], y]
As you can see, the serious problem I'm having is that it is pulling the factor a
outside of mydot
, which is incorrect.
Trying to get this to behave properly by making definitions of Derivative
fails, because the chain rule has already been applied:
Derivative[ndiff__][mydot][x__] := stuff;
D[mydot[x, (x + a y), z], y]
How do I program D
and Derivative
to apply chain rule to the symbol mydot
correctly?
ClearAttributes[D, Protected]; D[expr_, args__] := Block[{$inD = True, result}, result = (D[expr /. mydot[seq___] :> NonCommutativeMultiply[seq], args]) /. NonCommutativeMultiply[seq___] :> mydot[seq]; result ] /; ! TrueQ[$inD] SetAttributes[D, Protected];
$\endgroup$ – QuantumDot Jan 10 '16 at 13:26UpValues
of built-in symbolD[]
. $\endgroup$ – xyz Jan 10 '16 at 13:33UpValues
whenmydot
can be arbitrarily deep inside of an expression? $\endgroup$ – QuantumDot Jan 10 '16 at 14:19myD
function? Something likemyD[expr_, args__] := (D[expr /. mydot -> NonCommutativeMultiply, args]) /. NonCommutativeMultiply -> mydot
. $\endgroup$ – Virgil Jan 12 '16 at 19:04