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""" Elements of `\Q/n\Z`.
EXAMPLES::
sage: A = QQ / (3*ZZ) sage: x = A(11/3); x 2/3 sage: x*14 1/3 sage: x.additive_order() 9 sage: x / 3 2/9 """
#***************************************************************************** # 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_Element`` class represents an element of the abelian group `\Q/n\Z`.
INPUT:
- ``q`` -- a rational number.
- ``parent`` -- the parent abelian group `\Q/n\Z`.
OUTPUT:
The element `q` of abelian group `\Q/n\Z`, in standard form.
EXAMPLES::
sage: G = QQ/(19*ZZ) sage: G(400/19) 39/19 """ r""" Create an element of `\Q/n\Z`.
EXAMPLES::
sage: G = QQ/(3*ZZ) sage: G.random_element() 47/16 """
# x = (a/b) = q(n/m) + r/mb # am = q(nb) + r # r < nb so r/mb < n/m self._x = x else:
r""" Return the smallest non-negative rational number reducing to this element.
EXAMPLES::
sage: G = QQ/(5*ZZ) sage: g = G(2/4); g 1/2 sage: q = lift(g); q 1/2
TESTS::
sage: q.parent() is QQ True """
r""" Lift to `\Q`.
TESTS::
sage: QQ((QQ/ZZ)(4/3)) # indirect doctest 1/3 """
r""" Lift to `\Z`.
This is the smallest non-negative integer reducing to this element, or a ``ValueError`` if none exists.
TESTS::
sage: G = QQ/(2*ZZ) sage: ZZ(G(3)) 1 sage: from sage.groups.additive_abelian.qmodnz import QmodnZ sage: G = QmodnZ(8/3) sage: ZZ(G(1/3)) 3
sage: all(ZZ(G(i)) == i for i in range(8)) True
sage: G = QmodnZ(101/34) sage: all(ZZ(G(i)) == i for i in range(101)) True """ raise ValueError("No integral lift") # a/m + q*(n/m) = (a + qn)/m = km/m so a + qn = km, # k = a*m^(-1) mod n.
r""" Return the additive inverse of this element in `\Q/n\Z`.
EXAMPLES::
sage: from sage.groups.additive_abelian.qmodnz import QmodnZ sage: G = QmodnZ(5/7) sage: g = G(13/21) sage: -g 2/21
TESTS::
sage: G = QmodnZ(19/23) sage: g = G(15/23) sage: -g 4/23 sage: g + -g == G(0) True """ return self else:
r""" Return the sum of two elements in `\Q/n\Z`.
EXAMPLES::
sage: from sage.groups.additive_abelian.qmodnz import QmodnZ sage: G = QmodnZ(9/10) sage: g = G(5) sage: h = G(1/2) sage: g + h 1/10 sage: g + h == G(1/10) True
TESTS::
sage: h + g == G(1/10) True """
r""" Returns the difference of two elements in `\Q/n\Z`.
EXAMPLES::
sage: from sage.groups.additive_abelian.qmodnz import QmodnZ sage: G = QmodnZ(9/10) sage: g = G(4) sage: h = G(1/2) sage: g - h 4/5 sage: h - g 1/10 sage: g - h == G(4/5) True sage: h - g == G(1/10) True """
r""" Returns the (right) scalar product of this element by ``c`` in `\Q/n\Z`.
EXAMPLES::
sage: from sage.groups.additive_abelian.qmodnz import QmodnZ sage: G = QmodnZ(5/7) sage: g = G(13/21) sage: g*6 1/7 """
r""" Returns the (left) scalar product of this element by ``c`` in `\Q/n\Z`.
EXAMPLES::
sage: from sage.groups.additive_abelian.qmodnz import QmodnZ sage: G = QmodnZ(5/7) sage: g = G(13/21) sage: 6*g 1/7
TESTS::
sage: 6*g == g*6 True sage: 6*g == 5*g False """
r""" Division.
.. WARNING::
Division of `x` by `m` does not yield a well defined result, since there are `m` elements `y` of `\Q/n\Z` with the property that `x = my`. We return the one with the smallest non-negative lift.
EXAMPLES::
sage: G = QQ/(4*ZZ) sage: x = G(3/8) sage: x / 4 3/32 """
r""" Display the element.
EXAMPLES::
sage: G = QQ/(8*ZZ) sage: g = G(25/7); g 25/7 """
r""" Hashing.
TESTS::
sage: G = QQ/(4*ZZ) sage: g = G(4/5) sage: hash(g) 2135587864 # 32-bit -7046029254386353128 # 64-bit sage: hash(G(3/4)) 527949074 # 32-bit 3938850096065010962 # 64-bit sage: hash(G(1)) 1 """
r""" Compare two elements.
EXAMPLES::
sage: G = QQ/(4*ZZ) sage: g = G(4/5) sage: h = G(6/7) sage: g == h False sage: g == g True """ else:
r""" Returns the order of this element in the abelian group `\Q/n\Z`.
EXAMPLES::
sage: G = QQ/(12*ZZ) sage: g = G(5/3) sage: g.additive_order() 36 sage: (-g).additive_order() 36 """ # a/b * k = n/m * r if self._x == 0: return ZZ(1) return infinity |