Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to apply a function (like the sum) among all elements of a list?

In magma you have the possibility of invoking

&+[x0, x1, x2]

and that will return the sum of the elements in the array. You can also replace the sum operator by another binary operator that is associative. I'm wondering if SageMath has a similar feature, I've been looking in the documentation and apparently the best option is to use the built-in function sum(), but this doesn't generalize to any other binary operation.

Thanks for the help!