8

When $A$ and $B$ are matrices, we have the following Taylor expansion for the inversion function together with basic information on convergence: $$ (A+B)^{-1}=A^{-1}-A^{-1}BA^{-1}+A^{-1}BA^{-1}BA^{-1}-A^{-1}BA^{-1}BA^{-1}BA^{-1}+..., $$ provided $Norm[A^{-1}B]<1$. So, my question is how we can write a code in Mathematica to write this approximation up to any desired term? For example, to obtain $(I+B)^{-1}$ up to six terms by keeping the fact that matrix multiplications are not commutative ($I$ is the identity matrix).

Can we also use three matrices inside, e.g. $(I+B+C)^{-1}$ and then compute the expansion using Mathematica?

Thank you in advance for any tips or tricks.

Lior Blech
  • 852
  • 5
  • 15
M.J.2
  • 491
  • 2
  • 8

5 Answers5

6

Such formal power series can be computed in NCAlgebra by recursively calculating then evaluating directional derivatives. NCDirectionalD[f,{x,h}] calculates the directional derivative of f with respect to x in the direction h. The following will leverage that to produce a formal power series of f of degree n taken with respect to x around x0:

NCSeries[f_, {x_, x0_, n_}] := Block[{h}, 
    SetNonCommutative[h]; 
    Plus @@ (Table[1/i!, {i, 0, n}]*NestList[NCDirectionalD[#, {x, h}] &, f, n]) /. x -> x0 /. h -> x]

Your example is reproduced by:

f = inv[a + b];
NCSeries[f, {b, 0, 4}]
(* a^-1 - a^-1 ** b ** a^-1 + a^-1 ** b ** a^-1 ** b ** a^-1 - a^-1 ** b ** a^-1 ** b ** a^-1 ** b ** a^-1 + a^-1 ** b ** a^-1 ** b ** a^-1 ** b ** a^-1 ** b ** a^-1 *)

Your other cases are calculated similarly:

NCSeries[inv[1 + b], {b, 0, 6}]
NCSeries[inv[1 + b + c], {b, 0, 6}]

A multivariate version can be computed in the same way.

Mauricio de Oliveira
  • 2,001
  • 13
  • 15
5

How about using NonCommutativeMultiply as matrix multiplication?

Then, we can let -1 escape the noncommutative multiply

Unprotect[NonCommutativeMultiply];
NonCommutativeMultiply[H___, Times[-1, M_], T___] := - NonCommutativeMultiply[H, M, T]

And do the Taylor series about the big matrix by the small matrix by hand:

inv[n_][big_, small_] := Total@FoldList[
     #1 ** #2 &, 
     Inverse[big], 
     -(small ** Inverse[big]) & /@ Range[n]
]

Then, inv[3][A, B] gives

Inverse[A] - Inverse[A] ** B ** Inverse[A] + 
Inverse[A] ** B ** Inverse[A] ** B ** Inverse[A] - 
Inverse[A] ** B ** Inverse[A] ** B ** Inverse[A] ** B ** Inverse[A]

and inv[3][A, B + C] gives

Inverse[A] - Inverse[A] ** (B + C) ** Inverse[A] + 
Inverse[A] ** (B + C) ** Inverse[A] ** (B + C) ** Inverse[A] - 
Inverse[A] ** (B + C) ** Inverse[A] ** (B + C) ** 
Inverse[A] ** (B + C) ** Inverse[A]
Chris K
  • 20,207
  • 3
  • 39
  • 74
evanb
  • 6,026
  • 18
  • 30
4
dotk[ab_, k_] := Dot @@ ConstantArray[ab, k]
dotk[ab_, 0] := IdentityMatrix[Length@ab];
mInvSeries[a_, b_, n_] := Sum[(-1)^k Inverse[a].dotk[(b.Inverse[a]), k], {k, 0, n}]

Usage

a = 10 {{6, 3}, {2, 8}};
ai = mInvSeries[a, IdentityMatrix[2], 150];

(a.ai ) // N

(* {{0.981341, 0.00691085}, {0.00460723, 0.985948}} *)
Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
  • Your answer is really nice in terms of numerical point of view. Please keep it but what I want is to obtain the expansion theoretically. I mean, we give A and B and obtain the matrix series up to 6 terms theoretically with consideration that matrix multiplication is not commutative. – M.J.2 Mar 21 '16 at 21:19
  • @M.J.2 Well, you can. But it is nasty: mInvSeries[{{a, b}, {c, d}}, IdentityMatrix[2], 3] – Dr. belisarius Mar 21 '16 at 21:29
  • @M.J.2 Oh! you probably mean this mInvSeries[IdentityMatrix[2], {{a, b}, {c, d}}, 3] – Dr. belisarius Mar 21 '16 at 21:30
  • I wish to see the result of the code exactly as in the formulation of the question, I mean in terms of $A$ and $B$. Or when the inputs are $I$ and $A$, in terms of $I$ and $A$. – M.J.2 Mar 21 '16 at 21:47
  • @M.J.2 Mathematica has no support for that notation. $I$ is the imaginary unit ... – Dr. belisarius Mar 21 '16 at 21:51
4

In the same spirit to Dr. belisarius' answer:

abSeries[A_, B_, a_, n_] := Series[Inverse[A + a B], {a, 0, n}]

After obtaining the series you can get the matrix without the a by using

ReplaceAll[Normal[abSeries[A, B, a, n]],a->1]

There is definitely a way to generate the expression you quoted for "general" matrices in mathematica, but since I don't know the math in detail I don't know how to teach mathematica to derive it either. Of course programming a known expression is easy, similarly to what Dr. belisarius did.

Addition

This might be more akin to what was originally intended:

abSeries[A_, B_, n_] := Plus @@ NestList[-Dot[Inverse[A].B, #] &, Inverse[A], n]

It gives an expression for general expressions A and B meaning you do not have to input a literal matrix for the expressions for this to work. Of course to get the final literal result you still need to put in the matrices using ReplaceAll after the calculation.

If you want to use three matrices you can simply put in the addition of two matrices as A or B. i.e. B=C+D. You can then use Distribute and Factor to put the resulting expression into different forms.

Example:

In[1]:=ReplaceAll[abSeries[a, ee b, 5].(a + ee b), {a -> PauliMatrix[1], b -> PauliMatrix[2]}] // Simplify
Out[1]:={{1 + ee^6, 0}, {0, 1 + ee^6}}
Lior Blech
  • 852
  • 5
  • 15
  • what "general" expression? If Ais the Identity, the result is a polynomial in B... there is no more "generality" than that AFAIK – Dr. belisarius Mar 21 '16 at 21:37
  • First of all notice in the question he commented the expression is only valid if $Norm[A^{-1}B]<1$. Second, I meant more general matrices like matrices of infinite dimensionality or for some generators of a Lie algebra etc. – Lior Blech Mar 21 '16 at 21:42
  • In general $A$ is not always Identity matrix. I believe this answer is better than the above one but this is not the expansion of the question! Because it does not keep the non-commutative property of matrix multiplications. Please choose $n=5$ and see the differences! – M.J.2 Mar 21 '16 at 21:42
  • I totally agree with the sentence "matrices of infinite dimensionality or for some generators of a Lie algebra etc." For example, I want to finally write the Taylor expansion of $(I+B+C)^{-1}$. So, the code should take $(B+C)$ as an input and then apply the Taylor expansion two times. – M.J.2 Mar 21 '16 at 21:45
  • @M.J.2 Please try running the following with my code mInvSeries[A, B, 3] Is that what you want? – Dr. belisarius Mar 21 '16 at 21:45
  • Amazing. Dr. belisarius comment is totally correct. Can you now please edit your code, and write how we can simplify the procedures when there are three matrices? Thanks. – M.J.2 Mar 21 '16 at 21:50
  • I have tested my code by multiplying the resulting matrix with the matrix A+B, and it gives the identity matrix up to the desired order in the expansion. – Lior Blech Mar 21 '16 at 21:50
  • The answer of Lior Blech is good but its result is not exactly the same to the formulation in the question. I mean, it does not keep the non-commutative property of the input matrices. – M.J.2 Mar 21 '16 at 21:56
  • I edited the answer. I'm not sure what you mean but this might answer your question. – Lior Blech Mar 21 '16 at 22:49
2

This answer is an attempt to provide a solution for a hypothetical user that does not know the general formula beforehand and is unaware of any packages.

The answer below considers that the user is aware of the following:

  • If $f$ is an expandable function that can be considered on the real line (for example $f(x)=(1+x)^{-1}$ or $f(x)=\exp(x)$), then, for a matrix variable $A$ and a real number valued variable $a$, $f(A)$=Replace[$f(a),a \rightarrow A$]. This point allows us to use Series for real valued variables.

  • For $A$ and $B$ two matrices $\left(A.B\right)^{-1}=B^{-1}.A^{-1}$. This point is used to place the initial expression into the form $f(x)$ where $f(x)=(1+x)^{-1}$ and $ x=A^{-1}.B $

Then if we define an identity tensor for the dot product:

Dot[s___, id, g___] ^:= Dot[s, g] 

The formula may be obtained with the following code that attempts to do simple replacements sequentially (var below is a formal wrapper that formally replaces a matrix with a real valued variable) :

Fold[ReplaceAll, 
Inverse[A + B] , 
{
Inverse[w_] :> Inverse[A . TensorExpand[Inverse@A . w]] ,
 Inverse[a_ . b_] :> Inverse[b] . Inverse[a],
 MatrixPower[_, 0] -> id,
 Inverse[id + s_] :> ReplaceAll[
                    Normal@Series[(1 + epsilon*var[s])^(-1),
                       {epsilon, 0, 3}] /. epsilon -&gt; 1

                    , {
                         var[a_]^m_:&gt;Dot@@ConstantArray[a,m]
                       , var-&gt;Identity
                       , 1 -&gt; id
                      }
                    ]

} ]//TensorExpand

out: (* -MatrixPower[A, -1] . B . MatrixPower[A, -1] + MatrixPower[A, -1] . B . MatrixPower[A, -1] . B . MatrixPower[A, -1] - MatrixPower[A, -1] . B . MatrixPower[A, -1] . B . MatrixPower[A, -1] . B . MatrixPower[A, -1] + MatrixPower[A, -1] *)

xzczd
  • 65,995
  • 9
  • 163
  • 468
userrandrand
  • 5,847
  • 6
  • 33