4
$\begingroup$

I have the following function $$ B(n)=x \alpha ^n-y \alpha ^n q^n + \epsilon \left(x \alpha ^{n+1}-y \alpha ^{n+1} q^{n+1}\right). $$ Here, I want to find the product $B(n)^2$ or $B(n)*B(n+1)$ where the variables $x$ and $y$ are non-commutative i.e. $xy\neq yx$. Is there any way to achieve this in Mathematica ?

For example, when I try to find the product in Mathematica, I find that

$$ B(n)^2 = -2 x y \epsilon ^2 \alpha ^{2 n+2} q^{n+1}-2 x y \epsilon \alpha ^{2 n+1} q^{n+1}+y^2 \epsilon ^2 \alpha ^{2 n+2} q^{2 n+2}+2 y^2 \epsilon \alpha ^{2 n+1} q^{2 n+1}+y^2 \alpha ^{2 n} q^{2 n}-2 x y \epsilon \alpha ^{2 n+1} q^n-2 x y \alpha ^{2 n} q^n+x^2 \epsilon ^2 \alpha ^{2 n+2}+2 x^2 \epsilon \alpha ^{2 n+1}+x^2 \alpha ^{2 n} $$ and $$ B(n)*B(n+1) = -x y \epsilon ^2 \alpha ^{2 n+3} q^{n+1}-x y \epsilon ^2 \alpha ^{2 n+3} q^{n+2}-2 x y \epsilon \alpha ^{2 n+2} q^{n+1}-x y \epsilon \alpha ^{2 n+2} q^{n+2}-x y \alpha ^{2 n+1} q^{n+1}+y^2 \epsilon ^2 \alpha ^{2 n+3} q^{2 n+3}+2 y^2 \epsilon \alpha ^{2 n+2} q^{2 n+2}+y^2 \alpha ^{2 n+1} q^{2 n+1}-x y \epsilon \alpha ^{2 n+2} q^n-x y \alpha ^{2 n+1} q^n+x^2 \epsilon ^2 \alpha ^{2 n+3}+2 x^2 \epsilon \alpha ^{2 n+2}+x^2 \alpha ^{2 n+1}. $$ But it must be that $xy \neq yx$.

$\endgroup$
4
  • $\begingroup$ There is a question similar to my topic that is stackoverflow.com/questions/7320735/…. I want to do it in Mathematica. $\endgroup$
    – drxy
    Feb 4, 2020 at 11:13
  • $\begingroup$ Have you seen NonCommutativeMultiply? $\endgroup$ Feb 5, 2020 at 5:08
  • $\begingroup$ @CATrevillian; Yes I saw it but I couldn't use for my case. If is it possible, could you please explain how to apply NonCommutativeMultiply to my function $B(n)$? $\endgroup$
    – drxy
    Feb 5, 2020 at 8:29
  • $\begingroup$ Shouldn’t it just be B[n]**B[n+1]? $\endgroup$ Feb 5, 2020 at 12:16

1 Answer 1

3
$\begingroup$

In the light of Mathematica's NonCommutativeMultiply, I have solved the problem as follows:

B[n_] := (a ** x + b ** y) + (b ** x + a ** y ** q^n);

ExpandNCM[(h : NonCommutativeMultiply)[a___, b_Plus, c___]] := 
 Distribute[h[a, b, c], Plus, h, Plus, ExpandNCM[h[##]] &]

ExpandNCM[(h : NonCommutativeMultiply)[a___, b_Times, c___]] := 
 Most[b] ExpandNCM[h[a, Last[b], c]]

ExpandNCM[a_] := ExpandAll[a]

B[n]**B[n + 1] // ExpandNCM // ExpandAll

= a ** x ** a ** x + a ** x ** b ** x + a ** x ** b ** y + 
  b ** x ** a ** x + b ** x ** b ** x + b ** x ** b ** y + 
  b ** y ** a ** x + b ** y ** b ** x + b ** y ** b ** y + 
  a ** x ** a ** y ** q^(1 + n) + a ** y ** q^n ** a ** x + 
  a ** y ** q^n ** b ** x + a ** y ** q^n ** b ** y + 
  b ** x ** a ** y ** q^(1 + n) + b ** y ** a ** y ** q^(1 + n) + 
  a ** y ** q^n ** a ** y ** q^(1 + n)

The only problem is that you must simplify some expressions with manually.

Thank you @CATrevillian.

$\endgroup$
4
  • 1
    $\begingroup$ Nice job! I was gonna try to comment on a cool extension wherein you could use TagSet or the-like to define the behavior of Power in the case of this type of NonCommutativeMultiply, but alas, I couldn't make the extension function properly. This is awesome! Great work here, drxy. $\endgroup$ Feb 5, 2020 at 14:24
  • $\begingroup$ Dear @CATrevillian; I have seen before NonCommutativeMultiply. But my inspiration came from after reading your post. So thank you very much. $\endgroup$
    – drxy
    Feb 5, 2020 at 16:54
  • $\begingroup$ your constructs are quite advanced, for me at least, so I thank you for this in return! If I might ask for clarification, can you explain the pieces of your code, how they work/your choices in how you formatted them? $\endgroup$ Feb 5, 2020 at 20:12
  • 1
    $\begingroup$ @CATrevillian; I have edited the answer. For the sake of simplicity, I define different $B(n)$ but I think that this code is more clear than previous one. $\endgroup$
    – drxy
    Feb 6, 2020 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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