# Differentiation of non-commutative polynomials in Sage

Let $f$ be a polynomial in the non-commutative polynomial ring $K[[x_1,..,x_n]]$ in $n$ variables. Define a $K$-linear map for an $i$ with $1 \leq i \leq n$ as $d_i : K[[x_1,..,x_n]] \rightarrow K[[x_1,..,x_n]]$ on monomials as $d_i (f)= g$ if $f=x_i g$ and $d_i (f)= 0$ else, so that this operator simply strikes off the leftmost $x_i$.

Define the $K$-linear (cyclic) differentiation operator for an $i$ with $1 \leq i \leq n$ as $\delta_i: K[[x_1,..,x_n]] \rightarrow K[[x_1,..,x_n]]$ on monomials as $\delta_i ( x_{i_1} \cdots x_{i_t} )= \sum\limits_{j=1}^{t} { d_i (x_{i_j} x_{i_{j+1}} \cdots x_{i_t} x_{i_1} \cdots x_{i_{j-1}}})$.

Question: Is there an easy (or even already existing) way to obtain the result of applying $\delta_i$ to a non-commutative polynomial using Sage?

edit retag close merge delete

Sort by » oldest newest most voted

If i correctly understood the cyclic differential, the following pedestrian code should do the job...

def delta(f, i):
"""Implement $d_i$ on elements f of a free algebra with N generators.
Here, we expect that i is among 0, 1, ... , N-1.

Below, there is a commented print.
For the test non-commutative polynomial f from

F.<a,b,c> = FreeAlgebra(QQ)
f = a^3*b^2*a*c*b + 3*a*b^3*c - 7*a^3

it delivers:

Derivating monomial a^3*b^2*a*c*b
(alias [(a, 3), (b, 2), (a, 1), (c, 1), (b, 1)] as a list)
with coefficient 1.

Derivating monomial a*b^3*c
(alias [(a, 1), (b, 3), (c, 1)] as a list)
with coefficient 3.

Derivating monomial a^3
(alias [(a, 3)] as a list)
with coefficient -7.

Hope this explains the implementation now...
"""
F = f.parent()
N = len(F.gens())
if i not in range(N):
return F(0)

v = F.gens()[i]    # and we cyclically differentiate w.r.t. v

monomials = []    # so far, and we append monomials from derivations
for mon, mon_coeff in f:
# print('Derivating monomial {}\n(alias {} as a list)\nwith coefficient {}.\n'
#       .format(mon, list(mon), mon_coeff))
mon_list = list(mon)
L = len(mon_list)    # there are L entries in this list
for j in range(L):
if mon_list[j] == v:
p = mon_list[j] * v^(mon_list[j] - 1) \
* prod([mon_list[(j + k) % L] ^ mon_list[(j + k) % L]
for k in range(1, L)])

monomials.append(mon_coeff*p)
return sum(monomials)


Test:

F.<a,b,c> = FreeAlgebra(QQ)
f = a^3*b^2*a*c*b + 3*a*b^3*c - 7*a^3
print(f'f = {f}')
print(f'delta0 f = {delta(f, 0)}')
print(f'delta1 f = {delta(f, 1)}')
print(f'delta2 f = {delta(f, 2)}')


This delivers:

f = -7*a^3 + 3*a*b^3*c + a^3*b^2*a*c*b
delta0 f = -21*a^2 + 3*b^3*c + 3*a^2*b^2*a*c*b + c*b*a^3*b^2
delta1 f = 9*b^2*c*a + a^3*b^2*a*c + 2*b*a*c*b*a^3
delta2 f = 3*a*b^3 + b*a^3*b^2*a

more

Probably I didn't understand correctly the question, but I tend to think that the OP wants to implement Voiculescu's cyclic derivative. Then $\delta_a$ on the monomial $a^3b^2acb$ would be $a^2b^2acb + ab^2acba + b^ 2 acba^2 + cba^3b^2$ (the cyclicity comes from the last sum over all the "letters" and dropping always the first, if the first variable $x$ coincides with that of the nc derivative, $\delta_x$), and the answer from the code is $3 a^2 b^2 a c b + c ba^3b^2$. But I think your code has otherwise nailed it (I'm just too new to SageMath to know how to fix this).

Thank you very much for the answer. I will do some tests. The definition can also be found in the beginning of section 3 of https://www.maths.gla.ac.uk/~mwemyss/... . I will try it on some other examples now.