# Changeset 7682:6747edea46a8

Ignore:
Timestamp:
11/20/07 02:42:48 (6 years ago)
Branch:
default
Message:

n-th root for complex numbers, integer divisors

Location:
sage/rings
Files:
4 edited

Unmodified
Removed
• ## sage/rings/complex_double.pyx

 r7284 """ return RealDoubleElement(gsl_complex_abs(self._complex)) def argument(self): return RealDoubleElement(gsl_complex_arg(self._complex)) def abs2(self): return [z, -z] return z def nth_root(self, n, all=False): """ The n-th root function. INPUT: all -- bool (default: False); if True, return a list of all n-th roots. EXAMPLES: sage: a = CDF(125) sage: a.nth_root(3) 5.0 sage: a = CDF(10, 2) sage: [r^5 for r in a.nth_root(5, all=True)] [10.0 + 2.0*I, 10.0 + 2.0*I, 10.0 + 2.0*I, 10.0 + 2.0*I, 10.0 + 2.0*I] sage: abs(sum(a.nth_root(111, all=True))) # random but close to zero 6.00659385991e-14 """ if not self: return [self] if all else self arg = self.argument() / n abs = self.abs().nth_root(n) z = ComplexDoubleElement(abs * arg.cos(), abs*arg.sin()) if all: zeta = self._parent.zeta(n) return [z * zeta**k for k in range(n)] else: return z def is_square(self):
• ## sage/rings/complex_number.pyx

 r5809 return [z, -z] return z def nth_root(self, n, all=False): """ The n-th root function. INPUT: all -- bool (default: False); if True, return a list of all n-th roots. EXAMPLES: sage: a = CC(27) sage: a.nth_root(3) 3.00000000000000 sage: a.nth_root(3, all=True) [3.00000000000000, -1.50000000000000 + 2.59807621135332*I, -1.50000000000000 - 2.59807621135332*I] sage: a = ComplexField(20)(2,1) sage: [r^7 for r in a.nth_root(7, all=True)] [2.0000 + 1.0000*I, 2.0000 + 1.0000*I, 2.0000 + 1.0000*I, 2.0000 + 1.0000*I, 2.0000 + 1.0000*I, 2.0000 + 1.0000*I, 2.0000 + 1.0000*I] """ if not self: return [self] if all else self arg = self.argument() / n abs = self.abs().nth_root(n) z = ComplexNumber(self._parent, abs * arg.cos(), abs*arg.sin()) if all: zeta = self._parent.zeta(n) return [z * zeta**k for k in range(n)] else: return z def is_square(self):
• ## sage/rings/integer.pyx

 r7317 import sage.rings.integer_ring return sage.rings.integer_ring.factor(self, algorithm=algorithm, proof=proof) def prime_divisors(self, **kwds): return [p for p,e in self.factor(**kwds)] def coprime_integers(self, m):
• ## sage/rings/real_double.pyx

 r7319 raise ValueError, "negative number %s does not have a square root in the real field"%self return self._complex_double_(sage.rings.complex_double.CDF).sqrt(all=all) def is_square(self): """
Note: See TracChangeset for help on using the changeset viewer.