Module integer

Module integer 

Source
Expand description

Integer numbers, subsets of $\Z$.

An integer (m/w) is a number that can be written without a fractional component.

§Integer subsets

Different integer implementations are classified mathematically by:

  • Whether they only have positive sign (PositiveInteger, NonNegativeInteger), only negative sign (NegativeInteger, NonPositiveInteger), or both (Integer, NonZeroInteger).
  • Whether they support 0 (Integer, NonNegativeInteger, NonPositiveInteger) or not (NonZeroInteger, PositiveInteger, NegativeInteger).

This makes for 6 different kinds of integers.

They all implement the Integer trait, and are all variants of the Integers family enum, which includes also the special Prime kind.

They are also classified computationally, by 6 choices on their bit-size representation: (8, 16, 32, 64, 128 or Big). Combined makes for 36 choices of integers. (Except Big is only implemented for Integer for now).

Note that numbers that can represent both positive an negative integers can represent half the max positive or negative value at the same bit-size than their only negative or positive counterparts. E.g.:

assert_eq![[-128, 127], [Integer8::MIN, Integer8::MAX]];
assert_eq![[-255, 255], [NonPositiveInteger8::MIN.into(), NonNegativeInteger8::MAX.into()]];

§Operations

Not all types have the same support for arithmetic operations, specially if we want the operation to return an integer of the same type.

We say that a group is closed over an operation when that operation will always return a number of the same type. the following table summarizes the closed operations for each kind of integer:

IntegerNonZeroNonNegativePositiveNonpositiveNegativePrime
sign+ -+ -++--+
zero000
addyesyesyesyesyes
subyes
mulyesyesyesyes
divyesyesyesyes
remyesyesyes
negyesyes

Modules§

n0z
Non-zero integer numbers (o), from the set $\Z \setminus 0$ (!= 0).
nnz
Non-negative integer numbers (m/o), from the set $\Z^*$ ($\N _0$) (>= 0).
npz
Non-positive integer numbers (m), from the set $\Z^- \cup {0}$ (<= 0).
nz
Negative integer numbers (m/o), from the set $\Z^-$ (< 0).
prime
Prime numbers (m/o/w), from the set $\Bbb{P}$.
pz
Positive integer numbers (m/o), from the set $\Z^+$ ($\N _1$) (> 0).
z
Integer numbers (m/o/w), from the set $\Z$.

Structs§

Integer8
An 8-bit integer number, from the set $\Z$, also known as Z8.
Integer16
A 16-bit integer number, from the set $\Z$, also known as Z16.
Integer32
A 32-bit integer number, from the set $\Z$, also known as Z32.
Integer64
A 64-bit integer number, from the set $\Z$, also known as Z64.
Integer128
A 128-bit integer number, from the set $\Z$, also known as Z128.
IntegerBigbig
A big integer number, from the set $\Z$, also known as ZBig.
NegativeInteger8
An 8-bit negative integer number, from the set $\Z^-$, also known as Nz8.
NegativeInteger16
A 16-bit negative integer number, from the set $\Z^-$, also known as Nz16.
NegativeInteger32
A 32-bit negative integer number, from the set $\Z^-$, also known as Nz32.
NegativeInteger64
A 64-bit negative integer number, from the set $\Z^-$, also known as Nz64.
NegativeInteger128
A 128-bit negative integer number, from the set $\Z^-$, also known as Nz128.
NonNegativeInteger8
An 8-bit non-negative integer number, from the set $\Z^*$ ($\N _0$), also known as Nnz8.
NonNegativeInteger16
A 16-bit non-negative integer number, from the set $\Z^*$ ($\N _0$), also known as Nnz16.
NonNegativeInteger32
A 32-bit non-negative integer number, from the set $\Z^*$ ($\N _0$), also known as Nnz32.
NonNegativeInteger64
A 64-bit non-negative integer number, from the set $\Z^*$ ($\N _0$), also known as Nnz64.
NonNegativeInteger128
A 128-bit non-negative integer number, from the set $\Z^*$ ($\N _0$), also known as Nnz128.
NonPositiveInteger8
An 8-bit non-positive integer number, from the set $\Z^- \cup {0}$, also known as Npz8.
NonPositiveInteger16
A 16-bit non-positive integer number, from the set $\Z^- \cup {0}$, also known as Npz16.
NonPositiveInteger32
A 32-bit non-positive integer number, from the set $\Z^- \cup {0}$, also known as Npz32.
NonPositiveInteger64
A 64-bit non-positive integer number, from the set $\Z^- \cup {0}$, also known as Npz64.
NonPositiveInteger128
A 128-bit non-positive integer number, from the set $\Z^- \cup {0}$, also known as Npz128.
NonZeroInteger8
A 8-bit non-zero integer number, from the set $\Z \setminus 0$, also known as N0z8.
NonZeroInteger16
A 16-bit non-zero integer number, from the set $\Z \setminus 0$, also known as N0z16.
NonZeroInteger32
A 32-bit non-zero integer number, from the set $\Z \setminus 0$, also known as N0z32.
NonZeroInteger64
A 64-bit non-zero integer number, from the set $\Z \setminus 0$, also known as N0z64.
NonZeroInteger128
A 128-bit non-zero integer number, from the set $\Z \setminus 0$, also known as N0z128.
PositiveInteger8
An 8-bit positive integer number, from the set $\Z^+$ ($\N _1$), also known as Pz8.
PositiveInteger16
A 16-bit positive integer number, from the set $\Z^+$ ($\N _1$), also known as Pz16.
PositiveInteger32
A 32-bit positive integer number, from the set $\Z^+$ ($\N _1$), also known as Pz32.
PositiveInteger64
A 64-bit positive integer number, from the set $\Z^+$ ($\N _1$), also known as Pz64.
PositiveInteger128
A 128-bit positive integer number, from the set $\Z^+$ ($\N _1$), also known as Pz128.
Prime8
An 8-bit prime number, from the set $\Bbb{P}$, also known as P8.
Prime16
A 16-bit prime number, from the set $\Bbb{P}$, also known as P16.
Prime32
A 32-bit prime number, from the set $\Bbb{P}$, also known as P32.
Prime64
A 64-bit prime number, from the set $\Bbb{P}$, also known as P64.
Prime128
A 128-bit prime number, from the set $\Bbb{P}$, also known as P128.

Enums§

AllIntegers
The family of all kinds of integers, also known as AllZ.
Integers
The family of integer numbers, also known as Z.
NegativeIntegers
The family of negative integers, also known as Nz.
NonNegativeIntegers
The family of non-negative integers, also known as Nnz.
NonPositiveIntegers
The family of non-positive integers, also known as Npz.
NonZeroIntegers
The family of non-zero integers, also known as N0z.
PositiveIntegers
The family of positive integers, also known as Pz.
Primes
The family of prime numbers, also known as P.

Constants§

LARGEST_PRIME_POW2_DOUBLINGS
The largest primes that fit in the bits of consecutive doublings of powers of two.
PRIMES_BELL
The first 7 Bell primes (w) (A051131).
PRIMES_U8
The list of the first 54 primes that fit in a u8.
PRIMES_U16
The list of the 6,542 primes that fit in a u16, minus the first 54.
TEN_PRIMES_LESS_POW2
The list of the 10 primes just less than each power of two between 8 and 400 bits.

Traits§

Integer
Common trait for all integers.
Prime
Common trait for all primes.

Functions§

bit_lenbig
Returns the minimum binary bits necessary to represent the given integer in the given base.
bit_len_next_powerbig
Returns the result of the bit_len function and the next power of 2.
is_prime
Checks whether a number is prime, using optimized trial division.
is_prime_brute
Checks whether a number is prime, using basic trial division.
is_prime_sievestd
Checks whether a number is prime using an optimized sieve.
largest_prime_pow2_doublingsbig
Returns a big integer containing the largest prime just less a power of two.
nth_prime
Finds the 0-indexed nth prime number using is_prime.
nth_prime_sievestd
Finds the 0-indexed nth prime number using is_prime_sieve with the provided upper_bound.
prime_number_theoremstd
The prime number theorem (m/w) formula.
prime_pi
Counts the number of primes upto and including n, using is_prime.
prime_pi_sievestd
Counts the number of primes upto and including n using is_prime_sieve.
ten_primes_less_pow2big
Returns a big integer containing one of the ten largest primes just less than a power of two, between 8 and 400 bits.

Type Aliases§

AllZ
Abbreviation of AllIntegers family.
Counting
Alias of PositiveIntegers family.
Counting8
Alias of PositiveInteger8.
Counting16
Alias of PositiveInteger16.
Counting32
Alias of PositiveInteger32.
Counting64
Alias of PositiveInteger64.
Counting128
Alias of PositiveInteger128.
N0z
Abbreviation of NonZeroIntegers family.
N0z8
Abbreviation of NonZeroInteger8.
N0z16
Abbreviation of NonZeroInteger16.
N0z32
Abbreviation of NonZeroInteger32.
N0z64
Abbreviation of NonZeroInteger64.
N0z128
Abbreviation of NonZeroInteger128.
Natural8
Alias of NonNegativeInteger8.
Natural16
Alias of NonNegativeInteger16.
Natural32
Alias of NonNegativeInteger32.
Natural64
Alias of NonNegativeInteger64.
Natural128
Alias of NonNegativeInteger128.
Naturals
Alias of NonNegativeIntegers family.
Nnz
Abbreviation of NonNegativeIntegers family.
Nnz8
Abbreviation of NonNegativeInteger8.
Nnz16
Abbreviation of NonNegativeInteger16.
Nnz32
Abbreviation of NonNegativeInteger32.
Nnz64
Abbreviation of NonNegativeInteger64.
Nnz128
Abbreviation of NonNegativeInteger128.
Npz
Abbreviation of NonPositiveIntegers family.
Npz8
Abbreviation of NonPositiveInteger8.
Npz16
Abbreviation of NonPositiveInteger16.
Npz32
Abbreviation of NonPositiveInteger32.
Npz64
Abbreviation of NonPositiveInteger64.
Npz128
Abbreviation of NonPositiveInteger128.
Nz
Abbreviation of NegativeIntegers family.
Nz8
Abbreviation of NegativeInteger8.
Nz16
Abbreviation of NegativeInteger16.
Nz32
Abbreviation of NegativeInteger32.
Nz64
Abbreviation of NegativeInteger64.
Nz128
Abbreviation of NegativeInteger128.
P
Abbreviation of Primes family.
P8
Abbreviation of Prime8.
P16
Abbreviation of Prime16.
P32
Abbreviation of Prime32.
P64
Abbreviation of Prime64.
P128
Abbreviation of Prime128.
Pz
Abbreviation of PositiveIntegers family.
Pz8
Abbreviation of PositiveInteger8.
Pz16
Abbreviation of PositiveInteger16.
Pz32
Abbreviation of PositiveInteger32.
Pz64
Abbreviation of PositiveInteger64.
Pz128
Abbreviation of PositiveInteger128.
Z
Abbreviation of Integers family.
Z8
Abbreviation of Integer8.
Z16
Abbreviation of Integer16.
Z32
Abbreviation of Integer32.
Z64
Abbreviation of Integer64.
Z128
Abbreviation of Integer128.
ZBigbig
Abbreviation of IntegerBig.