Be explicit and do it in two steps. The first step is just the series computation with the matrix expression M+S
replaced by a single variable:
f = Series[(1 + t x)^(-1), {t, 0, 3}]
$1-x t+x^2 t^2-x^3 t^3+O[t]^4$
We need to describe how to expand powers of x
. This can be done recursively:
power[a_, n_Integer] /; n > 1 := Distribute[a . power[a, n - 1]];
power[a_, 1] := a;
After a power is expanded, we also need to collect sequences of like terms into (matrix) powers. This solution does it explicitly by post-processing the result of Split
applied to such a sequence:
collect[a__] := With[{l = Power[First[#], Length[#]] & /@ Split[{a}]},
If[Length@l == 1, First@l, Dot @@ l]];
Apply these rules to the series, remembering also to expand x
itself when not wrapped inside Power
:
f /. {Power[x, n_] :> power[m + s, n], x -> m + s} /. Dot[a__] :> Dot[collect[a]]
$(1+(-m-s) t+(m.m+m.s+s.m+s.s) t^2+ \\ (-m.m.m-m.m.s-m.s.m-m.s.s-s.m.m-s.m.s-s.s.m-s.s.s) t^3+ \\ O[t]^4)$
For some reason the second replacement does not work (MMA 8.0). It appears to work with almost any head except Dot
! Here's a workaround:
f /. {Power[x, n_] :> power[m + s, n], x -> m + s} /. x_[a__] /; x === Dot :> x[collect[a]]
$1+(-m-s) t+(m^2+s^2+m.s+s.m) t^2+ \\ (-m^3-s^3-m.s^2-m^2.s-s.m^2-s^2.m-m.s.m-s.m.s) t^3+O[t]^4$