# ModulesWithBasis.linear_combination should be a method of Modules

Reported by: Owned by: mkoeppe major sage-9.2 linear algebra tscrim, egourgoulhon, gh-mjungmath Matthias Koeppe Travis Scrimshaw N/A f34d2a5 f34d2a5b563f8b5f0582d3f880065c5515dfcd00

### Description

This method does not need a basis.

Moving it to Modules will make it available in FiniteRankFreeModule.

        def linear_combination(self, iter_of_elements_coeff, factor_on_left=True):
r"""
Return the linear combination \lambda_1 v_1 + \cdots +
\lambda_k v_k (resp.  the linear combination v_1 \lambda_1 +
\cdots + v_k \lambda_k) where iter_of_elements_coeff iterates
through the sequence ((\lambda_1, v_1), ..., (\lambda_k, v_k)).

INPUT:

- iter_of_elements_coeff -- iterator of pairs
(element, coeff) with element in self and
coeff in self.base_ring()

- factor_on_left -- (optional) if True, the coefficients
are multiplied from the left; if False, the coefficients
are multiplied from the right

EXAMPLES::

sage: m = matrix([[0,1],[1,1]])
sage: J.<a,b,c> = JordanAlgebra(m)
sage: J.linear_combination(((a+b, 1), (-2*b + c, -1)))
1 + (3, -1)
"""
if factor_on_left:
return self.sum(coeff * element
for element, coeff in iter_of_elements_coeff)
else:
return self.sum(element * coeff
for element, coeff in iter_of_elements_coeff)


### comment:1 Changed 23 months ago by mkoeppe

• Branch set to u/mkoeppe/moduleswithbasis_linear_combination_should_be_a_method_of_modules

### comment:2 Changed 23 months ago by mkoeppe

• Authors set to Matthias Koeppe
• Commit set to f34d2a5b563f8b5f0582d3f880065c5515dfcd00
• Status changed from new to needs_review

New commits:

 ​f34d2a5 Move parent method linear_combination from ModulesWithBasis to Modules

### comment:3 Changed 22 months ago by tscrim

• Reviewers set to Travis Scrimshaw
• Status changed from needs_review to positive_review

Agreed. Addition and scalar multiplications are must-implements for the objects.

Thanks!

### comment:5 Changed 22 months ago by vbraun

• Branch changed from u/mkoeppe/moduleswithbasis_linear_combination_should_be_a_method_of_modules to f34d2a5b563f8b5f0582d3f880065c5515dfcd00
• Resolution set to fixed
• Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.