← 返回首页
GH-100425: Note improved commutativity in sum(). by rhettinger · Pull Request #107785 · python/cpython · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

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

Merged
rhettinger merged 1 commit into
python:mainfrom
rhettinger:sum_algo
Aug 8, 2023
Merged

GH-100425: Note improved commutativity in sum().#107785
rhettinger merged 1 commit into
python:mainfrom
rhettinger:sum_algo

Conversation

rhettinger commented Aug 8, 2023
edited by github-actions Bot
Loading

Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown
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 merged commit aab6f71 into python:main Aug 8, 2023

Copy link
Copy Markdown
Contributor

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

rhettinger deleted the sum_algo branch August 8, 2023 17:30

Copy link
Copy Markdown

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

bedevere-bot removed the needs backport to 3.12 only 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>
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
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

Footer

© 2026 GitHub, Inc.