<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> <!-- %% --> <!-- %A integers.xml GAP documentation Martin Schönert --> <!-- %A Alexander Hulpke --> <!-- %% --> <!-- %% --> <!-- %Y (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland --> <!-- %Y Copyright (C) 2002 The GAP Group --> <!-- %% -->
One of the most fundamental datatypes in every programming language is
the integer type. &GAP; is no exception.
<P/>
&GAP; integers are entered as a sequence of decimal digits optionally
preceded by a <Q><C>+</C></Q> sign for positive integers or
a <Q><C>-</C></Q> sign for negative integers.
The size of integers in &GAP; is only limited by the amount of available
memory, so you can compute with integers having thousands of digits.
<P/>
<Example><![CDATA[
gap> -1234;
-1234
gap> 123456789012345678901234567890123456789012345678901234567890;
123456789012345678901234567890123456789012345678901234567890
]]></Example>
Note that in a few places, only certain small integer values can be used. A
<E>small integer</E> (also referred to as <E>immediate integer</E>) is an
integer <M>n</M> satisfying <C>INTOBJ_MIN</C> <M> \leq n \leq </M>
<C>INTOBJ_MAX</C>, where <C>INTOBJ_MIN</C> and <C>INTOBJ_MAX</C> equal either
<M>-2^{28}</M> and <M>2^{28}-1</M> (on 32-bit systems) or <M>-2^{60}</M> and
<M>2^{60}-1</M> (on 64-bit systems).
<Index>small integer</Index>
<Index>immediate integer</Index>
<Index>INTOBJ_MIN</Index>
<Index>INTOBJ_MAX</Index>
For example, the elements of a range are restricted to small integers
(see <Ref Sect="Ranges"/>).
<P/>
Many more functions that are mainly related to the prime residue group of
integers modulo an integer are described in chapter <Ref Chap="Number Theory"/>,
and functions dealing with combinatorics can be found
in chapter <Ref Chap="Combinatorics"/>.
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="sect:Integers: Global Variables">
<Heading>Integers: Global Variables</Heading>
<Description>
<Ref Meth="Random" Label="for integers"/> for integers returns
pseudo random integers between <M>-10</M> and
<M>10</M> distributed according to a binomial distribution.
To generate uniformly distributed integers from a range,
use the construction <C>Random( [ <A>low</A> .. <A>high</A> ] )</C>
(see <Ref Oper="Random" Label="for lower and upper bound"/>).
</Description>
</ManSection>
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Quotients and Remainders">
<Heading>Quotients and Remainders</Heading>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Residue Class Rings">
<Heading>Residue Class Rings</Heading>
<Index Key="mod" Subkey="residue class rings"><K>mod</K></Index>
<Index Subkey="residue class rings">modulo</Index>
<Ref Func="ZmodnZ"/> returns a residue class ring of <Ref Var="Integers"/>
modulo an ideal.
These residue class rings are rings, thus all operations for rings
(see Chapter <Ref Chap="Rings"/>) apply.
See also Chapters <Ref Chap="Finite Fields"/> and
<Ref Chap="Number Theory"/>.
<ManSection>
<Oper Name="\mod" Arg="r/s, n" Label="for residue class rings"/>
<Description>
If <A>r</A>, <A>s</A> and <A>n</A> are integers, <C><A>r</A> / <A>s</A></C> as a reduced fraction is
<C>p/q</C>, where <C>q</C> and <A>n</A> are coprime, then <C><A>r</A> / <A>s</A> mod <A>n</A></C> is
defined to be the product of <C>p</C> and the inverse of <C>q</C> modulo <A>n</A>. See
Section <Ref Sect="Arithmetic Operators"/> for more details and definitions.
<P/>
With the above definition, <C>4 / 6 mod 32</C> equals <C>2 / 3 mod 32</C> and hence
exists (and is equal to 22), despite the fact that 6 has no inverse
modulo 32.
</Description>
</ManSection>
&GAP; provides <Ref Oper="Random" Label="for a list or collection"/> methods
for many collections of objects.
On a lower level these methods use <E>random sources</E> which provide
random integers and random choices from lists.
<P/>
See <Ref Filt="IsRandomSource"/> for the user interface for random sources,
and Section <Ref Subsect="Implementing new kinds of random sources"/>
for information about developing new kinds of random sources.
</Section> <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Bitfields">
<Heading>Bitfields</Heading>
Bitfields are a low-level feature intended to support efficient
subdivision of immediate integers into bitfields of various widths.
This is typically useful in implementing space-efficient and/or
cache-efficient data structures. This feature should be used with care
because (<E>inter alia</E>) it has different limitations on 32-bit and 64-bit
architectures.
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.