From 7569a9509a9dbdb3a6dbc603f8bc53d65e2e0480 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 18 Aug 2022 22:14:03 -0700 Subject: [PATCH] src/sage/categories/finitely_enumerated_families.py: New --- .../finitely_enumerated_families.py | 53 +++++++++++++++++++ src/sage/sets/family.py | 28 +++++----- 2 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 src/sage/categories/finitely_enumerated_families.py diff --git a/src/sage/categories/finitely_enumerated_families.py b/src/sage/categories/finitely_enumerated_families.py new file mode 100644 index 00000000000..08ca4cabcbc --- /dev/null +++ b/src/sage/categories/finitely_enumerated_families.py @@ -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()] diff --git a/src/sage/sets/family.py b/src/sage/sets/family.py index 62eaff7ea36..db9668a4308 100644 --- a/src/sage/sets/family.py +++ b/src/sage/sets/family.py @@ -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 """ #***************************************************************************** @@ -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 @@ -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()