Skip to content
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 and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-100425: Note improved commutativity in sum(). #107785

Merged
merged 1 commit into from
Aug 8, 2023

Conversation

rhettinger
Copy link
Contributor

@rhettinger rhettinger commented Aug 8, 2023

@rhettinger
Copy link
Contributor Author

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.

@rhettinger rhettinger merged commit aab6f71 into python:main Aug 8, 2023
20 checks passed
@miss-islington
Copy link
Contributor

Thanks @rhettinger for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-107787 is a backport of this pull request to the 3.12 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.12 bug and security fixes label Aug 8, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 8, 2023
(cherry picked from commit aab6f71)

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants