# Ticket #15193: 15193-Factorization-pari-chain.patch

File 15193-Factorization-pari-chain.patch, 1.6 KB (added by pbruin, 8 years ago)

same but using itertools.chain

• ## sage/structure/factorization.py

# HG changeset patch
# User Peter Bruin <P.Bruin@warwick.ac.uk>
# Date 1380294535 -3600
# Node ID 36f7c2d9d76f3982c4ccb69a06a70cf33808de64
# Parent  4275212b576c16066ba6d5e9574e057c7f558bc8
Trac 15193: add method Factorization._pari_(), using itertools.chain

diff --git a/sage/structure/factorization.py b/sage/structure/factorization.py
 a from sage.structure.sequence import Sequence from sage.rings.integer import Integer from sage.misc.all import prod from sage.misc.cachefunc import cached_method class Factorization(SageObject): """ s =  u + ' \\cdot ' + s return s @cached_method def _pari_(self): """ Return the PARI factorization matrix corresponding to self. EXAMPLES:: sage: f = factor(-24) sage: pari(f) [-1, 1; 2, 3; 3, 1] sage: R. = QQ[] sage: g = factor(x^10 - 1) sage: pari(g) [x - 1, 1; x + 1, 1; x^4 - x^3 + x^2 - x + 1, 1; x^4 + x^3 + x^2 + x + 1, 1] """ from sage.libs.pari.all import pari from itertools import chain n = len(self) if self.__unit == 1: init = () else: init = (self.__unit, 1) n += 1 # concatenate (p, e) tuples entries = init + tuple(chain.from_iterable(self)) return pari.matrix(n, 2, entries) def __add__(self, other): """ Return the (unfactored) sum of self and other.