I want to define an abstract multilinear function mlfunc in arbitrary arguments with the standard algebraic and analytic properties.
Implementing algebraic properties are easy, say here. I omit it since it is not relevant here.
Differentiation is implemented by something like this:
mlfunc /: D[mlfunc[args__], x_] :=
Sum[ReplacePart[mlfunc[args], i :> D[{args}[[i]], x]], {i,
Length[{args}]}]
To make it work as expected for sums, scalar products and higher derivatives (D[g[x]f[...]+f[...],{x,2}]), one needs to adjust system option
With[{old =
OptionValue[SystemOptions["DifferentiationOptions"],
"DifferentiationOptions" -> "ExcludedFunctions"]},
SetSystemOptions[
"DifferentiationOptions" ->
"ExcludedFunctions" -> DeleteDuplicates[Append[old, mlfunc]]]];
Then it works perfectly in all possible forms.
The next step is series expansion. I suppose Series uses D, so it should be already done, but it is not:
In[192]:= Series[mlfunc[f[x], g[x]], {x, 0, 1}]
(*not intended*)
Out[192]= SeriesData[x, 0, {
mlfunc[
f[0],
g[0]], Derivative[1][g][0] Derivative[0, 1][mlfunc][
f[0],
g[0]] + Derivative[1][f][0] Derivative[1, 0][mlfunc][
f[0],
g[0]]}, 0, 2, 1]
It seems that somehow Series ignores my upvalue assignment and treats mlfunc as an ordinary function. The expected result should be
(*correct result*)
SeriesData[x, 0, {
mlfunc[
f[0],
g[0]], mlfunc[
f[0],
Derivative[1][g][0]] + mlfunc[
Derivative[1][f][0],
g[0]]}, 0, 2, 1]
Question Can we let Series know the multilinear properties of mlfunc in some way and produce the correct series expansion result at any order of expansion?
Any help would be appreciated.
System`Private`InternalSeriesearlier, but I do not think hacking the internal functions is a good solution. I expect a canonical workaround out there. Thanks anyway. $\endgroup$