Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
src/sage/categories/finitely_enumerated_families.py: New
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Aug 19, 2022
1 parent 434932f commit 7569a95
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 12 deletions.
53 changes: 53 additions & 0 deletions src/sage/categories/finitely_enumerated_families.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
r"""
Finitely enumerated families
"""

#*****************************************************************************
# Copyright (C) 2022 Matthias Koeppe
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# https://www.gnu.org/licenses/
#*****************************************************************************

from sage.misc.abstract_method import abstract_method
from sage.misc.cachefunc import cached_method
from sage.categories.category_singleton import Category_singleton
from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
from sage.categories.enumerated_families import EnumeratedFamilies


class FinitelyEnumeratedFamilies(Category_singleton):
r"""
The category of finitely enumerated families
An *finitely enumerated family* is an enumerated family whose keys
form a finite enumerated set; this implies that the family is a finite set.
EXAMPLES::
sage: from sage.categories.enumerated_families import EnumeratedFamilies
sage: from sage.categories.finitely_enumerated_families import FinitelyEnumeratedFamilies
sage: FinitelyEnumeratedFamilies()
Category of finitely enumerated families
sage: FinitelyEnumeratedFamilies() == EnumeratedFamilies() & FiniteSets()
False
sage: F = Family(ZZ, lambda x: x % 7, is_injective=False, category=FiniteSets())
sage: F in EnumeratedFamilies() & FiniteSets()
True
sage: F in FinitelyEnumeratedFamilies()
False
"""

def super_categories(self):
r"""
EXAMPLES::
sage: from sage.categories.finitely_enumerated_families import FinitelyEnumeratedFamilies
sage: FinitelyEnumeratedFamilies().super_categories()
[Category of enumerated families, Category of finite enumerated sets]
"""
return [EnumeratedFamilies(), FiniteEnumeratedSets()]
28 changes: 16 additions & 12 deletions src/sage/sets/family.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
sage: P = Partitions(3)
sage: Family(P, lambda x: x).category()
Category of finite enumerated families
Category of finitely enumerated families
"""

#*****************************************************************************
Expand All @@ -46,6 +46,7 @@

from sage.categories.enumerated_families import EnumeratedFamilies
from sage.categories.enumerated_sets import EnumeratedSets
from sage.categories.finitely_enumerated_families import FinitelyEnumeratedFamilies
from sage.categories.families import Families
from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets
Expand Down Expand Up @@ -1118,25 +1119,28 @@ def __init__(self, set, function, name=None, category=None, is_injective=None, i
else:
is_injective = True

if category is None:
category = Families()
else:
category &= Families()

set_category = Sets()
if set in FiniteEnumeratedSets():
set_category = FiniteEnumeratedSets()
set_category &= FiniteEnumeratedSets()
category &= FinitelyEnumeratedFamilies()
elif set in InfiniteEnumeratedSets():
if is_injective:
set_category = InfiniteEnumeratedSets()
set_category &= InfiniteEnumeratedSets()
else:
set_category = EnumeratedSets()
set_category &= EnumeratedSets()
elif isinstance(set, (list, tuple, range, CombinatorialClass)):
set_category = FiniteEnumeratedSets()
set_category &= FiniteEnumeratedSets()
elif set in EnumeratedSets():
set_category = EnumeratedSets()
else:
set_category = Sets()
set_category &= EnumeratedSets()

if category is None:
category = Sets()
category = Families() & set_category & category
category &= set_category
if set_category.is_subcategory(EnumeratedSets()):
category = EnumeratedFamilies() & category
category &= EnumeratedFamilies()

try:
facade = function.codomain()
Expand Down

0 comments on commit 7569a95

Please sign in to comment.