fmpz – integers

class flint.fmpz(val=None)

The fmpz type represents an arbitrary-size integer.

>>> fmpz(3) ** 25
847288609443
bell_number(type cls, ulong n)

Returns the Bell number \(B_n\) as an fmpz.

>>> fmpz.bell_number(10)
115975
bin_uiui(type cls, ulong n, ulong k)

Returns the binomial coefficient \({n \choose k}\) as an fmpz.

bit_length(self)
divisor_sigma(n, k)

Returns the divisor sum \(\sigma_k(n)\) as an fmpz.

>>> fmpz(60).divisor_sigma(0)
12
>>> fmpz(60).divisor_sigma(1)
168
>>> fmpz(60).divisor_sigma(10)
605263138639095300
euler_number(type cls, ulong n)

Returns the Euler number \(E_n\) as an fmpz.

>>> fmpz.euler_number(10)
-50521
euler_phi(n)

Returns the Euler totient function \(\varphi(n)\) as an fmpz.

>>> fmpz(60).euler_phi()
16
>>> fmpz(3**10).euler_phi()
39366
fac_ui(type cls, ulong n)

Returns the factorial \(n!\) as an fmpz.

>>> fmpz.fac_ui(10)
3628800
factor(self)

Factors self into pseudoprimes, returning a list of (prime, exp) pairs. The sign is ignored.

>>> fmpz(5040).factor()
[(2, 4), (3, 2), (5, 1), (7, 1)]
>>> fmpz(10**35 + 1).factor()
[(11, 1), (9091, 1), (909091, 1), (4147571, 1), (265212793249617641, 1)]
>>> len(fmpz.fac_ui(1000).factor())
168

Warning: factoring large integers can be slow unless all prime factors are small.

fib_ui(type cls, ulong n)

Returns the Fibonacci number \(F_n\) as an fmpz.

>>> fmpz.fib_ui(10)
55
gcd(self, other)

Returns the greatest common divisor of self and other.

>>> fmpz(30).gcd(45)
15
moebius_mu(n)

Returns the Moebius function \(\mu(n)\) as an fmpz.

>>> [fmpz(n).moebius_mu() for n in range(10)]
[0, 1, -1, -1, 0, -1, 1, -1, 0, 0]
partitions_p(n)

Returns \(p(n)\), the number of partitions of \(n\), as an fmpz.

>>> [fmpz(n).partitions_p() for n in range(8)]
[1, 1, 2, 3, 5, 7, 11, 15]
>>> fmpz(100).partitions_p()
190569292
>>> len(str(fmpz(10**9).partitions_p()))
35219

The partition function grows rapidly. On a 32-bit system, \(n\) must not be larger than about \(10^{16}\). On a 64-bit system, \(n\) must not be larger than about \(10^{20}\). For large \(n\), this function benefits from setting ctx.threads = 2 on multicore systems.

primorial_ui(type cls, ulong n)

Returns the product of all primes less than or equal to n (n primorial) as an fmpz.

>>> fmpz.primorial_ui(10)
210
repr(self)
rising(s, ulong n)

Returns the rising factorial \(s (s+1) \cdots (s+n-1)\) as an fmpz.

>>> fmpz(10).rising(5)
240240
stirling_s1(type cls, ulong n, ulong k)

Returns the Stirling number of the first kind \(S_1(n,k)\) as an fmpz.

>>> fmpz.stirling_s1(10,5)
-269325
stirling_s2(type cls, ulong n, ulong k)

Returns the Stirling number of the second kind \(S_2(n,k)\) as an fmpz.

>>> fmpz.stirling_s2(10,5)
42525
str(self, int base=10, long condense=0)

Converts self to a string, optionally in a non-decimal base and optionally showing only leading and trailing digits.

>>> (fmpz(3) ** 100).str()
'515377520732011331036461129765621272702107522001'
>>> (fmpz(3) ** 100).str(base=3, condense=10)
'1000000000{...81 digits...}0000000000'