Opened 3 months ago

Closed 3 months ago

#30179 closed enhancement (fixed)

ModulesWithBasis.linear_combination should be a method of Modules

Reported by: mkoeppe Owned by:
Priority: major Milestone: sage-9.2
Component: linear algebra Keywords:
Cc: tscrim, egourgoulhon, gh-mjungmath Merged in:
Authors: Matthias Koeppe Reviewers: Travis Scrimshaw
Report Upstream: N/A Work issues:
Branch: f34d2a5 (Commits) Commit: f34d2a5b563f8b5f0582d3f880065c5515dfcd00
Dependencies: Stopgaps:

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)

Change History (5)

comment:1 Changed 3 months ago by mkoeppe

  • Branch set to u/mkoeppe/moduleswithbasis_linear_combination_should_be_a_method_of_modules

comment:2 Changed 3 months ago by mkoeppe

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

New commits:

f34d2a5Move parent method linear_combination from ModulesWithBasis to Modules

comment:3 Changed 3 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.

comment:4 Changed 3 months ago by mkoeppe

Thanks!

comment:5 Changed 3 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.