GH-100425: Note improved commutativity in sum(). by rhettinger · Pull Request #107785 · python/cpython (original) (raw)
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation3 Commits1 Checks0 Files changed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
Contributor
rhettinger commented
•
edited by github-actionsbot
Loading
Script to demonstrate the improvement:
from random import random
from itertools import permutations
n = 4
trials = 100
errors = 0
for i in range(trials):
example = [random() for i in range(n)]
if len(set(map(sum, permutations(example)))) != 1:
errors += 1
print(i, sorted(example))
print(f'{errors / trials * 100.0=}%')
Formerly there was a 63% error rate. Now it is zero.
Thanks @rhettinger for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request
(cherry picked from commit aab6f71)
Co-authored-by: Raymond Hettinger rhettinger@users.noreply.github.com