# 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}^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

### Bifurcation diagram for coupled nonlinear difference equations

1  Asked on February 26, 2021 by nightcape

### How to do a Inverse Discrete Fourier which contains frequency component?

1  Asked on February 26, 2021

### Multidimensional fit and interpolation for scattered unstructured data

1  Asked on February 26, 2021

### On making a graphical real-time memory usage monitor

3  Asked on February 26, 2021

### How to make functions from datasets

2  Asked on February 26, 2021 by catbasket

### Trying to build a code to translate handwritten formulas using ML

0  Asked on February 26, 2021 by gluoncito

### RootSearch warning “too small to represent as a normalized machine number”

1  Asked on February 25, 2021 by matheorem

### How do I initialise a compound expression in Animate? Or, how do I have an expression evaluate on startup?

1  Asked on February 25, 2021 by ross-keenan

### NDSolve giving a wrong solution

4  Asked on February 25, 2021 by fwgb

### BarChart with two ChartLabels

2  Asked on February 25, 2021 by javacake

### Using Mathematica for tensor analysis

2  Asked on February 25, 2021

### Replace symbols with values without evaluation

5  Asked on February 25, 2021 by tyilo

### Optimization problem over two variables

1  Asked on February 25, 2021

### Interactive Machine Learning App to make Predictions using Descriptors

1  Asked on February 25, 2021 by nawn

### State Space Model in Controllable Canonical Form

1  Asked on February 24, 2021 by user74620

### Turing patterns

2  Asked on February 24, 2021 by sankha

### How to make a smooth highly contrasted image from a Blur, without affecting the sides?

1  Asked on February 24, 2021

### Plotting a Piecewise function that returns implicit equations using ContourPlot

2  Asked on February 24, 2021

### Ways to speed up numerical integration

2  Asked on February 24, 2021 by corey979

### How to explain these results of integration of DiracDelta?

4  Asked on February 24, 2021

### Ask a Question

Get help from others!