# Implementing binomial expansion of (non-commuting) matrices in Mathematica

Mathematica Asked by Rob on July 31, 2020

Given two matrices $$A$$ and $$B$$, their Binomial expansion is, in general, given by (see this page)

$$(A+B)^n = sumlimits_{k=0, k=n[2]}^n Bigg( sumlimits_{r=0}^k binom{k}{r} A^r B^{k-r} Bigg) Bigg(frac{-C}{2}Bigg)^{frac{n-k}{2}} frac{n!}{k!(frac{n-k}{2})!}$$

Here, $$C=AB-BA$$, is the commutator of $$A$$ and $$B$$. For matM = {{m11, m12}, {m21, m22}}; matN = {{n11, n12}, {n21, n22}};, how can one implement the above formula in Mathematica, say for simple case with $$n=2$$?

commutator[a_, b_] := a.b - b.a
mtxbinomial[a_, b_, n_] :=
Block[{c = commutator[a, b], zeros = ConstantArray[0, Dimensions[a]]},
If[c == zeros,
Message[commutator::args, "Matrices A and B commute!"]; Abort[]
];
Sum[
If[Mod[k, 2] == Mod[n, 2],
Sum[Binomial[k, r] MatrixPower[a, r].MatrixPower[b, k - r], {r, 0, k}].
MatrixPower[-c/2, (n - k)/2]*n!/(k! ((n - k)/2)!),
zeros],
{k, 0, n}]]


Testing $$(A+B)^2$$ gives True for some random matrices:

a = RandomReal[{-1, 1}, {5, 5}];
b = RandomReal[{-1, 1}, {5, 5}];
expected = MatrixPower[a + b, 2];
mtxbinomial[a, b, 2] == expected


Answered by flinty on July 31, 2020

## Related Questions

### How to plot spherical harmonics using two primary colors?

1  Asked on May 27, 2021 by donald-obama

### Mean of TransformedDistribution returns wrong result

0  Asked on May 26, 2021 by r-y-zhao

### Vertex labels versus vertex names in VertexRenderingFunction

2  Asked on May 26, 2021

### How to format a Grid command

2  Asked on May 26, 2021

### PointValuePlot can’t generate vector figure when set ColorFunction->”Rainbow”

1  Asked on May 26, 2021 by chuannan-li

### Should this Dataset be Transposed for best Neural-Net Performance?

0  Asked on May 26, 2021

### What fraction of a mountain parcel has slopes over 15%?

2  Asked on May 26, 2021 by matt-f

### Optimizing a slow For loop

1  Asked on May 26, 2021 by lele

### How to plot HeavisideTheta with y=0.5 at x=0, and similar piecewise functions

2  Asked on May 26, 2021

### NDSolve with a 0/0 error

1  Asked on May 25, 2021

### How to perform integration with Dirac Delta in Mathematica?

0  Asked on May 25, 2021 by gbd

### Extract the boundary from a ListContourPlot

2  Asked on May 25, 2021

### Labeling coordinate curves in ParametricPlot

1  Asked on May 25, 2021 by gilonik

### UnityLink called from wolframscript seems to work, but

0  Asked on May 25, 2021 by rlj

### Is it possible to make a composite tooltip with multiple data types?

1  Asked on May 25, 2021 by r-hall

### How do I recreate the lines and labels as seen in this image?

0  Asked on May 25, 2021

### Can Mathematica be wrong about the solution of a non-linear system?

1  Asked on May 25, 2021 by antonio-j-gmez

### How to prevent NDSolve to store result for each time step?

1  Asked on May 25, 2021 by rodion-stepanov

### How should I define the Cayley transform?

1  Asked on May 24, 2021 by the_lar

### Colorize a Region

1  Asked on May 24, 2021

### Ask a Question

Get help from others!