FastMath.Combinatorics

FastMath.Combinatorics provides fast and efficient combinatorics functions for Elixir, including implementations for:

The library is optimized for performance, using iterative methods, symmetry, and other techniques to minimize unnecessary computations.

Features

Installation

Add fastmath_combinatorics to your list of dependencies in mix.exs:

def deps do
  [
    {:fastmath_combinatorics, "~> 0.1.0"}
  ]
end

Then run:

mix deps.get

Documentation

Documentation can be generated using ExDoc and is available at HexDocs.

To generate the docs locally, run:

mix docs

Once published, the documentation will be available at HexDocs.

Examples

Factorial

Calculate the factorial of a number:

iex> FastMath.Combinatorics.factorial(5)
120

Permutations

Calculate the number of permutations ( P(n, r) ):

iex> FastMath.Combinatorics.permutations(5, 3)
60

Combinations

Calculate the number of combinations ( C(n, r) ):

iex> FastMath.Combinatorics.combinations(5, 3)
10

Variations

Calculate the number of variations ( V(n, r) ):

iex> FastMath.Combinatorics.variations(2, 3)
8

Generate Combinations

Generate all ( r )-element combinations from a list:

iex> FastMath.Combinatorics.generate_combinations([1, 2, 3, 4], 3)
[[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]

Contributing

Contributions are welcome! If you have ideas for improvements or additional functionality, feel free to submit a pull request or open an issue.

License

This project is licensed under the MIT License.