1
$\begingroup$

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:

t=2;
s=Sum[a[i]_,{i,t}]**(a[t+1]_)
ss=Sum[a[i]**a[t+1],{i,t}]

(a+b)**c/.{s->ss}

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

$\endgroup$

2 Answers 2

5
$\begingroup$

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;
Distribute[expression]
(* a ** z + b ** z + c ** z *)
$\endgroup$
2
$\begingroup$

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.

$\endgroup$

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.