So, are Q and P supposed to represent Matrices, and all the other names represent scalars?
ee:=(Q+P)*a_1+P*a_2-((Q+P)*b_1+P*b_2)*(d_2*Q/d_1+P)/d_2:
U:=simplify(subs(Q=Id-P,ee),{P^2=P,Id^2=Id,Id*P=P}):
collect(expand(U),[P,Id]);
/ b_1 b_1 b_2\ / b_1\
|a_2 - --- + --- - ---| P + |a_1 - ---| Id
\ d_2 d_1 d_2/ \ d_1/
I was about to mention being careful about products such as Q*P since you've used the commuting multiplication *
instead of the noncommutative .
for multiplication. But perhaps it follows from your conditions that Q.P is the zero Matrix since Q.P+P = Q.P+P.P = (Q+P).P = P
. And the Q may be replaced by Id-P right away, anyway.