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

comparison of permutation and standard permutation #21069

Closed
dkrenn opened this issue Jul 21, 2016 · 28 comments
Closed

comparison of permutation and standard permutation #21069

dkrenn opened this issue Jul 21, 2016 · 28 comments

Comments

@dkrenn
Copy link
Contributor

dkrenn commented Jul 21, 2016

Because ClonableArray also takes the parent into consideration of equality checking, we currently have the following:

sage: Permutations([1])[0] == Permutation([1])
False

I propose to have Permutations(range(n)) be identical to Permutations(n).

CC: @sagetrac-sage-combinat @darijgr @nthiery @simon-king-jena

Component: coercion

Author: Travis Scrimshaw

Branch/Commit: dc5c35a

Reviewer: Darij Grinberg

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

@dkrenn dkrenn added this to the sage-7.3 milestone Jul 21, 2016
@tscrim
Copy link
Collaborator

tscrim commented Jul 21, 2016

comment:1

I think this is more an issue with the default _cmp_ in ClonableArray wanting to have a common parent, but there are not coercions between most combinatorial objects (nor should there be typically). IMO, this is even worse:

sage: Permutations([1])[0] == Permutation([1])
False

However, I don't agree with the argument that "same representation => equality". Should the partition [2, 1] equal the permutation [2, 1]? (Currently they do, but I think that is a small issue and you should not rely on this behavior.) We run into a major notation problem as there is not enough valid syntax and math notation to separate the two clearly; context (or their parents) separate them.

@dkrenn
Copy link
Contributor Author

dkrenn commented Aug 11, 2016

comment:2

Replying to @tscrim:

However, I don't agree with the argument that "same representation => equality". Should the partition [2, 1] equal the permutation [2, 1]? (Currently they do, but I think that is a small issue and you should not rely on this behavior.) We run into a major notation problem as there is not enough valid syntax and math notation to separate the two clearly; context (or their parents) separate them.

Ok, I agree.

@dkrenn dkrenn removed this from the sage-7.3 milestone Aug 11, 2016
@dkrenn
Copy link
Contributor Author

dkrenn commented Aug 11, 2016

comment:3

Set to invalid.

@tscrim
Copy link
Collaborator

tscrim commented Aug 11, 2016

comment:4

I am going to recycle this ticket to address the issue above.

@tscrim

This comment has been minimized.

@tscrim tscrim added this to the sage-7.4 milestone Aug 11, 2016
@tscrim tscrim changed the title comparison of permutation and list: unexpected result comparison of permutation and standard permutation Aug 11, 2016
@dkrenn
Copy link
Contributor Author

dkrenn commented Aug 11, 2016

comment:5

Replying to @tscrim:

I am going to recycle this ticket to address the issue above.

Ok.

@tscrim
Copy link
Collaborator

tscrim commented Aug 21, 2016

comment:6

While I was at it, I fixed the Permutations_nk.random_element, which was returning elements of [0, ..., n-1].


New commits:

0196365Making permutations [1,...,n] be standard.

@tscrim
Copy link
Collaborator

tscrim commented Aug 21, 2016

Author: Travis Scrimshaw

@tscrim
Copy link
Collaborator

tscrim commented Aug 21, 2016

@tscrim
Copy link
Collaborator

tscrim commented Aug 21, 2016

Commit: 0196365

@tscrim
Copy link
Collaborator

tscrim commented Aug 21, 2016

comment:7

I just realized the branch is named wrong...

@tscrim
Copy link
Collaborator

tscrim commented Aug 21, 2016

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 23, 2016

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

14b364eMerge branch 'public/combinat/permutations_std_set-21069' in 7.4.b1
7548e6etrac 21069 fixing a doctest in Dyck words

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 23, 2016

Changed commit from 0196365 to 7548e6e

@darijgr
Copy link
Contributor

darijgr commented Sep 3, 2016

comment:9
+                    if list(n) == range(1, len(n)+1):

Maybe you want sorted(n) rather than list(n) here?

@tscrim
Copy link
Collaborator

tscrim commented Sep 3, 2016

comment:10

No, I want list(n) because the identity permutations are different.

@darijgr
Copy link
Contributor

darijgr commented Sep 3, 2016

comment:11

Oh, the word "permutation" is meant in the non-algebraic meaning! Makes sense then. Will look at the rest of the code now.

@darijgr
Copy link
Contributor

darijgr commented Sep 3, 2016

comment:12

OK. Two issues:

  1. Instances of class Permutations_set have a _set attribute, whereas objects of class StandardPermutations_n don't. Could this break things?

  2. Is the time to call StandardPermutations_n higher than for Permutations_set? (I suspect it is, if only due to things like cat = FiniteWeylGroups().Irreducible() & FinitePermutationGroups().) Is this relevant?

@tscrim
Copy link
Collaborator

tscrim commented Sep 3, 2016

comment:13

Replying to @darijgr:

OK. Two issues:

  1. Instances of class Permutations_set have a _set attribute, whereas objects of class StandardPermutations_n don't. Could this break things?

No because nobody should be using _set (nor do we have to respect it) because it is hidden.

  1. Is the time to call StandardPermutations_n higher than for Permutations_set? (I suspect it is, if only due to things like cat = FiniteWeylGroups().Irreducible() & FinitePermutationGroups().) Is this relevant?

I don't understand what you're asking. If you're saying putting StandardPermutations_n as a superclass of Permutations_set, then we should not do that. It is too much of a can of worms and far outside the scope of this ticket.

@darijgr
Copy link
Contributor

darijgr commented Sep 3, 2016

comment:14
  1. OK.

  2. What I mean is that calling Permutations([1,2,3]) might now suddenly be taking a lot longer. I don't know whether this is an actual issue because (a) I haven't tested, and (b) it is a parent, and maybe calling many parents is not a standard use case we should be optimizing for anyway. But I'm asking to be sure.

@tscrim
Copy link
Collaborator

tscrim commented Sep 3, 2016

comment:15

Replying to @darijgr:

  1. What I mean is that calling Permutations([1,2,3]) might now suddenly be taking a lot longer. I don't know whether this is an actual issue because (a) I haven't tested, and (b) it is a parent, and maybe calling many parents is not a standard use case we should be optimizing for anyway. But I'm asking to be sure.

There are already such tests, so it really should not unless you're constantly doing things like [1,2,...,n,'a']. I also doubt it would be the bottleneck in a loop.

@darijgr
Copy link
Contributor

darijgr commented Sep 7, 2016

comment:16

OK, the slowdown is in the single-digit percentages (just checked). The code LGTM then. To be safe, what do the guardians of the object hierarchy think about it?

@fchapoton
Copy link
Contributor

comment:17

2 failing doctests, see bot

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 17, 2016

Changed commit from 7548e6e to dc5c35a

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 17, 2016

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

3cc7873Merge branch 'public/combinat/permutations_std_set-21069' of git://trac.sagemath.org/sage into public/combinat/permutations_std_set-21069
dc5c35aChange due to Python3 list.

@tscrim
Copy link
Collaborator

tscrim commented Oct 17, 2016

Reviewer: Darij Grinberg

@tscrim
Copy link
Collaborator

tscrim commented Oct 17, 2016

comment:19

Failure was due to me not using Python3-style list. Fixed and doctests now pass.

Since there were no comments from Darij's request in comment:16, I'm allowing myself to set this to a positive review.

@vbraun
Copy link
Member

vbraun commented Oct 21, 2016

Changed branch from public/combinat/permutations_std_set-21069 to dc5c35a

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

5 participants