0
$\begingroup$

I use NC ALgebra to deal with polynomials in non commutative variables ei and fj. The eis do not commute with themselves, the fjs do not commute with themselves, but the ei commute with the fjs. So e2 ** f1 = f1 ** e2 but e1 ** e3 != e3 ** e1

Now, here are a few examples of the transformations I want to implement:

e1 ** e3 -> e1.e3

e1 ** f4 -> e1 ** f4

e2 ** e3 ** f2 ** f4 ** f3 -> (e2.e3) ** (f2.f4.f3)

As you can see, I want to change the product in between the eis and in between the fjs.

I would like this to be doable for a variable number of monomials. Here's the code I produced :

<< NC`
<< NCAlgebra`;  

pair2var[x_, j_] := ToExpression[ToString[x] <> ToString[j]]

n = 4 ; m = 4 ;

evars = Table[ pair2var[e, i], {i, n}];
fvars = Table[ pair2var[f, i], {i, m}];

SetNonCommutative @@ evars
SetNonCommutative @@ fvars

length = 4;
evars1 = Flatten[Table[evars, {i, 1, 4}]];
fvars1 = Flatten[Table[fvars, {i, 1, 4}]];
epermu = 
  Select[Permutations[evars1, length], UnsameQ[#, {}] &] // Reverse;
fpermu = 
  Select[Permutations[fvars1, length], UnsameQ[#, {}] &] // Reverse;
SeparatingCommutativeVariables[poly_] := 
 NCReplaceRepeated[poly, 
  Join[Flatten[
    Table[(i /. List -> NonCommutativeMultiply) ** (j /. 
         List -> NonCommutativeMultiply) -> (i /. 
         List -> Dot) ** (j /. List -> Dot), {i, epermu}, {j, 
      fpermu}]]]]

This code is working but it is too slow If someone has suggestion to do the same thing but faster, I would greatly appreciate their help.

Thanks in advance !


PS : precision on the context

I am implementing a quantum information problem on Mathematica and I have to deal with polynomials in variables {e1,e2,e3,e4} and {f1,f2,f3,f4}.

Given an expression of the form : e1 + f2 ** e3 ** f2 ** e4 + f2 ** f1, I want to separate the different variables, and apply two different functions, FuncE and FuncF on each type :

FuncE[e1]*FuncF[Identity] + FuncE[e3,e4] * FuncF[f2,f4] + FuncE[Identity]*Funcf[f2,f1].

So far, my strategy has been to: 1 - put all the variables ei on the left, the variables fjs on the right 2 - change the product in between eis, in between fjs, but not between eis and fjs (see question above) 3 - Apply FuncE and FuncF on the right variables by recognizing a pattern : A**B-> FuncE[A]*FuncF[B]

This strategy leads to some problems, notably to deal with expressions where one of the two types of variables do not appear (for instance e2 ** e3 or f1 ** f4 ** f2). Please not that I already considered considering a Kronecker product between eis and fjs, but this is too slow.

$\endgroup$

1 Answer 1

1
$\begingroup$

Checkout the NCPoly functionality in NCAlgebra. Depending on what you want to do, it might help.

https://ncalgebra.github.io/#PolysWithCommutativeCoefficients

https://ncalgebra.github.io/#PackageNCPoly

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.