[
    {
        "name": "Arithmetic",
        "comment": " A library that provides useful number-theoretical functions for dealing\nwith integers, primes, divisibility, et cetera.\n\n# Primes\n@docs isPrime, primesBelow, primeFactors, primeExponents\n\n# Parity\n@docs isEven, isOdd\n\n# Divisors\n@docs divides, isMultipleOf, divisors, properDivisors, divisorCount\n\n# GCD and LCM\n@docs gcd, lcm, isCoprimeTo, totient, extendedGcd\n\n# Base conversion\n@docs toBase, fromBase\n\n# Squares\n@docs squareRoot, safeSquareRoot, intSquareRoot, exactIntSquareRoot, isSquare\n\n# Cubes\n@docs cubeRoot, intCubeRoot, exactIntCubeRoot, isCube\n\n# Modular arithmetic\n@docs powerMod, modularInverse, chineseRemainder\n\n",
        "unions": [],
        "aliases": [],
        "values": [
            {
                "name": "chineseRemainder",
                "comment": " Given a list of residue-modulus pairs `[(r1, m1), (r2, m2), ...]`, solve\nthe system of linear congruences:\n\n    x = r1 (mod m1)\n    x = r2 (mod m2)\n    ...\n\nLet `M` be the product of all moduli in the list. The [Chinese remainder\ntheorem](https://en.wikipedia.org/wiki/Chinese_remainder_theorem) tells us that\n\n* if all of the moduli are pairwise coprime (their `gcd` is 1), there are\n  infinitely many solutions, all congruent `mod M`;\n* if there is a pair of non-coprime moduli in the list, there is no solution.\n\nThe result is a solution `Just x` with `0 <= x < M` in the first case; or\n`Nothing` if the system is unsolvable.\n\n    chineseRemainder [(10, 11), (4, 12), (12, 13)] == Just 1000\n        -- Solution to x = 10 (mod 11), x = 4 (mod 12), x = 12 (mod 13).\n\n    chineseRemainder [(2, 3), (4, 6)] == Nothing\n        -- 3 and 6 are not coprime, so there is no solution.\n\n    chineseRemainder [] == Just 0\n        -- The trivial solution, modulo M = 1.\n",
                "type": "List ( Int, Int ) -> Maybe Int"
            },
            {
                "name": "cubeRoot",
                "comment": " Take the cube root of a number.\n\n    cubeRoot 15.625 == 2.5\n",
                "type": "Float -> Float"
            },
            {
                "name": "divides",
                "comment": " Test whether one number divides another.\n\n    10 `divides` 120 == True\n    10 `divides` 125 == False\n",
                "type": "Int -> Int -> Bool"
            },
            {
                "name": "divisorCount",
                "comment": " Get the number of divisors of a number (counting itself).\n",
                "type": "Int -> Int"
            },
            {
                "name": "divisors",
                "comment": " Get all divisors of a number, in ascending order.\n\n    divisors 20 == [1, 2, 4, 5, 10, 20]\n",
                "type": "Int -> List Int"
            },
            {
                "name": "exactIntCubeRoot",
                "comment": " Return `Just s` if the given integer is a cube, and `s` is its cube root;\notherwise, return `Nothing`.\n\n    exactIntCubeRoot 800 == Nothing\n    exactIntCubeRoot 1000 == Just 10\n",
                "type": "Int -> Maybe Int"
            },
            {
                "name": "exactIntSquareRoot",
                "comment": " Return `Just s` if the given integer is a square, and `s` is its square\nroot; otherwise, return `Nothing`.\n\n    exactIntSquareRoot 20 == Nothing\n    exactIntSquareRoot 25 == Just 5\n",
                "type": "Int -> Maybe Int"
            },
            {
                "name": "extendedGcd",
                "comment": " Given `a` and `b`, compute integers `(d, u, v)` so that `a * u + b * v ==\nd` where `d == gcd a b`. (These are known as [Bézout coefficients](\nhttps://en.wikipedia.org/wiki/B%C3%A9zout%27s_identity). If the inputs are both\npositive, the solution returned satisfies `abs u < b // gcd a b` and\n`abs v < a // gcd a b`.)\n\n    extendedGcd 1215 465 == (15, -13, 34)\n        -- because gcd 1215 465 == 15 == -13 * 1215 + 34 * 465\n",
                "type": "Int -> Int -> ( Int, Int, Int )"
            },
            {
                "name": "fromBase",
                "comment": " Interpret a list of digits as a number in the given base. The input is \nexpected to consist of integers `d` for which `0 <= d < base`.\n\n    fromBase 2 [1, 0, 1, 0, 1, 0] = 42\n",
                "type": "Int -> List Int -> Int"
            },
            {
                "name": "gcd",
                "comment": " Calculate the greatest common divisor of two integers. `gcd x 0` and\n`gcd 0 x` both return `x`. Negative arguments are made positive first.\n\n    gcd 56 80 == 8\n",
                "type": "Int -> Int -> Int"
            },
            {
                "name": "intCubeRoot",
                "comment": " Integer cube root, rounding down.\n\n    intCubeRoot 800 == 9\n    intCubeRoot 1000 == 10\n",
                "type": "Int -> Int"
            },
            {
                "name": "intSquareRoot",
                "comment": " Take the square root, rounding down. Return `NaN` (not a number) for\nnegative arguments.\n\n    intSquareRoot 20 == 4\n    intSquareRoot 25 == 5\n",
                "type": "Int -> Int"
            },
            {
                "name": "isCoprimeTo",
                "comment": " Test whether two integers are coprime.\n\n    56 `isCoprimeTo` 80 == False\n    5 `isCoprimeTo` 8 \n",
                "type": "Int -> Int -> Bool"
            },
            {
                "name": "isCube",
                "comment": " Test whether a number is a cube.\n\n    isCube 800 == False\n    isCube 1000 == True\n",
                "type": "Int -> Bool"
            },
            {
                "name": "isEven",
                "comment": " Test whether an integer is even.\n\n    isEven 2 == True\n    isEven 3 == False\n",
                "type": "Int -> Bool"
            },
            {
                "name": "isMultipleOf",
                "comment": " Test whether one number is a multiple of another.\n\n    120 `isMultipleOf` 10 == True\n    125 `isMultipleOf` 10 == False\n",
                "type": "Int -> Int -> Bool"
            },
            {
                "name": "isOdd",
                "comment": " Test whether an integer is odd.\n\n    isOdd 2 == False\n    isOdd 3 == True\n",
                "type": "Int -> Bool"
            },
            {
                "name": "isPrime",
                "comment": " Test whether an integer is a positive prime.\n\n    isPrime 2357 == True\n    isPrime 500 == False\n",
                "type": "Int -> Bool"
            },
            {
                "name": "isSquare",
                "comment": " Test whether a number is a square.\n\n    isSquare 20 == False\n    isSquare 25 == True\n",
                "type": "Int -> Bool"
            },
            {
                "name": "lcm",
                "comment": " Calculate the least common multiple of two integers. `lcm x 0` and\n`lcm 0 x` both return `0`. Negative arguments are made positive first.\n\n    lcm 56 80 == 560\n",
                "type": "Int -> Int -> Int"
            },
            {
                "name": "modularInverse",
                "comment": " Given a number `a` and a modulus `n`, return the multiplicative inverse of\n`a` modulo `n`, if it exists. That is: try to return `Just b`, with\n`0 <= b < n`, so that `a * b == 1` modulo `n`, but return `Nothing` if no such\n`b` exists. (`b` exists precisely when `a` and the modulus `n` are coprime.)\n\n    modularInverse 3 11 == Just 4    -- 3 * 4 == 12 == 1 (mod 11)\n    modularInverse 3 15 == Nothing   -- 3 and 15 aren't coprime\n",
                "type": "Int -> Int -> Maybe Int"
            },
            {
                "name": "powerMod",
                "comment": " `powerMod b e m` efficiently calculates `b ^ e` (modulo `m`). It assumes\n`b >= 0`, `e >= 0` and `m >= 1`.\n\nFor example, to compute `4147 ^ 8671 % 1000` efficiently:\n\n    powerMod 4147 8671 1000 == 803\n",
                "type": "Int -> Int -> Int -> Int"
            },
            {
                "name": "primeExponents",
                "comment": " Return a list of all prime-exponent pairs for a given positive integer's\nprime decomposition, with the primes in ascending order. If the input is less\nthan 2, the empty list is returned.\n\n    primeExponents 24 == [(2, 3), (5, 2)]                -- 2^3 * 5^2\n    primeExponents 531764 == [(2, 1), (11, 2), (13, 3)]  -- 2^1 * 11^2 * 13^3\n    primeExponents 1 == []                               -- empty product\n",
                "type": "Int -> List ( Int, Int )"
            },
            {
                "name": "primeFactors",
                "comment": " Return a list of all prime factors for a given positive integer, in\nascending order. If the input is less than 2, the empty list is returned.\n\n    primeFactors 24 == [2, 2, 2, 3]\n    primeFactors 767 == [13, 59]\n    primeFactors 1 == []\n",
                "type": "Int -> List Int"
            },
            {
                "name": "primesBelow",
                "comment": " Get all primes in the given range `[0..n-1]`, using the Sieve of\nEratosthenes.\n\n    primesBelow 4 == [2, 3]\n    primesBelow 17 == [2, 3, 5, 7, 11, 13]\n",
                "type": "Int -> List Int"
            },
            {
                "name": "properDivisors",
                "comment": " Get all proper divisors (i.e., divisors less than the input) of a number,\nin ascending order.\n\n    properDivisors 20 == [1, 2, 4, 5, 10]\n",
                "type": "Int -> List Int"
            },
            {
                "name": "safeSquareRoot",
                "comment": " Safely take the square root of a number: return `Just (squareRoot n)` if\nthe input `n` is nonnegative; otherwise, return `Nothing`.\n\n    squareRoot 5.76 == Just 2.4\n    squareRoot (-1) == Nothing\n",
                "type": "Float -> Maybe Float"
            },
            {
                "name": "squareRoot",
                "comment": " Take the square root of a number. Return `NaN` (not a number) for negative\narguments.\n\n    squareRoot 5.76 == 2.4\n    squareRoot (-1) |> isNaN\n",
                "type": "Float -> Float"
            },
            {
                "name": "toBase",
                "comment": " Convert a number to a list of digits in the given base. The input number is\nmade positive first.\n\n    toBase 2 42 = [1, 0, 1, 0, 1, 0]  -- 42 in binary\n",
                "type": "Int -> Int -> List Int"
            },
            {
                "name": "totient",
                "comment": " Compute Euler's totient function `φ(n)`: the number of positive integers\n`1 <= k <= n` for which `gcd(n, k) == 1`. The input is made positive first.\n\n    totient 99 == 60\n    totient 1450 == 560\n",
                "type": "Int -> Int"
            }
        ],
        "binops": []
    }
]