binomial_distribution overflows at 171 trials even when the result is representable
Maintainer antworten meist innerhalb von 2 Tagen
@landfvit arbeitet bereits daran.
Seit 28.10.2026.
Bewertung
- Schwierigkeit
- 1/5
- Geschätzter Aufwand
- Unter einer Stunde
- Anfängerfreundlichkeit
- 85/100
Rechercherichtung
Lies maths/binomial_distribution.py und führe die Reproduktion aus dem Issue aus: binomial_distribution(85, 171, 0.5) sollte 0.060749764626165485 entsprechen. Ersetze das auf float(factorial(trials)) basierende Zwischenergebnis durch eine Form mit math.comb(trials, successes), sodass die große Fakultät nie in einen float umgewandelt wird, und führe die Reproduktion erneut aus. Fertig bedeutet: kein OverflowError für diese Eingabe und die erwartete Wahrscheinlichkeit wird zurückgegeben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Repository commit
6e03a48579ca212a08b36be00378f887dc41a003
Python version (python --version)
Python 3.11.0, macOS
Dependencies version (pip freeze)
No third-party dependencies are needed for this reproduction; both the implementation and reference use the Python standard library.
Expected behavior
The probability mass function should return a finite probability for valid inputs such as 85 successes in 171 fair trials. The expected value for this case is approximately 0.060749764626165485.
Actual behavior
Run from the repository root:
from math import comb
from maths.binomial_distribution import binomial_distribution
k, n, p = 85, 171, 0.5
print('reference:', comb(n, k) * p**k * (1-p)**(n-k))
print('actual:', binomial_distribution(k, n, p))
Output:
reference: 0.060749764626165485
Traceback (most recent call last):
...
OverflowError: int too large to convert to float
In maths/binomial_distribution.py, float(factorial(trials)) overflows for trials >= 171, even though the final probability for this input is representable. Using math.comb(trials, successes) avoids converting the much larger intermediate factorial to a float. For substantially larger inputs, an implementation should also consider underflow when multiplying the probability terms; the reference expression above is intended only for the concrete reproduction.
Searched existing issues and pull requests for binomial_distribution and binomial overflow; I did not find an existing report of this failure.
- Vorherrschende Sprache
- Python
- Sterne
- 225k
- Forks
- 51.2k
- Ø Merge
- 1 T. 13 Std.
- Gemergte PRs (30 T.)
- 32
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus TheAlgorithms/Python
-
continued_fraction uses float division, producing invalid terms for large integers and raising OverflowErrorEvtl. vergeben @trleo hat das vor 1 Tag übernommen. Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
TheAlgorithms/Python#15655 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 2 Tagen
-
ciphers/base32.py and ciphers/base85.py encode Unicode code points instead of bytes: output diverges from the spec for non-ASCII, round-trips corrupt chars >= U+0400, arbitrary bytes crashEvtl. vergeben @Nate-br hat das vor 2 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
TheAlgorithms/Python#15636 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen
-
ciphers/des_ecb.py: encrypt/decrypt silently corrupts any character above U+00FF (round-trip fails)Evtl. vergeben @mohammedanasnakhuda hat das vor 3 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
TheAlgorithms/Python#15634 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
other/password.py: alternative_password_generator ignores the requested length when the required characters exceed itEvtl. vergeben @raaj-2222 hat das vor 3 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
TheAlgorithms/Python#15633 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen
-
ciphers/base58.py is a copy of base64_cipher.py — no Base58 implementation exists in the fileEvtl. vergeben @SakshiYeole hat das vor 4 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 45/100
TheAlgorithms/Python#15637 ·
Maintainer antworten meist innerhalb von 2 Tagen
Alle Issues in TheAlgorithms/Python
Ähnliche Issues
-
app: scripts status: backlog type: documentation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
netbox-community/netbox-scripts#68 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 91/100
marin-community/marin#10765 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 70/100
flathub/com.unity.UnityHub#230 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
namespace operations
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 63/100
EclipseFdn/open-vsx.org#14910 ·
Maintainer antworten meist innerhalb von 1 Tag