Package sage :: Package rings :: Module integer
[hide private]
[frames] | no frames]

Module integer



File: sage/rings/integer.pyx (starting at line 1)

Elements of the ring $\Z$ of integers

AUTHORS:
    -- William Stein (2005): initial version
    
    -- Gonzalo Tornaria (2006-03-02): vastly improved python/GMP
                                   conversion; hashing
    -- Didier Deshommes <dfdeshom@gmail.com> (2006-03-06): numerous
                                   examples and docstrings
    -- William Stein (2006-03-31): changes to reflect GMP bug fixes
    -- William Stein (2006-04-14): added GMP factorial method (since it's
                                   now very fast).
    -- David Harvey (2006-09-15): added nth_root, exact_log
    -- David Harvey (2006-09-16): attempt to optimise Integer constructor
    -- Rishikesh (2007-02-25): changed quo_rem so that the rem is positive
    -- David Harvey, Martin Albrecht, Robert Bradshaw (2007-03-01):
                                   optimized Integer constructor and
                                   pool
    -- Pablo De Napoli (2007-04-01): multiplicative_order should
                                   return +infinity for non zero
                                   numbers
    -- Robert Bradshaw (2007-04-12): is_perfect_power, Jacobi symbol
                                   (with Kronecker extension). Convert
                                   some methods to use GMP directly
                                   rather than pari, Integer() ->
                                   PY_NEW(Integer)
    -- David Roe (2007-03-21): sped up valuation and is_square, added
                                   val_unit, is_power, is_power_of and
                                   divide_knowing_divisible_by
    -- Robert Bradshaw (2008-03-26): gamma function, multifactorials

EXAMPLES:
   Add 2 integers:
       sage: a = Integer(3) ; b = Integer(4)
       sage: a + b == 7
       True

   Add an integer and a real number:
       sage: a + 4.0
       7.00000000000000

   Add an integer and a rational number:
       sage: a + Rational(2)/5
       17/5

   Add an integer and a complex number:
       sage: b = ComplexField().0 + 1.5
       sage: loads((a+b).dumps()) == a+b
       True

   sage: z = 32
   sage: -z
   -32
   sage: z = 0; -z
   0
   sage: z = -0; -z
   0
   sage: z = -1; -z
   1

Multiplication:
    sage: a = Integer(3) ; b = Integer(4)
    sage: a * b == 12
    True
    sage: loads((a * 4.0).dumps()) == a*b
    True
    sage: a * Rational(2)/5
    6/5

    sage: list([2,3]) * 4
    [2, 3, 2, 3, 2, 3, 2, 3]

    sage: 'sage'*Integer(3)
    'sagesagesage'

COERCIONS:
    Returns version of this integer in the multi-precision floating
    real field R.

    sage: n = 9390823
    sage: RR = RealField(200)
    sage: RR(n)
    9.3908230000000000000000000000000000000000000000000000000000e6



Classes [hide private]
  Integer
File: sage/rings/integer.pyx (starting at line 253) The \class{Integer} class represents arbitrary precision integers.
  IntegerWrapper
File: sage/rings/integer.pyx (starting at line 248) Python classes have problems inheriting from Integer directly, but they don't have issues with inheriting from IntegerWrapper.
  int_to_Z
  long_to_Z
File: sage/rings/integer.pyx (starting at line 3645)...
Functions [hide private]
 
GCD_list(...)
File: sage/rings/integer.pyx (starting at line 3545) Return the GCD of a list v of integers.
 
LCM_list(...)
File: sage/rings/integer.pyx (starting at line 3483) Return the LCM of a list v of integers.
 
clear_mpz_globals(...)
File: sage/rings/../ext/gmp.pxi (starting at line 32)
 
free_integer_pool(...)
File: sage/rings/integer.pyx (starting at line 3917)
 
gmp_randrange(...)
File: sage/rings/../ext/gmp.pxi (starting at line 232)
 
init_mpz_globals(...)
File: sage/rings/../ext/gmp.pxi (starting at line 29)
 
is_Integer(...)
File: sage/rings/integer.pyx (starting at line 230) Return true if x is of the SAGE integer type.
 
make_integer(...)
File: sage/rings/integer.pyx (starting at line 3611) Create a SAGE integer from the base-32 Python *string* s.
 
parent(...)
File: sage/rings/../structure/coerce.pxi (starting at line 45)
Variables [hide private]
  MAX_UNSIGNED_LONG = 18446744073709551614
  ONE = 1
  arith = ['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3....
  doc = '\nIntegers\n'
  initialized = True
  mpz_t_offset_python = 32
  the_integer_ring = ['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37'...
Function Details [hide private]

GCD_list(...)

 
File: sage/rings/integer.pyx (starting at line 3545)

Return the GCD of a list v of integers.  Element of v is
converted to a SAGE integer if it isn't one already.

This function is used, e.g., by rings/arith.py

INPUT:
    v -- list or tuple

OUTPUT:
    integer

EXAMPLES:
    sage: from sage.rings.integer import GCD_list
    sage: w = GCD_list([3,9,30]); w
    3
    sage: type(w)
    <type 'sage.rings.integer.Integer'>

The inputs are converted to SAGE integers. 
    sage: w = GCD_list([int(3), int(9), '30']); w
    3
    sage: type(w)
    <type 'sage.rings.integer.Integer'>

LCM_list(...)

 
File: sage/rings/integer.pyx (starting at line 3483)

Return the LCM of a list v of integers.  Element of v is
converted to a SAGE integer if it isn't one already.

This function is used, e.g., by rings/arith.py

INPUT:
    v -- list or tuple

OUTPUT:
    integer

EXAMPLES:
    sage: from sage.rings.integer import LCM_list
    sage: w = LCM_list([3,9,30]); w
    90
    sage: type(w)
    <type 'sage.rings.integer.Integer'>

The inputs are converted to SAGE integers. 
    sage: w = LCM_list([int(3), int(9), '30']); w
    90
    sage: type(w)
    <type 'sage.rings.integer.Integer'>

is_Integer(...)

 
File: sage/rings/integer.pyx (starting at line 230)

Return true if x is of the SAGE integer type.

EXAMPLES:
    sage: is_Integer(2)
    True
    sage: is_Integer(2/1)
    False
    sage: is_Integer(int(2))
    False
    sage: is_Integer(long(2))
    False
    sage: is_Integer('5')
    False

make_integer(...)

 
File: sage/rings/integer.pyx (starting at line 3611)

Create a SAGE integer from the base-32 Python *string* s.
This is used in unpickling integers.

EXAMPLES:
    sage: from sage.rings.integer import make_integer
    sage: make_integer('-29')
    -73
    sage: make_integer(29)
    Traceback (most recent call last):
    ...
    TypeError: expected string or Unicode object, sage.rings.integer.Integer found


Variables Details [hide private]

arith

Value:
['4ti2-20061025',
 'R-2.6.0',
 'atlas-3.7.37',
 'atlas-3.8.1',
 'atlas-3.8.1.p1',
 'atlas-3.8.1.p3',
 'atlas-3.8.p11',
 'atlas-3.8.p6',
...

the_integer_ring

Value:
['4ti2-20061025',
 'R-2.6.0',
 'atlas-3.7.37',
 'atlas-3.8.1',
 'atlas-3.8.1.p1',
 'atlas-3.8.1.p3',
 'atlas-3.8.p11',
 'atlas-3.8.p6',
...