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

sage.combinat.permutation.from_cycles produces wrong result when 'cycles' is a generator #34662

Closed
maxale opened this issue Oct 15, 2022 · 13 comments

Comments

@maxale
Copy link
Contributor

maxale commented Oct 15, 2022

We have

sage: cycles = [[1,2,3],[4,5,6]]
sage: sage.combinat.permutation.from_cycles(6,cycles)
[2, 3, 1, 5, 6, 4]
sage: sage.combinat.permutation.from_cycles(6,(c for c in cycles))
[1, 2, 3, 4, 5, 6]

where the former result is correct and the latter is wrong.

Component: combinatorics

Author: Dave Morris

Branch/Commit: af2f762

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/34662

@maxale maxale added this to the sage-9.8 milestone Oct 15, 2022
@DaveWitteMorris
Copy link
Member

Branch: public/34662

@DaveWitteMorris
Copy link
Member

Author: Dave Morris

@DaveWitteMorris
Copy link
Member

comment:3

Thanks for pointing out this bug. I rewrote the code to only access the input once, so it works with generators. The new code also verifies the input without sorting a list (which takes more than linear time).


New commits:

e5e8cd5trac 34662: create permutation from a generator

@DaveWitteMorris
Copy link
Member

Commit: e5e8cd5

@DaveWitteMorris
Copy link
Member

Changed stopgaps from todo to none

@tscrim
Copy link
Collaborator

tscrim commented Oct 24, 2022

comment:4

The test of int(x) doesn't quite do what it is claiming to do:

sage: int(1.5)
1

It would be better to just explicit convert the inputs to ZZ, which can just fail.

Likewise, do p[i] = ZZ(i+1).

Please factor out the len(cycle) calls as a variable in the loop as an optimization.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 26, 2022

Branch pushed to git repo; I updated commit sha1. New commits:

af2f762improvements suggested by reviewer

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 26, 2022

Changed commit from e5e8cd5 to af2f762

@DaveWitteMorris
Copy link
Member

comment:6

Thanks for your comments. I think I made the changes that you suggested.

@tscrim
Copy link
Collaborator

tscrim commented Oct 28, 2022

Reviewer: Travis Scrimshaw

@tscrim
Copy link
Collaborator

tscrim commented Oct 28, 2022

comment:7

Thanks. LGTM.

@DaveWitteMorris
Copy link
Member

comment:8

Thanks!

@vbraun
Copy link
Member

vbraun commented Nov 7, 2022

Changed branch from public/34662 to af2f762

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants