Skip to content

simplify some nested for loops #40439

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

fchapoton
Copy link
Contributor

either using walrus or simpler syntax

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.

@@ -955,7 +955,9 @@ def maximal_order(self, take_shortcuts=True, order_basis=None):
Order of Quaternion Algebra (-22, 210) with base ring Rational Field
with basis (1, i, 1/2*i + 1/2*j, 1/2 + 17/22*i + 1/44*k)

sage: for d in ( m for m in range(1, 750) if is_squarefree(m) ): # long time (3s)
sage: for d in range(1, 700): # long time (3s)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make the test timing comparable with past versions I would keep the 750, but that's really only a personal opinion, feel free to ignore!

Suggested change
sage: for d in range(1, 700): # long time (3s)
sage: for d in range(1, 750): # long time (3s)

@mantepse
Copy link
Contributor

nice!

@fchapoton
Copy link
Contributor Author

I would myself use rather 600 than 750. So I put 700 as a middle step. In principle, tests are not supposed to be long and complicated.

@mantepse
Copy link
Contributor

I would myself use rather 600 than 750. So I put 700 as a middle step. In principle, tests are not supposed to be long and complicated.

So, then use a number such that it is no longer a long test. In a fresh session,

sage: all(QuaternionAlgebra(d).maximal_order(take_shortcuts=False).is_maximal() for d in range(1, 350) if is_squarefree(d))

seems to be on the very safe side.

Besides, I think that would also be the better form of the example, more precisely

            sage: Q = QuaternionAlgebra
            sage: all(Q(d).maximal_order(take_shortcuts=False).is_maximal()
            ....:     for d in range(1, 350) if is_squarefree(d))

@fchapoton
Copy link
Contributor Author

d'accord ! Voilà

vbraun pushed a commit to vbraun/sage that referenced this pull request Jul 20, 2025
sagemathgh-40439: simplify some nested for loops
    
either using walrus or simpler syntax

### 📝 Checklist

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
    
URL: sagemath#40439
Reported by: Frédéric Chapoton
Reviewer(s): Martin Rubey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants