#10963: More functorial constructions
-------------------------------------+-------------------------------------
Reporter: nthiery | Owner: stumpc5
Type: enhancement | Status: needs_work
Priority: major | Milestone: sage-5.13
Component: categories | Resolution:
Keywords: days54 | Merged in:
Authors: Nicolas M. Thiéry | Reviewers: Simon King, Frédéric
Report Upstream: N/A | Chapoton
Branch: | Work issues:
public/ticket/10963 | Commit:
Dependencies: #11224, #8327, | 80d55fe6f2c1ed2496a02cab4ae0db4cb31a7b06
#10193, #12895, #14516, #14722, | Stopgaps:
#13589, #14471, #15069, #15094, |
#11688, #13394 |
-------------------------------------+-------------------------------------
Comment (by darij):
I don't understand git...
So I've typed
{{{
git diff -c 362fd5e4..80d55fe | gedit
}}}
to check my merge again. It gives a lot of changes (of course -- update
from beta2 to beta4), including this:
{{{
diff --git a/src/sage/categories/category.py
b/src/sage/categories/category.py
index 69373b7..732c233 100644
--- a/src/sage/categories/category.py
+++ b/src/sage/categories/category.py
@@ -108,6 +108,60 @@ from sage.structure.sage_object import SageObject
from sage.structure.unique_representation import UniqueRepresentation
from sage.structure.dynamic_class import DynamicMetaclass, dynamic_class
+import sage.misc.weak_dict
+from sage.misc.weak_dict import WeakValueDictionary
+_join_cache = WeakValueDictionary()
+
+def _join(categories, as_list):
+ """
+ This is an auxiliary function for :meth:`Category.join`
+
+ INPUT:
+
+ - ``categories``: A tuple (no list) of categories.
+ - ``as_list`` (boolean): Whether or not the result should be
represented as a list.
+
+ EXAMPLES::
+
+ sage: Category.join((Groups(), CommutativeAdditiveMonoids())) #
indirect doctest
+ Join of Category of groups and Category of commutative additive
monoids
+ sage: Category.join((Modules(ZZ), FiniteFields()), as_list=True)
+ [Category of finite fields, Category of modules over Integer
Ring]
+
+ """
+ # Since Objects() is the top category, it is the neutral element of
join
+ if len(categories) == 0:
+ from objects import Objects
+ return Objects()
+
+ if not as_list:
+ try:
+ return _join_cache[categories]
+ except KeyError:
+ pass
+
+ # Ensure associativity by flattening JoinCategory's
+ # Invariant: the super categories of a JoinCategory are not
JoinCategories themselves
+ categories = sum( (tuple(category._super_categories) if
isinstance(category, JoinCategory) else (category,)
+ for category in categories), ())
+
+ # canonicalize, by removing redundant categories which are super
+ # categories of others, and by sorting
+ result = ()
+ for category in categories:
+ if any(cat.is_subcategory(category) for cat in result):
+ continue
+ result = tuple( cat for cat in result if not
category.is_subcategory(cat) ) + (category,)
+ result = tuple(sorted(result, key = category_sort_key, reverse=True))
+ if as_list:
+ return list(result)
+ if len(result) == 1:
+ out = _join_cache[categories] = result[0]
+ else:
+ out = _join_cache[categories] = JoinCategory(result)
+ return out
+
+
class Category(UniqueRepresentation, SageObject):
r"""
The base class for modeling mathematical categories, like for
example:
}}}
Why is `def _join` marked as newly added? It did not enter Sage between
beta2 and beta4. Instead, git blame shows most of it is from 2011:
{{{
darij@travis-virtualbox:~/gitsage/sage-5.13.beta1$ git blame
src/sage/categories/category.py
[...]
fa807558 (Simon King 2013-11-02 22:51:17 +0100 110) import
sage.misc.weak_dict
fa807558 (Simon King 2013-11-02 22:51:17 +0100 111) from
sage.misc.weak_dict import WeakValueDiction
f89e19cf (Simon King 2011-12-25 00:48:56 +0100 112) _join_cache =
WeakValueDictionary()
f89e19cf (Simon King 2011-12-25 00:48:56 +0100 113)
a3c5958b (Simon King 2011-10-06 14:17:11 +0200 114) def
_join(categories, as_list):
a3c5958b (Simon King 2011-10-06 14:17:11 +0200 115) """
a3c5958b (Simon King 2011-10-06 14:17:11 +0200 116) This is an
auxiliary function for :meth:`Cat
a3c5958b (Simon King 2011-10-06 14:17:11 +0200 117)
a3c5958b (Simon King 2011-10-06 14:17:11 +0200 118) INPUT:
a3c5958b (Simon King 2011-10-06 14:17:11 +0200 119)
a3c5958b (Simon King 2011-10-06 14:17:11 +0200 120) -
``categories``: A tuple (no list) of categ
a3c5958b (Simon King 2011-10-06 14:17:11 +0200 121) -
``as_list`` (boolean): Whether or not the
a3c5958b (Simon King 2011-10-06 14:17:11 +0200 122)
a3c5958b (Simon King 2011-10-06 14:17:11 +0200 123) EXAMPLES::
a3c5958b (Simon King 2011-10-06 14:17:11 +0200 124)
a3c5958b (Simon King 2011-10-06 14:17:11 +0200 125) sage:
Category.join((Groups(), Commutati
a3c5958b (Simon King 2011-10-06 14:17:11 +0200 126) Join
of Category of groups and Category
a3c5958b (Simon King 2011-10-06 14:17:11 +0200 127) sage:
Category.join((Modules(ZZ), Finite
71230653 (Nicolas M. Thiery 2013-05-31 13:11:13 -0400 128)
[Category of finite fields, Category of
a3c5958b (Simon King 2011-10-06 14:17:11 +0200 129)
a3c5958b (Simon King 2011-10-06 14:17:11 +0200 130) """
a3c5958b (Simon King 2011-10-06 14:17:11 +0200 131) # Since
Objects() is the top category, it is
a3c5958b (Simon King 2011-10-06 14:17:11 +0200 132) if
len(categories) == 0:
a3c5958b (Simon King 2011-10-06 14:17:11 +0200 133) from
objects import Objects
a3c5958b (Simon King 2011-10-06 14:17:11 +0200 134) return
Objects()
a3c5958b (Simon King 2011-10-06 14:17:11 +0200 135)
f89e19cf (Simon King 2011-12-25 00:48:56 +0100 136) if not
as_list:
f89e19cf (Simon King 2011-12-25 00:48:56 +0100 137) try:
f89e19cf (Simon King 2011-12-25 00:48:56 +0100 138)
return _join_cache[categories]
f89e19cf (Simon King 2011-12-25 00:48:56 +0100 139) except
KeyError:
[...]
}}}
--
Ticket URL: <http://trac.sagemath.org/ticket/10963#comment:175>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/groups/opt_out.