当前位置: 首页>>代码示例>>Python>>正文


Python ZZ.gcd方法代码示例

本文整理汇总了Python中sage.rings.all.ZZ.gcd方法的典型用法代码示例。如果您正苦于以下问题:Python ZZ.gcd方法的具体用法?Python ZZ.gcd怎么用?Python ZZ.gcd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sage.rings.all.ZZ的用法示例。


在下文中一共展示了ZZ.gcd方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Small_primes_of_degree_one_iter

# 需要导入模块: from sage.rings.all import ZZ [as 别名]
# 或者: from sage.rings.all.ZZ import gcd [as 别名]
class Small_primes_of_degree_one_iter():
    r"""
    Iterator that finds primes of a number field of absolute degree
    one and bounded small prime norm.

    INPUT:

    - ``field`` -- a ``NumberField``.

    - ``num_integer_primes`` (default: 10000) -- an integer.  We try to find
      primes of absolute norm no greater than the
      ``num_integer_primes``-th prime number. For example, if
      ``num_integer_primes`` is 2, the largest norm found will be 3, since
      the second prime is 3.

    - ``max_iterations`` (default: 100) -- an integer. We test
      ``max_iterations`` integers to find small primes before raising
      ``StopIteration``.

    AUTHOR:

    - Nick Alexander
    """
    def __init__(self, field, num_integer_primes=10000, max_iterations=100):
        r"""
        Construct a new iterator of small degree one primes.

        EXAMPLES::

            sage: x = QQ['x'].gen()
            sage: K.<a> = NumberField(x^2 - 3)
            sage: K.primes_of_degree_one_list(3) # random
            [Fractional ideal (2*a + 1), Fractional ideal (-a + 4), Fractional ideal (3*a + 2)]
        """
        self._field = field
        self._poly = self._field.absolute_field('b').defining_polynomial()
        self._poly = ZZ['x'](self._poly.denominator() * self._poly()) # make integer polynomial
        self._lc = self._poly.leading_coefficient()

        # this uses that [ O_K : Z[a] ]^2 = | disc(f(x)) / disc(O_K) |
        from sage.libs.pari.all import pari
        self._prod_of_small_primes = ZZ(pari('TEMPn = %s; TEMPps = primes(TEMPn); prod(X = 1, TEMPn, TEMPps[X])' % num_integer_primes))
        self._prod_of_small_primes //= self._prod_of_small_primes.gcd(self._poly.discriminant() * self._lc)

        self._integer_iter = iter(ZZ)
        self._queue = []
        self._max_iterations = max_iterations

    def __iter__(self):
        r"""
        Return self as an iterator.

        EXAMPLES::

            sage: x = QQ['x'].gen()
            sage: K.<a> = NumberField(x^2 - 3)
            sage: it = K.primes_of_degree_one_iter()
            sage: iter(it) == it # indirect doctest
            True
        """
        return self

    def _lengthen_queue(self):
        r"""
        Try to find more primes of absolute degree one of small prime
        norm.

        Checks \code{self._max_iterations} integers before failing.

        WARNING:

            Internal function.  Not for external use!

        EXAMPLES::

            sage: x = QQ['x'].gen()
            sage: K.<a> = NumberField(x^2 - 3)
            sage: Ps = K.primes_of_degree_one_list(20, max_iterations=3) # indirect doctest
            sage: len(Ps) == 20
            True
        """
        count = 0
        while count < self._max_iterations:
            n = next(self._integer_iter)
            g = self._prod_of_small_primes.gcd(self._poly(n))
            self._prod_of_small_primes //= g
            self._queue = self._queue + [ (p, n) for p in g.prime_divisors() ]
            count += 1
        self._queue.sort() # sorts in ascending order

    def __next__(self):
        r"""
        Return a prime of absolute degree one of small prime norm.

        Raises ``StopIteration`` if such a prime cannot be easily found.

        EXAMPLES::

            sage: x = QQ['x'].gen()
            sage: K.<a> = NumberField(x^2 - 3)
#.........这里部分代码省略.........
开发者ID:saraedum,项目名称:sage-renamed,代码行数:103,代码来源:small_primes_of_degree_one.py

示例2: enum_affine_rational_field

# 需要导入模块: from sage.rings.all import ZZ [as 别名]
# 或者: from sage.rings.all.ZZ import gcd [as 别名]
def enum_affine_rational_field(X,B):
    """
    Enumerates affine rational points on scheme ``X`` (defined over `\QQ`) up
    to bound ``B``.

    INPUT:

    - ``X`` -  a scheme or set of abstract rational points of a scheme;
    - ``B`` -  a positive integer bound.

    OUTPUT:

    - a list containing the affine points of ``X`` of height up to ``B``,
      sorted.

    EXAMPLES::

        sage: A.<x,y,z> = AffineSpace(3,QQ)
        sage: from sage.schemes.affine.affine_rational_point import enum_affine_rational_field
        sage: enum_affine_rational_field(A(QQ),1)
        [(-1, -1, -1), (-1, -1, 0), (-1, -1, 1), (-1, 0, -1), (-1, 0, 0), (-1, 0, 1),
        (-1, 1, -1), (-1, 1, 0), (-1, 1, 1), (0, -1, -1), (0, -1, 0), (0, -1, 1),
        (0, 0, -1), (0, 0, 0), (0, 0, 1), (0, 1, -1), (0, 1, 0), (0, 1, 1), (1, -1, -1),
        (1, -1, 0), (1, -1, 1), (1, 0, -1), (1, 0, 0), (1, 0, 1), (1, 1, -1), (1, 1, 0),
        (1, 1, 1)]

    ::

        sage: A.<w,x,y,z> = AffineSpace(4,QQ)
        sage: S = A.subscheme([x^2-y*z+3,w^3+z+y^2])
        sage: enum_affine_rational_field(S(QQ),2)
        []
        sage: enum_affine_rational_field(S(QQ),3)
        [(-2, 0, -3, -1)]

    ::

        sage: A.<x,y> = AffineSpace(2,QQ)
        sage: C = Curve(x^2+y-x)
        sage: enum_affine_rational_field(C,10)
        [(-2, -6), (-1, -2), (0, 0), (1, 0), (2, -2), (3, -6)]


    AUTHORS:

    - David R. Kohel <[email protected]>: original version.

    - Charlie Turner (06-2010): small adjustments.
    """
    if is_Scheme(X):
        X = X(X.base_ring())
    n = X.codomain().ambient_space().ngens()
    if X.value_ring() is ZZ:
        Q = [ 1 ]
    else: # rational field
        Q = range(1, B + 1)
    R = [ 0 ] + [ s*k for k in range(1, B+1) for s in [1, -1] ]
    pts = []
    P = [0] * n
    m = ZZ(0)
    try:
        pts.append(X(P))
    except TypeError:
        pass
    iters = [ iter(R) for _ in range(n) ]
    for it in iters:
        it.next()
    i = 0
    while i < n:
        try:
            a = ZZ(iters[i].next())
        except StopIteration:
            iters[i] = iter(R) # reset
            P[i] = iters[i].next() # reset P[i] to 0 and increment
            i += 1
            continue
        m = m.gcd(a)
        P[i] = a
        for b in Q:
            if m.gcd(b) == 1:
                try:
                    pts.append(X([ num/b for num in P ]))
                except TypeError:
                    pass
        i = 0
        m = ZZ(0)
    pts.sort()
    return pts
开发者ID:Etn40ff,项目名称:sage,代码行数:90,代码来源:affine_rational_point.py


注:本文中的sage.rings.all.ZZ.gcd方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。