ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 23 Dec 2022 04:35:09 +0100Constructing Objects in a Categoryhttps://ask.sagemath.org/question/65465/constructing-objects-in-a-category/Suppose I want to define a Hopf algebra H (or group, ring, etc.) and I want it to be an object of the category HopfAlgebras(QQ).
Programming aside, the information need to define a Hopf algebra is the underlying algebra, the comultiplication, antipode, and counit. If H is finitely generated, then I can define the algebra as the quotient of a free algebra, this I know how to do in sage. I can also define the comultiplication, antipode, and counit as ring homorphisms.
How do I use all of this data to make H into an instance of HopfAlgebras(QQ)?NoGoodMathematicianFri, 23 Dec 2022 04:35:09 +0100https://ask.sagemath.org/question/65465/Possible bug - specifying category messes up coercion?https://ask.sagemath.org/question/60903/possible-bug-specifying-category-messes-up-coercion/The snippet
D = CombinatorialFreeModule(ZZ, [1,2])
D(0)
works fine, however
C = CombinatorialFreeModule(ZZ, [1,2], category=AlgebrasWithBasis(ZZ))
C(0)
gets into an infinite loop:
File "/opt/sagemath-9.0/local/lib/python3.7/site-packages/sage/categories/magmas.py", line 488, in one
return self(1)
File "sage/structure/parent.pyx", line 900, in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9218)
return mor._call_(x)
File "sage/categories/map.pyx", line 1694, in sage.categories.map.FormalCompositeMap._call_ (build/cythonized/sage/categories/map.c:11607)
x = f._call_(x)
File "sage/categories/morphism.pyx", line 549, in sage.categories.morphism.SetMorphism._call_ (build/cythonized/sage/categories/morphism.c:8489)
cpdef Element _call_(self, x):
File "sage/categories/morphism.pyx", line 568, in sage.categories.morphism.SetMorphism._call_ (build/cythonized/sage/categories/morphism.c:8439)
return self._function(x)
File "/opt/sagemath-9.0/local/lib/python3.7/site-packages/sage/categories/unital_algebras.py", line 70, in from_base_ring
return self.one()._lmul_(r)
File "sage/misc/cachefunc.pyx", line 2310, in sage.misc.cachefunc.CachedMethodCallerNoArgs.__call__ (build/cythonized/sage/misc/cachefunc.c:12712)
self.cache = f(self._instance)
Why is this? Is this expected behaviour?makosWed, 02 Feb 2022 15:18:43 +0100https://ask.sagemath.org/question/60903/Implementing Subgroupshttps://ask.sagemath.org/question/59688/implementing-subgroups/I created my own implementation of a specific group, inheriting from Group, following the pattern in the tutorial here:
https://doc.sagemath.org/html/en/thematic_tutorials/coercion_and_categories.html
I can construct elements, multiply them and find inverses.
My group is infinite, but I know that any finitely generated subgroup is finite. I'd like to have something where I can do:
sage: G = myGroup()
sage: g_1,g_2,g3 = some elements of G
sage: G2 = G.subgroup([g1,g2])
sage: g3 in G2
True/False
sage: G2.order()
35
sage: G2.list_elements()
...
My question is, do I have to implement this all "from scratch", or can sage already do most if this if I've implemented the multiplication? How do I make it work with the category framework, so G1 is a group, and has a cannonical conversion to G? (if that is the right thing to want.)
paragonThu, 11 Nov 2021 17:15:36 +0100https://ask.sagemath.org/question/59688/Finite categories?https://ask.sagemath.org/question/58033/finite-categories/Hi,
As part of a project on geometry of moduli of curves ('stacky fans') I'm trying to implement `categories with finitely many objects and finitely many morphisms'. I've started creating a class FiniteCat, but I can't decide whether it should be a child of DiGraph (where I add extra data of composition) , or of Category, using the existing machinery around that.
For context, I'm going to start with creating a FiniteCat from a lattice/poset (with maybe a couple of hundred vertices), then adding in a few more interesting (auto)morphisms). The main purpose is that I want to look at (pre)sheaves on these categories, check whether certain collections of data define sections of these presheaves, and perform basic operations on them.
Any suggestions would be very welcome .
Thanks,
David HolmesDavid HolmesFri, 16 Jul 2021 13:07:46 +0200https://ask.sagemath.org/question/58033/Hochschild cohomology of a matrix subalgebrahttps://ask.sagemath.org/question/51290/hochschild-cohomology-of-a-matrix-subalgebra/ Let $M_n(R)$ be the $n\times n$ matrix algebra over the polynomial ring $R=K[t]$. It is spanned by $\{e_{ij}; i,j\in[n]\}$.
> Let $A$ be a subalgebra of $M_n(R)$,
> spanned by $\{p_{ij}e_{ij}\}$, where
> $(i,j)$ ranges over some subset of
> $[n]\times[n]$ and $p_{ij}\in R$ are
> some polynomials. How can I compute
> with SageMath the hochschild
> (co)homology $HH^\ast(A;A)$?
So far, I know how to do some basics:
R.<t>=GF(3)[];
A.<x,y> = ExteriorAlgebra(QQ);
C = A.hochschild_complex(A); print(type(A),'\n',type(C))
show(C.homology(0),', ',C.homology(1),', ',C.homology(2))
show(C.cohomology(0),', ',C.cohomology(1),', ',C.cohomology(2))
However, I don't know how to create my matrix subalgebra $A$ over $R$. Also, I don't think this really computes hochschild cohomology. Is it dualised over $\mathbb{Q}$ or over $A=\Lambda_\mathbb{Q}[x,y]$?LeonWed, 06 May 2020 01:15:20 +0200https://ask.sagemath.org/question/51290/implement algebras with some extra structurehttps://ask.sagemath.org/question/47753/implement-algebras-with-some-extra-structure/I seem not to be understanding the way to implement categories with extra structure. Suppose I want to implement the category `Cs` of pairs `(A,S)` where `A` is a `QQ`-algebra and `S` is a linear endomorphism of `A` with the obvious morphisms. `Algebras(QQ)` is a full subcategory of `Cs` by adding the zero endormophism. And we also have the forgetful functor from `Cs` to `Algebras(QQ)` which consists to simply forget `S`.
Now from reading the examples in
https://doc.sagemath.org/html/en/reference/categories/index.html
or
https://doc.sagemath.org/html/en/thematic_tutorials/coercion_and_categories.html
I could set up
<pre><code>class Cs(Category)
def super_categories(self):
return[Algebras(QQ)]
</code></pre>
And that woul d give me a canonical forgetful functor `Cs` -> `Algebras(QQ)`. Now my problem is when I want to create a parent of `Cs()` starting from a parent in `Algebras(QQ)`. That is, I could set up a new parent and elements which will have to implement the methods for `Algebras(QQ)`:
<pre><code>sage: from sage.misc.abstract_method import abstract_methods_of_class
sage: abstract_methods_of_class(Algebras(QQ).parent_class)
{'optional': ['algebra_generators'], 'required': ['__contains__']}
sage: abstract_methods_of_class(Algebras(QQ).element_class)
{'optional': ['_add_', '_mul_'], 'required': ['__nonzero__']}
</code></pre>
But instead of implementing those methods I would want to use the methods of the underlying parent of `Algebras(QQ)`. Something like a hypothetical `PolynomialRing(QQ, 'x', category=Cs())`. In other words I'm looking to implement the functor `A -> (A, 0)` above.
Finally I have similar concerns about implementing `Cs()` in the other two possible ways, namely as the subcategory of the category of arrows in `VectorSpaces(QQ)` with the same source and target an object from `Algebras(QQ)`, or as a super category of `Algebras(QQ)` using `_subcategory_hook_`. Always I get to the point where I don't know how to implement something like `PolynomialRing(QQ, category=Cs())`. What I am doing now is keeping a copy of the algebra `A` inside of an instance of `Cs.parent_class` and then implementing the element and parent mehods of `Algebras(QQ)` by pointing to the corresponding methods of `A` but that seems silly. I'd appreciate any pointer.heluaniTue, 03 Sep 2019 21:05:43 +0200https://ask.sagemath.org/question/47753/is an object of a subcategory an object of the ambient category?https://ask.sagemath.org/question/47724/is-an-object-of-a-subcategory-an-object-of-the-ambient-category/I have defined a category `Cs()` and its subcategory `Ds()` as follows:
<pre><code>
class Cs(Category_over_base_ring):
...
def __init__(self, K):
Category_over_base_ring.__init__(self, K)
def super_categories(self):
return [ GradedAlgebras(self.base_field()) ]
class Ds(CategoryWithAxiom):
_base_category_class_and_axiom = (Cs, 'Commutative')
Cs.Commutative = Ds
</code></pre>
The omitted code I think its irrelevant. I can check that `Ds()` is a subcategory of `Cs()`:
<pre><code>
sage: C = Cs(QQ)
sage: D = Ds(QQ)
sage: D.is_subcategory(C)
True
sage:
</code></pre>
Now I create a parent of `Ds()` as follows:
<pre><code>
class DParent (Parent,UniqueRepresentation):
def __init__(self,K, *args, **kwds ):
if not (K in Fields() or \
(isinstance(K, Category) and K.is_subcategory(Fields()))):
raise ValueError(
"base must be a field or a subcategory of Fields(); got {}".format(K))
self._base_algebra = PolynomialRing(K,*args,**kwds)
super(DParent,self).__init__(self,
category=Ds(K))
...
</code></pre>
And I can check that these parents are objects of `Ds()` but not of `Cs()`:
<pre><code>
sage: J = DParent(QQ, 1, 'x', order=TermOrder('wdeglex', (2,)))
sage: J in C
False
sage: J in D
True
</code></pre>
Where can I be making a mistake?
**Addition:** I am looking at the implementation in sage/categories/category.py and I am more puzzled:
<pre><code>sage: J.category().is_subcategory(C)
True
sage: C.__contains__(J)
False
</code></pre>
But at least I get
<pre><code>
sage: c = J.categories()
sage: any(isinstance(cat,C.subcategory_class) for cat in c)
True
sage: C.__classcontains__(C.subcategory_class,J)
True
sage:
</code></pre>heluaniMon, 02 Sep 2019 18:22:25 +0200https://ask.sagemath.org/question/47724/Power series with coeffs in SymmetricFunctions()https://ask.sagemath.org/question/37460/power-series-with-coeffs-in-symmetricfunctions/The following gives an error:
sym = SymmetricFunctions(QQ)
R.<t> = PowerSeriesRing(sym)
saying that base_ring is not a commutative ring. I can check sym.categories(), and indeed it is not, but I think it should be. Is there an easy way to make this work?
Thanks!paragonFri, 28 Apr 2017 22:42:00 +0200https://ask.sagemath.org/question/37460/RingMorphism defined by a python functionhttps://ask.sagemath.org/question/10795/ringmorphism-defined-by-a-python-function/Is there a way to define a `RingHomomorphism` object that calls a user defined function? I know this is possible for `SetMorphism`, but I can't find a way to do the same for rings.
My use case: I have a python (or cython) function defining an embedding of a (finite) field into another. Of course, I could evaluate it on the generators of the domain and create a `RingHomomorphism_im_gens` object, but my function is much faster to evaluate.
LucaMon, 02 Dec 2013 18:00:15 +0100https://ask.sagemath.org/question/10795/Partial Algebrashttps://ask.sagemath.org/question/8022/partial-algebras/Hi!
As part of a future package for matroid theory, I would like to implement an algebraic structure called a "partial field".
A partial field is a tuple P = (S, 0, 1, +, *) such that
1. S - {0} is a group G under * with identity 1
2. Every element p has an additive inverse q such that p + q = 0
3. Otherwise, the sum p + q is defined for only some choices of p + q.
Associativity of + is respected "as much as possible". Formally, this means that there exists a ring R such that G is contained in the group of units of R, and addition in the partial field is the restriction of addition in the ring to S.
Example: the regular partial field. This has elements {-1, 0, 1}, with addition and multiplication as in ZZ, but 1 + 1 is not defined.
How can we best implement such structures? That is, where should the category PartialFields go? One choice would be to subclass Rings. However, for various reasons it is desirable to return an "undefined_element" instead of the sum in the ring. This would break associativity tests that seem to be required for rings.
Example: take the partial field {(-1)^s 2^k : s,k in ZZ} U {0}, with usual multiplication and addition in QQ restricted to this set (e.g. 1/2 - 1 = -1/2 is ok, but 4 - 1/4 is undefined).
* (1 + 1) + (1 -2) = 1
* ((1 + 1) + 1) - 2 = undefined_element
If we do not subclass Ring, then a whole new can of worms is opened: we're no longer allowed to fill matrices with our elements. I'm not looking forward to re-implementing the Matrix class (though we would probably subclass it anyway as PMatrix, since we need a different determinant and rank algorithm, as well as some new methods).
P.S. How does one define ZZ[1/2] in Sage?
P.P.S. How would I coerce from my own, custom ring into QQ?
StefanFri, 25 Mar 2011 04:54:01 +0100https://ask.sagemath.org/question/8022/