def __init__(self, parent, x, bits=None, nterms=None): """ EXAMPLES:: sage: sage.rings.contfrac.ContinuedFraction(CFF,[1,2,3,4,1,2]) [1, 2, 3, 4, 1, 2] sage: sage.rings.contfrac.ContinuedFraction(CFF,[1,2,3,4,-1,2]) Traceback (most recent call last): ... ValueError: each entry except the first must be positive """ FieldElement.__init__(self, parent) if isinstance(x, ContinuedFraction): self._x = list(x._x) elif isinstance(x, (list, tuple)): x = [ZZ(a) for a in x] for i in range(1, len(x)): if x[i] <= 0: raise ValueError, "each entry except the first must be positive" self._x = list(x) else: self._x = [ ZZ(a) for a in continued_fraction_list(x, bits=bits, nterms=nterms) ]
def selmer_group(self, S, m, proof=True, orders=False): r""" Compute the group `\QQ(S,m)`. INPUT: - ``S`` -- a set of primes - ``m`` -- a positive integer - ``proof`` -- ignored - ``orders`` (default False) -- if True, output two lists, the generators and their orders OUTPUT: A list of generators of `\QQ(S,m)` (and, optionally, their orders in `\QQ^\times/(\QQ^\times)^m`). This is the subgroup of `\QQ^\times/(\QQ^\times)^m` consisting of elements `a` such that the valuation of `a` is divisible by `m` at all primes not in `S`. It is equal to the group of `S`-units modulo `m`-th powers. The group `\QQ(S,m)` contains the subgroup of those `a` such that `\QQ(\sqrt[m]{a})/\QQ` is unramified at all primes of `\QQ` outside of `S`, but may contain it properly when not all primes dividing `m` are in `S`. EXAMPLES:: sage: QQ.selmer_group((), 2) [-1] sage: QQ.selmer_group((3,), 2) [-1, 3] sage: QQ.selmer_group((5,), 2) [-1, 5] The previous examples show that the group generated by the output may be strictly larger than the 'true' Selmer group of elements giving extensions unramified outside `S`. When `m` is even, `-1` is a generator of order `2`:: sage: QQ.selmer_group((2,3,5,7,), 2, orders=True) ([-1, 2, 3, 5, 7], [2, 2, 2, 2, 2]) sage: QQ.selmer_group((2,3,5,7,), 3, orders=True) ([2, 3, 5, 7], [3, 3, 3, 3]) """ gens = list(S) ords = [ZZ(m)] * len(S) if m % 2 == 0: gens = [ZZ(-1)] + gens ords = [ZZ(2)] + ords if orders: return gens, ords else: return gens
def characteristic(self): """ Return 0, since the continued fraction field has characteristic 0. EXAMPLES:: sage: c = CFF.characteristic(); c 0 sage: parent(c) Integer Ring """ return ZZ(0)
def random_element(self, num_bound=None, den_bound=None, *args, **kwds): """ Return an random element of `\QQ`. EXAMPLES:: sage: QQ.random_element(10,10) 1/4 Passes extra positional or keyword arguments through:: sage: QQ.random_element(10,10, distribution='1/n') -1 """ global ZZ if ZZ is None: import integer_ring ZZ = integer_ring.ZZ if num_bound == None: num = ZZ.random_element(*args, **kwds) den = ZZ.random_element(*args, **kwds) while den == 0: den = ZZ.random_element(*args, **kwds) return self((num, den)) else: if num_bound == 0: num_bound = 2 if den_bound is None: den_bound = num_bound if den_bound < 1: den_bound = 2 num = ZZ.random_element(-num_bound, num_bound+1, *args, **kwds) den = ZZ.random_element(1, den_bound+1, *args, **kwds) while den == 0: den = ZZ.random_element(1, den_bound+1, *args, **kwds) return self((num,den))
def random_element(self, num_bound=None, den_bound=None, *args, **kwds): """ EXAMPLES:: sage: QQ.random_element(10,10) 1/4 Passes extra positional or keyword arguments through:: sage: QQ.random_element(10,10, distribution='1/n') -1 """ global ZZ if ZZ is None: import integer_ring ZZ = integer_ring.ZZ if num_bound == None: num = ZZ.random_element(*args, **kwds) den = ZZ.random_element(*args, **kwds) while den == 0: den = ZZ.random_element(*args, **kwds) return self((num, den)) else: if num_bound == 0: num_bound = 2 if den_bound is None: den_bound = num_bound if den_bound < 1: den_bound = 2 num = ZZ.random_element(-num_bound, num_bound + 1, *args, **kwds) den = ZZ.random_element(1, den_bound + 1, *args, **kwds) while den == 0: den = ZZ.random_element(1, den_bound + 1, *args, **kwds) return self((num, den))
def primes_of_bounded_norm_iter(self, B): r""" Iterator yielding all primes less than or equal to `B`. INPUT: - ``B`` -- a positive integer; upper bound on the primes generated. OUTPUT: An iterator over all integer primes less than or equal to `B`. .. note:: This function exists for compatibility with the related number field method, though it returns prime integers, not ideals. EXAMPLES:: sage: it = QQ.primes_of_bounded_norm_iter(10) sage: list(it) [2, 3, 5, 7] sage: list(QQ.primes_of_bounded_norm_iter(1)) [] """ try: B = ZZ(B.ceil()) except (TypeError, AttributeError): raise TypeError("%s is not valid bound on prime ideals" % B) if B < 2: raise StopIteration from sage.rings.arith import primes for p in primes(B + 1): yield p
def random_element(self, num_bound=None, den_bound=None, *args, **kwds): """ Return an random element of `\QQ`. Elements are constructed by randomly choosing integers for the numerator and denominator, not neccessarily coprime. INPUT: - ``num_bound`` -- a positive integer, specifying a bound on the absolute value of the numerator. If absent, no bound is enforced. - ``den_bound`` -- a positive integer, specifying a bound on the value of the denominator. If absent, the bound for the numerator will be reused. Any extra positional or keyword arguments are passed through to :meth:`sage.rings.integer_ring.IntegerRing_class.random_element`. EXAMPLES:: sage: QQ.random_element() -4 sage: QQ.random_element() 0 sage: QQ.random_element() -1/2 In the following example, the resulting numbers range from -5/1 to 5/1 (both inclusive), while the smallest possible positive value is 1/10:: sage: QQ.random_element(5, 10) -2/7 Extra positional or keyword arguments are passed through:: sage: QQ.random_element(distribution='1/n') 0 sage: QQ.random_element(distribution='1/n') -1 """ global ZZ if ZZ is None: import integer_ring ZZ = integer_ring.ZZ if num_bound is None: num = ZZ.random_element(*args, **kwds) den = ZZ.random_element(*args, **kwds) while den == 0: den = ZZ.random_element(*args, **kwds) return self((num, den)) else: if num_bound == 0: num_bound = 2 if den_bound is None: den_bound = num_bound if den_bound < 1: den_bound = 2 num = ZZ.random_element(-num_bound, num_bound+1, *args, **kwds) den = ZZ.random_element(1, den_bound+1, *args, **kwds) while den == 0: den = ZZ.random_element(1, den_bound+1, *args, **kwds) return self((num,den))
def random_element(self, num_bound=None, den_bound=None, *args, **kwds): """ Return an random element of `\QQ`. Elements are constructed by randomly choosing integers for the numerator and denominator, not neccessarily coprime. INPUT: - ``num_bound`` -- a positive integer, specifying a bound on the absolute value of the numerator. If absent, no bound is enforced. - ``den_bound`` -- a positive integer, specifying a bound on the value of the denominator. If absent, the bound for the numerator will be reused. Any extra positional or keyword arguments are passed through to :meth:`sage.rings.integer_ring.IntegerRing_class.random_element`. EXAMPLES:: sage: QQ.random_element() -4 sage: QQ.random_element() 0 sage: QQ.random_element() -1/2 In the following example, the resulting numbers range from -5/1 to 5/1 (both inclusive), while the smallest possible positive value is 1/10:: sage: QQ.random_element(5, 10) -2/7 Extra positional or keyword arguments are passed through:: sage: QQ.random_element(distribution='1/n') 0 sage: QQ.random_element(distribution='1/n') -1 """ global ZZ if ZZ is None: import integer_ring ZZ = integer_ring.ZZ if num_bound is None: num = ZZ.random_element(*args, **kwds) den = ZZ.random_element(*args, **kwds) while den == 0: den = ZZ.random_element(*args, **kwds) return self((num, den)) else: if num_bound == 0: num_bound = 2 if den_bound is None: den_bound = num_bound if den_bound < 1: den_bound = 2 num = ZZ.random_element(-num_bound, num_bound + 1, *args, **kwds) den = ZZ.random_element(1, den_bound + 1, *args, **kwds) while den == 0: den = ZZ.random_element(1, den_bound + 1, *args, **kwds) return self((num, den))