Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
r""" This module implements `\Q/n\Z` for `n \in \Q`.
When `n \in \Z`, you can construct these groups as follows::
sage: G = QQ/ZZ; G Q/Z sage: QQ/(2*ZZ) Q/2Z
You can create random elements::
sage: [G.random_element() for _ in range(4)] [15/16, 0, 1/2, 139/190]
There is an iterator over the (infinitely many) elements::
sage: import itertools sage: list(itertools.islice(G, 10)) [0, 1/2, 1/3, 2/3, 1/4, 3/4, 1/5, 2/5, 3/5, 4/5] """
#***************************************************************************** # Copyright (C) 2017 David Roe <roed.math@gmail.com> # # Distributed under the terms of the GNU General Public License (GPL) # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # http://www.gnu.org/licenses/ #*****************************************************************************
r""" The ``QmodnZ`` class represents the abelian group `\Q/n\Z`.
INPUT:
The constructor may be called in any of the following ways.
#. ``QmodnZ(n)``, where
- `n` -- a rational number (including 0 or negative rational numbers).
#. ``QQ/(n*ZZ)``, where
- `n` -- an integer (including 0 or negative integers).
OUTPUT:
The abelian group `\Q/n\Z`.
EXAMPLES::
sage: from sage.groups.additive_abelian.qmodnz import QmodnZ sage: QQ/(19*ZZ) Q/19Z
sage: QmodnZ(19) Q/19Z
sage: QmodnZ(2/3) Q/(2/3)Z """
r""" Initialization.
EXAMPLES::
sage: from sage.groups.additive_abelian.qmodnz import QmodnZ sage: G = QmodnZ(2) sage: G Q/2Z
TESTS::
sage: G = QQ/(19*ZZ) sage: TestSuite(G).run() """
r""" Display the group.
EXAMPLES::
sage: from sage.groups.additive_abelian.qmodnz import QmodnZ sage: G = QmodnZ(1); G Q/Z
sage: G = QQ/(3*ZZ); G Q/3Z
sage: G = QmodnZ(1/5); G Q/(1/5)Z """ else:
r""" Coercion from a parent ``S``.
There is a coercion from ``S`` if ``S`` has a coerce map to `\Q` or if `S = \Q/m\Z` for `m` a multiple of `n`.
TESTS::
sage: G2 = QQ/(2*ZZ) sage: G3 = QQ/(3*ZZ) sage: G4 = QQ/(4*ZZ) sage: G2.has_coerce_map_from(QQ) True sage: G2.has_coerce_map_from(ZZ) True sage: G2.has_coerce_map_from(ZZ['x']) False sage: G2.has_coerce_map_from(G3) False sage: G2.has_coerce_map_from(G4) True sage: G4.has_coerce_map_from(G2) False """
#TODO: Disallow order comparisons between different Q/nZ's # e.g., sage: QmodnZ(10/3) > QmodnZ(5/3) # returns False.
r""" Construct an element in `\Q/n\Z`.
EXAMPLES::
sage: from sage.groups.additive_abelian.qmodnz import QmodnZ sage: G = QmodnZ(2/3) sage: G(5/6) 1/6 """
""" Return an element, for use in coercion system.
TESTS::
sage: (QQ/ZZ).an_element() 0 """
""" Return some elements, for use in testing.
TESTS::
sage: L = (QQ/ZZ).some_elements() sage: len(L) 92 """
r""" Return a random element of `\Q/n\Z`. The denominator is selected using the ``1/n`` distribution on integers, modified to return a positive value. The numerator is then selected uniformly.
EXAMPLES::
sage: G = QQ/(6*ZZ) sage: G.random_element() 47/16 sage: G.random_element() 1 sage: G.random_element() 3/5 """ return self(QQ.random_element()) else:
r""" Creates an iterator that generates the elements of `\Q/n\Z` without repetition, organized by increasing denominator; for a fixed denominator elements are listed by increasing numerator.
EXAMPLES:
The first 19 elements of `\Q/5\Z`::
sage: import itertools sage: list(itertools.islice(QQ/(5*ZZ),19)) [0, 1, 2, 3, 4, 1/2, 3/2, 5/2, 7/2, 9/2, 1/3, 2/3, 4/3, 5/3, 7/3, 8/3, 10/3, 11/3, 13/3] """
for x in QQ: yield self(x) else: |