I want to make the rule for a generalized distributivity. In what I'm doing, I'll have expressions such as:

$$(a_1 + ...+ a_n)**a_{n+1}$$

And I want to transform them to:

$$(a_1 ** a_{n+1} + ...+ a_n ** a_{n+1})$$

I know how to do in case I have a foreseeable number of variables. I could use:

(a + b) ** c /. {(x_ + y_) ** z_ -> (x ** z + y ** z)}

As the number $n$ is arbitrary, I thought I could do something in the lines of:



But this does not work. I tried to probe why this doesn't work but found nothing relevant. Can you help me?


2 Answers 2


Not sure exactly how you want to use this, but the built in Distribute can do the work for you:

expression = (a + b + c) ** z;
(* a ** z + b ** z + c ** z *)

You can always use ReplaceRepeated (//.):

expr = (a + b + c + d) ** z;
expr //. {(x_ + y_) ** z_ -> (x ** z + y ** z)}
(* a ** z + b ** z + c ** z + d ** z *)

which applies the rule repeatedly until the expression doesn't change anymore.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.