Skip to main content

A binomial function that extends the domain of combinations to include negative integers.

Project description

Negative Binom

A binomial function that extends the domain of combinations to include negative integers.

Installation

You can install the package using:

pip install negative-binom

Usage

Import the function and use it as follows:

from negative_binom import binom

# Standard case:
print(binom(5, 2)) # Output: 10

# Extended cases:
print(binom(-5, 2)) # Output: 15
print(binom(5, -2)) # Output: 0
print(binom(-5, -2)) # Output: 0

Mathematical Explanation

The binomial coefficient is traditionally defined as:

\binom{m}{n} = \frac{m!}{n!(m-n)!}, \quad \text{for }m \geq n \geq 0

The binom function extends the definition to handle negative values of m and n using "The Pascal Hexagon" provided by Hilton and Pedersen in Extending the Binomial Coefficients to Preserve Symmetry and Pattern:

Pascal's Hexagon

The hexagon is broken into different parts depending on if they contain zeros or non-zeros. Formulas below then can be used to determine the values of the binomial coefficients:

  1. Standard case $(m \geq 0)$
  • If $m \geq n \geq 0$:
\binom{m}{n}=\frac{m!}{n!(m-n)!}
  • Otherwise:
\binom{m}{n}=0
  1. Extended case $(0 > m)$
  • If $n \geq 0$:
\binom{m}{n}=(-1)^n \binom{-m+n-1}{n}
  • If $m \geq n$:
\binom{m}{n}=(-1)^{m+n} \binom{-n-1}{-m-1}
  • Otherwise:
\binom{m}{n}=0

This extended definition of binomial coefficients makes it possible to work with negative values of $m$ and $n$.

Personal Notes

I made this package because I needed a binomial function that included negative arguments as well. math.comb results in error and scipy.stats.binom sets the result to 0 for negative arguments, so they didn't work for me. Hope this helps anyone else.

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

negative_binom-0.1.1.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

negative_binom-0.1.1-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file negative_binom-0.1.1.tar.gz.

File metadata

  • Download URL: negative_binom-0.1.1.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for negative_binom-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f5a89d61406bdfc7f3deb060ee6ced5c3796ce8be6c76c1bc6559e448d0e7ffa
MD5 e967be9fd145ac7f93ccf74311149af8
BLAKE2b-256 b13fa516d8449066535efd30b9940cb412f995010e5764fa60ae80b654abbc7d

See more details on using hashes here.

File details

Details for the file negative_binom-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: negative_binom-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for negative_binom-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1dcf181c3a51722165a8859a1aad60c03eb30d8b8e3048ff6f7c744a1dd79aef
MD5 e7b62c16154318ce21f85cc31226bd4c
BLAKE2b-256 24ceb6828d38249da678bd968901b1682ee9a018de26b6a4b8f6218e9b761cce

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page