Symbolics: Extend a rule to a sum with multiple terms

I have this:

@syms commutator(a, b)
myRule = @rule commutator((~a)+(~b), ~c) => commutator(~a, ~c) + commutator(~b, ~c)

how can I extend the rule to get:

myRule_ = @rule commutator((~a)+(~b)+(~d), ~c) => commutator(~a, ~c) + commutator(~b, ~c) + commutator(~d, ~c)

and so on, without handwriting the rules?

@shashi

1 Like

This works:

myRule_ = @rule commutator(+(~~xs), ~c) => sum(commutator(~i, ~c) for i in (~~xs))