mpz_t
integer type.
) |
You can create an integer from an int, long, string literal, or integer modulo N.
sage: Integer(495) 495 sage: Integer('495949209809328523') 495949209809328523 sage: Integer(Mod(3,7)) 3
Integers also support the standard arithmetic operations, such as +,-,*,/, codeabs, codemod, codefloat
binary,
copy,
crt,
denominator,
divides,
factor,
gcd,
inverse_mod,
is_one,
is_prime,
is_square,
is_square_free,
is_unit,
is_zero,
isqrt,
lcm,
numerator,
parent,
powermod,
powermodm_ui,
quo_rem,
set_si,
set_str,
sqrt,
str,
xgcd
Further documentation:
) |
Return the binary digits of self as a string.
sage: Integer(15).binary() '1111' sage: Integer(16).binary() '10000' sage: Integer(16938402384092843092843098243).binary() '11011010111011000111100011100100101001110100011010100011111110001010000000 00101111000010000011'
) |
Return a copy of the integer.
) |
Return the unique integer between 0
and
that is
congruent to the integer modulo
and to
modulo
. We
assume that
and
are coprime.
) |
Return the denominator of the integer.
) |
Return True if self divides n.
sage: Z = IntegerRing() sage: Z(5).divides(Z(10)) True sage: Z(0).divides(Z(5)) False sage: Z(10).divides(Z(5)) False
) |
Return the prime factorization of the integer as a list of
pairs
, where
is prime and
is a positive integer.
) |
Return the greatest common divisor of self and
.
) |
Returns the inverse of self modulo
, if this inverse exists.
Otherwise, raises a exceptionZeroDivisionError exception.
INPUT: self -- Integer n -- Integer OUTPUT: x -- Integer such that x*self = 1 (mod m), or raises ZeroDivisionError. IMPLEMENTATION: Call the mpz_invert GMP library function.
sage: a = Integer(189) sage: a.inverse_mod(10000) 4709 sage: a.inverse_mod(-10000) 4709 sage: a.inverse_mod(1890) Traceback (most recent call last): ... ZeroDivisionError: Inverse does not exist. sage: a = Integer(19)**100000 sage: b = a*a sage: c=a.inverse_mod(b) Traceback (most recent call last): ... ZeroDivisionError: Inverse does not exist.
) |
Returns True
if the integers is
, otherwise
False
.
) |
Returns True if this integer is not divisible by the square of any prime and False otherwise.
) |
Returns true
if this integer is a unit, i.e., 1 or
.
) |
Returns True
if the integers is 0
, otherwise False
.
) |
Returns the integer floor of the square root of self, or raises an ValueError if self is negative.
sage: a = Integer(5) sage: a.isqrt() 2
) |
Returns the least common multiple of self and
.
) |
Return the numerator of this integer.
) |
Return the ring
of integers.
) |
powermod(self, Integer exp, Integer mod): Compute self**exp modulo mod.
) |
Coerces
to a C signed integer if possible, and sets self
equal to
.
) |
Set self equal to the number defined by the string s in the given base.
) |
Returns the square root of self as a real number to the given number of bits of precision if self is nonnegative, and raises a ValueError exception otherwise.
sage: Z = IntegerRing() sage: Z(2).sqrt() 1.4142135623730951 sage: Z(2).sqrt(100) 1.4142135623730950488016887242092
) |
Return the string representation of self
in the given
base.
n.str(b)
.
) |
Return a triple
such that
Instances of class Integer also have the following special methods:
__abs__,
__add,
__add__,
__and__,
__cmp__,
__div,
__div__,
__eq__,
__float__,
__floordiv,
__floordiv__,
__ge__,
__gt__,
__hex__,
__int__,
__invert__,
__le__,
__long__,
__lshift__,
__lt__,
__mod__,
__mul,
__mul__,
__ne__,
__neg__,
__or__,
__pos__,
__pow__,
__radd__,
__rand__,
__rdiv__,
__reduce__,
__repr__,
__rfloordiv__,
__rlshift__,
__rmod__,
__rmul__,
__ror__,
__rpow__,
__rrshift__,
__rshift__,
__rsub__,
__str_malloc,
__sub,
__sub__,
_and,
_mpfr_,
_or,
_pari_
Further documentation:
) |
Return the string representation of self
in the given
base. (Uses malloc then PyMem. This is actually slightly
faster than self.str() below, but it is unpythonic to use
malloc.) However, self.str() below is nice because we know
the size of the string ahead of time, and can work around a
bug in GMP nicely. There seems to be a bug in GMP, where
non-2-power base conversion for very large integers > 10
million digits (?) crashes GMP.
See About this document... for information on suggesting changes.