def conj(P): """ Conjugate of a polynomial P. """ Pc = P.coefficients() x = P.parent().gen() return sum([Pc[p] * generic_power(x,p) for p in range(0,len(Pc))\ if Pc[p].imag() == 0]) - \ sum([Pc[p] * generic_power(x,p) for p in range(0,len(Pc)) \ if Pc[p].imag() != 0])
def _pow_int(self, n): """ Return ``self`` to the `n^{th}` power. INPUT: - ``n`` -- a positive integer EXAMPLES:: sage: S = Semigroups().example("leftzero") sage: x = S("x") sage: x^1, x^2, x^3, x^4, x^5 ('x', 'x', 'x', 'x', 'x') sage: x^0 Traceback (most recent call last): ... ArithmeticError: only positive powers are supported in a semigroup TESTS:: sage: x._pow_int(17) 'x' """ if n <= 0: raise ArithmeticError("only positive powers are supported in a semigroup") return generic_power(self, n)
def realpart(P): """ Real part of a polynomial P. (ie: compute sum P_i x^i only for P_i real). """ x = P.parent().gen() Pc = P.coefficients() return sum([Pc[p] * generic_power(x,p) for p in range(0,len(Pc)) \ if Pc[p].imag() == 0])
def impart(P): """ Imaginary part of a polynomial P. (ie: compute sum Im P_i x^i only for P_i imaginary). """ Pc = P.coefficients() x = P.parent().gen() Im = QQbar(I) return sum([-Im * Pc[p]*generic_power(x,p) \ for p in range(0,len(Pc)) if Pc[p].imag() != 0])
def _pow_int(self, n): r""" Return ``self`` to the `n^{th}` power. INPUT: - ``n`` -- a nonnegative integer EXAMPLES:: sage: S = Monoids().example() sage: S("a") ^ 5 'aaaaa' """ return generic_power(self, n)
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 """ from sage.rings.integer import Integer 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) if n < 0: self = ~self n = -n from sage.arith.power import generic_power return generic_power(self, n)
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) if n < 0: self = ~self n = -n from sage.arith.power import generic_power return generic_power(self, n)
def __pow__(self, n): """ Return the `n`-th power of the series. EXAMPLES:: sage: L.<z> = LazyLaurentSeriesRing(ZZ) sage: (1 - z)^-1 1 + z + z^2 + z^3 + z^4 + z^5 + z^6 + ... sage: (1 - z)^0 1 sage: (1 - z)^3 1 - 3*z + 3*z^2 - z^3 sage: (1 - z)^-3 1 + 3*z + 6*z^2 + 10*z^3 + 15*z^4 + 21*z^5 + 28*z^6 + ... """ if n == 0: return self.parent().one() return generic_power(self, n)