num
The Disco standard number theory library can be imported with
import num
It provides the following functions:
isPrime : N -> Booltests whether a given natural number is prime. It would be possible to implement this function in Disco, but this built-in version is much more efficient. For example it works on 15-digit numbers almost instantly.log(b,n)calculates the logarithm basebofn, rounded down to the nearest natural number.For convenience,
lgis defined as the base-2 logarithm specifically.lg(n) + 1is the number of bits needed to representnin binary.factortakes a natural number and returns a bag of its prime factors. LikeisPrime, this function could in theory be written in Disco itself, but the provided built-in version is extremely efficient.evenandoddtest whether a given integer is even or odd, respectively.