1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<!-- %% -->
<!-- %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 -->
<!-- %% -->
<Chapter Label="Integers">
<Heading>Integers</Heading>
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>
<#Include Label="IntegersGlobalVars">
<#Include Label="IsIntegers">
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Elementary Operations for Integers">
<Heading>Elementary Operations for Integers</Heading>
<#Include Label="IsInt">
<#Include Label="IsPosInt">
<#Include Label="Int">
<#Include Label="IsEvenInt">
<#Include Label="IsOddInt">
<#Include Label="AbsInt">
<#Include Label="SignInt">
<#Include Label="LogInt">
<#Include Label="RootInt">
<#Include Label="SmallestRootInt">
<#Include Label="IsSquareInt">
<#Include Label="ListOfDigits">
<ManSection>
<Meth Name="Random" Arg='Integers' Label="for integers"/>
<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>
<#Include Label="QuoInt">
<#Include Label="BestQuoInt">
<#Include Label="RemInt">
<#Include Label="GcdInt">
<#Include Label="Gcdex">
<#Include Label="LcmInt">
<#Include Label="CoefficientsQadic">
<#Include Label="CoefficientsMultiadic">
<#Include Label="ChineseRem">
<#Include Label="PowerModInt">
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Prime Integers and Factorization">
<Heading>Prime Integers and Factorization</Heading>
<#Include Label="Primes">
<#Include Label="IsPrimeInt">
<#Include Label="PrimalityProof">
<#Include Label="IsPrimePowerInt">
<#Include Label="NextPrimeInt">
<#Include Label="PrevPrimeInt">
<#Include Label="FactorsInt">
<#Include Label="PrimeDivisors">
<#Include Label="PartialFactorization">
<#Include Label="PrintFactorsInt">
<#Include Label="PrimePowersInt">
<#Include Label="DivisorsInt">
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<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>
<#Include Label="ZmodnZ">
<#Include Label="ZmodnZObj">
<#Include Label="IsZmodnZObj">
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Check Digits">
<Heading>Check Digits</Heading>
<#Include Label="CheckDigitISBN">
<#Include Label="CheckDigitTestFunction">
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Random Sources">
<Heading>Random Sources</Heading>
&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.
<#Include Label="IsRandomSource">
<#Include Label="Random">
<#Include Label="State">
<#Include Label="IsGlobalRandomSource">
<#Include Label="RandomSource">
<#Include Label="RandomSource_develop">
</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.
<#Include Label="MakeBitfields">
<#Include Label="BuildBitfields">
</Section>
</Chapter>
|