I'm trying to find a simple way to define a bilinear and Leibniz functional/map "$B(\cdot,\cdot)$", that eats two functions $f(x),f(y)$ or products theirof and produces the following, $$ B(f(x),f(y))=f(x**y-y**x) \,, $$

where "$**$" is a non-commutative product that's un-important for my question.

The problem I have is making the map $B(\cdot,\cdot)$ obey the Leibniz rule $$ B(f(x_1)f(x_2)...f(x_n),f(y))=\sum_if(x_1)...f(x_{i-1})B(f(x_i),f(y))f(x_{i+1})..f(x_n) \,. $$

I have read this question and tried the following code to implement just for Leibniz rule

B[f[x_], f[y_]] := f[x ** y - y ** x]
B[f[x_]*f[y_], f[z_]] := B[f[x], f[z]]*f[y] + f[x]*B[f[y], f[z]]

But the above code doesn't seem to understand how to handle power imputs of $f(x)$ with the same argument $x$, e.g. $f(x)^2$, and higher order products like $f(x)f(y)f(z)$. For example if I evaluate

B[f[a]^2, f[e]]
B[f[a]*f[b]*f[c], f[e]]

Mathematica doesn't seem to know what to do.

I guess it's because I only told Mathematica how to handle two imputs in one slot of $B(\cdot,\cdot)$. But since I am going to be manipulating higher order products of $f(x)$, how should I define the map $B$ without making one definition for each order of product/power of the imput function?

PS: The problem also comes up when I try to implement Bilinearity for the map $B$.


Try the following code:

B[f[x_],f[y_]]:=f[x**y-y**x]; B[x_Times,y_]:=Sum[ReplacePart[x,{i}:>B[x[[i]],y]],{i,Length[x]}]; B[Power[x_,y_],z_]:=y*Power[x,y-1]*B[x,z];

  • $\begingroup$ Thanks! I tried a few examples it worked out pretty well. May I ask what "x_Times" means in the 2nd line? And if you have the 2nd line, why do you still need the 3rd? I am trying to understand this well enough to impletement the bilinearity of B. Thanks! $\endgroup$ Apr 8 '20 at 22:49
  • $\begingroup$ @JDING x_Times is a pattern which represents an expression with head Times. Similarly, Power[x_, y_] is pattern represents an expression with head Power. For more detail, you may check the document for Pattern and Blank. Mathematically, x^2 can be identified with x*x. However, these are two different expressions in Mathematica. The former is of head Power, while the latter is of head Times (Mathematica would automatically replace x*x by x^2, but not vice versa). That's why we need the third line. $\endgroup$
    – Wen Chern
    Apr 9 '20 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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