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: $$bash pip install negative-binom $$

Usage

Import the function and use it as follows: $$python 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.4.tar.gz (3.2 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.4-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: negative_binom-0.1.4.tar.gz
  • Upload date:
  • Size: 3.2 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.4.tar.gz
Algorithm Hash digest
SHA256 732f31d27992d2b94bb1d503c584c2ece6a111ff98a6eff5ddfd3e3b627f6809
MD5 4bfb2c6332541ef0d6707d60162c7510
BLAKE2b-256 93834bf91302c92cf87571029ec409b9c5d94b5a65d019a860d37174ef7209df

See more details on using hashes here.

File details

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

File metadata

  • Download URL: negative_binom-0.1.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0dd0e82d344c13911b8e5c691f698118bece07aa5b504642eb617540d4e33b0a
MD5 d18121cc89a2b6003f303494be1834a6
BLAKE2b-256 7029259206a5235177c0ef7b1c21ae3f852410af33a3c814816a903e7d57889e

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