euler-0.1.0.0

Safe HaskellSafe
LanguageHaskell2010

Euler.Util.Arithmetic

Contents

Synopsis

Documentation

>>> import Test.QuickCheck

Functions

divides :: Integral a => a -> a -> Bool Source #

a `divides` b iff a is a divisor of b; in other words, b = 0 (mod a).

square :: Num a => a -> a Source #

square x = x^2

intSqrt :: Integral a => a -> Maybe a Source #

intSqrt x is the integer r such that r^2 = x, if such an integer exists.

\(NonNegative n) -> intSqrt (n^2) === Just n
\(Positive n) -> intSqrt(n^2 + 1) === Nothing
\(Positive n) -> intSqrt((n+1)^2 - 1) === Nothing

floorSqrt :: Integral a => a -> a Source #

floorSqrt x is the largest integer r such that r^2 <= x.

\(NonNegative n) -> floorSqrt (n^2) === n
\(Positive n) -> floorSqrt(n^2 + 1) === n
\(Positive n) -> floorSqrt((n+1)^2 - 1) === n

isSquare :: Integral a => a -> Bool Source #

isSquare x iff x is a square.

\(NonNegative n) -> isSquare (square n)
\(Positive n) -> not (isSquare $ (square n) + 1)

Factorial

Functions

factorial :: Integral a => a -> Integer Source #

factorial n (often written as n!) is the product of the integers from 1 to n, inclusive.

factorials :: [Integer] Source #

All of the factorials, ascending. Equivalent to map factorial [0..].

>>> take 10 factorials
[1,1,2,6,24,120,720,5040,40320,362880]

Properties

Constants

million :: Integral a => a Source #

One million = 1,000,000.