예제 #1
0
    def __pow__(self, n):
        """
        Return the `n^{th}` power of a factorization, which is got by
        combining together like factors.

        EXAMPLES::
        
            sage: f = factor(-100); f
            -1 * 2^2 * 5^2
            sage: f^3
            -1 * 2^6 * 5^6
            sage: f^4
            2^8 * 5^8

            sage: F = factor(2006); F
            2 * 17 * 59
            sage: F**2
            2^2 * 17^2 * 59^2

            sage: R.<x,y> = FreeAlgebra(ZZ, 2)
            sage: F = Factorization([(x,3), (y, 2), (x,1)]); F
            x^3 * y^2 * x
            sage: F**2
            x^3 * y^2 * x^4 * y^2 * x
        """
        from sage.groups.generic import power
        return power(self, n, Factorization([]))
예제 #2
0
    def __pow__(self, n):
        """
        Return the `n^{th}` power of a factorization, which is got by
        combining together like factors.

        EXAMPLES::
        
            sage: f = factor(-100); f
            -1 * 2^2 * 5^2
            sage: f^3
            -1 * 2^6 * 5^6
            sage: f^4
            2^8 * 5^8

            sage: F = factor(2006); F
            2 * 17 * 59
            sage: F**2
            2^2 * 17^2 * 59^2

            sage: R.<x,y> = FreeAlgebra(ZZ, 2)
            sage: F = Factorization([(x,3), (y, 2), (x,1)]); F
            x^3 * y^2 * x
            sage: F**2
            x^3 * y^2 * x^4 * y^2 * x
        """
        from sage.groups.generic import power
        return power(self, n, Factorization([]))
예제 #3
0
    def __pow__(self, n):
        """
        Return the `n^{th}` power of a factorization, which is got by
        combining together like factors.

        EXAMPLES::

            sage: f = factor(-100); f
            -1 * 2^2 * 5^2
            sage: f^3
            -1 * 2^6 * 5^6
            sage: f^4
            2^8 * 5^8

            sage: K.<a> = NumberField(x^3 - 39*x - 91)
            sage: F = K.factor(7); F
            (Fractional ideal (7, a)) * (Fractional ideal (7, a + 2)) * (Fractional ideal (7, a - 2))
            sage: F^9
            (Fractional ideal (7, a))^9 * (Fractional ideal (7, a + 2))^9 * (Fractional ideal (7, a - 2))^9

            sage: R.<x,y> = FreeAlgebra(ZZ, 2)
            sage: F = Factorization([(x,3), (y, 2), (x,1)]); F
            x^3 * y^2 * x
            sage: F**2
            x^3 * y^2 * x^4 * y^2 * x
        """
        if not isinstance(n, Integer):
            try:
                n = Integer(n)
            except TypeError:
                raise TypeError("Exponent n (= %s) must be an integer." % n)
        if n == 1:
            return self
        if n == 0:
            return Factorization([])
        if self.is_commutative():
            return Factorization([(p, n * e) for p, e in self],
                                 unit=self.unit()**n,
                                 cr=self.__cr,
                                 sort=False,
                                 simplify=False)
        from sage.groups.generic import power
        return power(self, n, Factorization([]))
예제 #4
0
    def __pow__(self, n):
        """
        Return the `n^{th}` power of a factorization, which is got by
        combining together like factors.

        EXAMPLES::

            sage: f = factor(-100); f
            -1 * 2^2 * 5^2
            sage: f^3
            -1 * 2^6 * 5^6
            sage: f^4
            2^8 * 5^8

            sage: K.<a> = NumberField(x^3 - 39*x - 91)
            sage: F = K.factor(7); F
            (Fractional ideal (7, a)) * (Fractional ideal (7, a + 2)) * (Fractional ideal (7, a - 2))
            sage: F^9
            (Fractional ideal (7, a))^9 * (Fractional ideal (7, a + 2))^9 * (Fractional ideal (7, a - 2))^9

            sage: R.<x,y> = FreeAlgebra(ZZ, 2)
            sage: F = Factorization([(x,3), (y, 2), (x,1)]); F
            x^3 * y^2 * x
            sage: F**2
            x^3 * y^2 * x^4 * y^2 * x
        """
        if not isinstance(n, Integer):
            try:
                n = Integer(n)
            except TypeError:
                raise TypeError("Exponent n (= %s) must be an integer." % n)
        if n == 1:
            return self
        if n == 0:
            return Factorization([])
        if self.is_commutative():
            return Factorization(
                [(p, n * e) for p, e in self], unit=self.unit() ** n, cr=self.__cr, sort=False, simplify=False
            )
        from sage.groups.generic import power

        return power(self, n, Factorization([]))