Ticket #15193: 15193-Factorization-pari.patch

File 15193-Factorization-pari.patch, 1.5 KB (added by pbruin, 8 years ago)
  • sage/structure/factorization.py

    # HG changeset patch
    # User Peter Bruin <P.Bruin@warwick.ac.uk>
    # Date 1379079713 -3600
    # Node ID 4954795dcbc6500559a748e648f52e1fa6e267f0
    # Parent  4275212b576c16066ba6d5e9574e057c7f558bc8
    Trac 15193: add method Factorization._pari_()
    
    diff --git a/sage/structure/factorization.py b/sage/structure/factorization.py
    a b  
    186186from sage.structure.sequence import Sequence
    187187from sage.rings.integer import Integer
    188188from sage.misc.all import prod
     189from sage.misc.cachefunc import cached_method
    189190
    190191class Factorization(SageObject):
    191192    """
     
    885886            s =  u + ' \\cdot ' + s
    886887        return s
    887888
     889    @cached_method
     890    def _pari_(self):
     891        """
     892        Return the PARI factorization matrix corresponding to ``self``.
     893
     894        EXAMPLES::
     895
     896            sage: f = factor(-24)
     897            sage: pari(f)
     898            [-1, 1; 2, 3; 3, 1]
     899
     900            sage: R.<x> = QQ[]
     901            sage: g = factor(x^10 - 1)
     902            sage: pari(g)
     903            [x - 1, 1; x + 1, 1; x^4 - x^3 + x^2 - x + 1, 1; x^4 + x^3 + x^2 + x + 1, 1]
     904
     905        """
     906        from sage.libs.pari.all import pari
     907        n = len(self)
     908        if self.__unit == 1:
     909            init = ()
     910        else:
     911            init = (self.__unit, 1)
     912            n += 1
     913        # concatenate (p, e) tuples
     914        entries = reduce(lambda f, g: f + g, self, init)
     915        return pari.matrix(n, 2, entries)
     916
    888917    def __add__(self, other):
    889918        """
    890919        Return the (unfactored) sum of self and other.