#28274 closed defect (fixed)

EnumeratedFamily should use integers as keys

Reported by: gh-mwageringel Owned by:
Priority: minor Milestone: sage-8.9
Component: combinatorics Keywords:
Cc: tscrim, nthiery Merged in:
Authors: Markus Wageringel Reviewers: Travis Scrimshaw
Report Upstream: N/A Work issues:
Branch: 4ba13d8 (Commits) Commit: 4ba13d872900eba7e2f556afd77bfc0f94852521
Dependencies: Stopgaps:

Description (last modified by tscrim)

This ticket solves the following problems involing EnumeratedFamily:

  • The keys of an enumerated family should be integers. Currently, the elements of the family itself are returned.
    sage: f = Family(Permutations(4))
    sage: f.keys()
    Standard permutations of 4
    sage: list(f.keys()) == list(f)  # should not be True here
    True
    
    Because of this, looking up elements by key as in f[next(iter(f.keys()))] raises a type error. For example, this is used in DisjointUnionEnumeratedSets.
  • Finite enumerated families should be in the category of FiniteEnumeratedSets(), while currently it is only in EnumeratedSets():
    sage: Family(Permutations(4)) in FiniteEnumeratedSets()  # should be True
    False
    
  • Infinite enumerated families are currently indexed by NonNegativeIntegers() from sage.categories.example.infinite_enumerated_sets. This ticket replaces the usage of these example numbers by those in sage.sets.non_negative_integers. This also includes one instance in baxter_permutations.

Change History (7)

comment:1 Changed 13 months ago by gh-mwageringel

  • Authors set to Markus Wageringel
  • Branch set to u/gh-mwageringel/28274
  • Commit set to 4ba13d872900eba7e2f556afd77bfc0f94852521
  • Status changed from new to needs_review

Note that this ticket is independent from, but compatible with #28273.


New commits:

4ba13d828274: fix keys and category of EnumeratedFamily

comment:2 Changed 12 months ago by chapoton

  • Cc tscrim added

Travis, any opinion on this proposal ?

comment:3 follow-up: Changed 12 months ago by tscrim

  • Cc nthiery added
  • Reviewers set to Travis Scrimshaw

This is clearly a bug as it contradicts the documentation of EnumeratedFamily:

    :class:`EnumeratedFamily` turns an enumerated set ``c`` into a family
    indexed by the set `\{0,\dots, |c|-1\}`.

I don't understand this:

The category of finite enumerated families should be in FiniteEnumeratedSets(), while currently it is only in EnumeratedSets().

in both what is supposed to mean and what was changed.

comment:4 in reply to: ↑ 3 Changed 12 months ago by gh-mwageringel

Replying to tscrim:

I don't understand this:

The category of finite enumerated families should be in FiniteEnumeratedSets(), while currently it is only in EnumeratedSets().

in both what is supposed to mean and what was changed.

What I meant is that the category should be a subcategory of FiniteEnumeratedSets() so that the following can be used to check whether the family is finite.

sage: Family(Permutations(4)) in FiniteEnumeratedSets()  # should be True
False

The category is set based on whether the type of the keys is known to be finite, such as for lists and tuples. I added range to this detection, which is the type of keys of EnumeratedFamily. This bug was probably introduced when six.moves.range was imported into the module, as ordinarily in Python 2 range returns a list.

comment:5 Changed 12 months ago by tscrim

  • Description modified (diff)
  • Status changed from needs_review to positive_review

Okay, that helps quite a lot. Thanks.

comment:6 Changed 12 months ago by gh-mwageringel

Thank you.

comment:7 Changed 12 months ago by vbraun

  • Branch changed from u/gh-mwageringel/28274 to 4ba13d872900eba7e2f556afd77bfc0f94852521
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.