Ask Your Question

heluani's profile - activity

2019-09-12 13:43:16 -0500 asked a question bug in basis or family?

I am having trouble dealing with modules with infinite bases and I think I pin-pointed the issue to the fact that there are no checks on elements belonging on a family. I am not sure if this is a feature of Sage or a bug so I'll accept any explanation on this. An example will clarify the issue:

sage: E = cartesian_product([{'L'}, NonNegativeIntegers()])
sage: ('L', 0) in E
True
sage: ('L', -2) in E
False
sage: M = CombinatorialFreeModule(QQ, E)
sage: B = M.basis()
sage: B[('L', -3)] 
B[('L', -3)]
sage: B[('L', -3)] in M
True
So I am not sure I can trust any code I'm writing with CombinatorialFreeModule cause I can make those checks, but I will have to go over the source to see if every method that I am calling makes these checks. Somehow if this is a feature I should get a warning or something in the docs isn't it?

2019-09-11 09:12:25 -0500 commented answer Restriction of scalars for free modules

Perhaps, I don't understand, which object is an instance of VectorSpaces(QQ).parent_class? or which object is in VectorSpaces(QQ)?

2019-09-10 12:56:22 -0500 asked a question Restriction of scalars for free modules

Suppose I have a free module M over QQ[x]. How do I obtain the underlying QQ vector space? FreeModule does not have this coercion:

sage: R = PolynomialRing(QQ,'x')
sage: R in CommutativeAlgebras(QQ)
True
sage: M = FreeModule(R,3)
sage: M in VectorSpaces(QQ)
False

And CombinatorialFreeModule only takes already subcategories of QQ-vector spaces:


sage: M = CombinatorialFreeModule(QQ, ['a','b','c'], category=Modules(R))
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
....
ValueError: Subcategory of `Category of vector spaces with basis over Rational Field` required; got `Category of modules over Univariate Polynomial Ring in x over Rational Field`
2019-09-06 10:15:29 -0500 received badge  Self-Learner (source)
2019-09-06 04:43:55 -0500 answered a question implement algebras with some extra structure

What I found was the easiest is to define my parents as inheriting from the corresponding objects from Algebras(QQ), and then reset the category using Parent's methods since I am guaranteed to have a subcategory. For example

 def CParent (MPolynomialRing_libsingular)
    def __init__(self, n, names, order)
        self._somedata = somevalue
        super(CParent, self).__init__(QQ, n, names, order)
        self._unset_category()
        self._init_category_(Cs)

This way I don't even need to implement an element class and I can focus on morphisms which is the only thing that changes in this category.

2019-09-04 06:22:33 -0500 received badge  Necromancer (source)
2019-09-04 06:22:33 -0500 received badge  Self-Learner (source)
2019-09-04 06:22:33 -0500 received badge  Teacher (source)
2019-09-04 06:21:51 -0500 received badge  Good Question (source)
2019-09-04 05:28:48 -0500 received badge  Nice Question (source)
2019-09-03 14:05:43 -0500 asked a question 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/refe... or https://doc.sagemath.org/html/en/them... I could set up

class Cs(Category)
    def super_categories(self):
          return[Algebras(QQ)]

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):

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__']}

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.

2019-09-03 08:00:03 -0500 answered a question Change degree in InfinitePolynomialRing

For what it's worth, you can force degree(x_n) = n+1 with the patch


--- /usr/lib/python2.7/site-packages/sage/rings/polynomial/infinite_polynomial_ring.py.bak  2019-09-03 09:24:46.299916008 -0300
+++ /usr/lib/python2.7/site-packages/sage/rings/polynomial/infinite_polynomial_ring.py  2019-09-03 09:42:00.063223890 -0300
@@ -993,8 +993,12 @@
         except ValueError:
             raise ValueError("Can't convert %s into an element of %s; the variables aren't admissible"%(x,self))

+        from sage.rings.integer import Integer
+
+        DegList = [Integer(s.split('_')[1])+1 for s in VarList]
         from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
-        R = PolynomialRing(self._base, VarList, order=self._order)
+        from sage.rings.polynomial.term_order import TermOrder
+        R = PolynomialRing(self._base, VarList, order=TermOrder(self._order,DegList))
         if isinstance(R, MPolynomialRing_libsingular) and isinstance(x,MPolynomial_libsingular): # everything else is so buggy that it's even not worth to try.
             try:
                 # Problem: If there is only a partial overlap in the variables
@@ -1449,8 +1453,11 @@
                 raise IndexError("Variable index is too big - consider using the sparse implementation")
             names = reduce(operator.add, names)
             names.sort(key=P.varname_key, reverse=True)
+            from sage.rings.integer import Integer
+            DegList = [Integer(s.split('_')[1])+1 for s in names]
             #Create the new polynomial ring
-            P._P = PolynomialRing(P.base_ring(), names, order = P._order)
+            from sage.rings.polynomial.term_order import TermOrder
+            P._P = PolynomialRing(P.base_ring(), names, order = TermOrder(P._order, DegList))
             ##Get the generators
             P._max = i
             #return InfinitePolynomial_dense(P, P._P.gen(P._P.variable_names().index(self._name+'_'+str(i))))

I opened a ticket in https://trac.sagemath.org/ticket/28452

2019-09-02 14:34:50 -0500 answered a question is an object of a subcategory an object of the ambient category?

I'll add an answer in case someone finds something similar. I am new to sage so I suppose there's something silly that I am doing and there are better ways of implementing this.

It turns out that Category_over_base_ring reimplements __contains__ and it tests for the base ring as well. For some reason that I don't know yet my parent's base_ring method does not call D.parent_class.base_ring method but some other. I overloaded it in DParent as follows


class DParent (Parent,UniqueRepresentation):
     ...
     def base_ring(self):
           return self.category().base_ring()

And now J in C returns true.

2019-09-02 11:22:50 -0500 received badge  Editor (source)
2019-09-02 11:22:25 -0500 asked a question is an object of a subcategory an object of the ambient category?

I have defined a category Cs() and its subcategory Ds() as follows:


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

The omitted code I think its irrelevant. I can check that Ds() is a subcategory of Cs():


sage: C = Cs(QQ)
sage: D = Ds(QQ)
sage: D.is_subcategory(C) 
True
sage: 

Now I create a parent of Ds() as follows:


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))
...

And I can check that these parents are objects of Ds() but not of Cs():


sage: J = DParent(QQ, 1, 'x', order=TermOrder('wdeglex', (2,)))
sage: J in C
False
sage: J in D
True

Where can I be making a mistake?

Addition: I am looking at the implementation in sage/categories/category.py and I am more puzzled:

sage: J.category().is_subcategory(C)
True
sage: C.__contains__(J)
False

But at least I get


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:
2019-08-31 14:51:59 -0500 asked a question Viewing a Derivation as a linear endormorphism

I have a ring R over the rational numbers and a Derivation D of R. I want to view D as a linear endomorphism of R over Q. I tried these two methods. First the obvious one

sage: R = PolynomialRing(QQ,'x')
sage: hom_space = End(R, category=VectorSpaces(QQ))
sage: M = R.derivation_module()
sage: D = M.gen(0)
sage: D in hom_space
False

Then I figured I could try to make a linear transformation explicitly out of D:


sage: E = linear_transformation(R,R,D)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-39-704105f377c5> in <module>()
----> 1 E = linear_transformation(R,R,D)
....
....
TypeError: first argument must be a matrix or a vector space, not Multivariate Polynomial Ring in x, y, z over Rational Field

So finally I tried to coerce R into a vector space over Q


sage: C = VectorSpaces(QQ)
sage: C(R)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
...
.....
TypeError: 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomialRing_libsingular' object has no attribute 'vector_space'
unable to coerce x (=Multivariate Polynomial Ring in x, y, z over Rational Field) into Category of vector spaces over Rational Field
2019-08-29 05:30:20 -0500 asked a question Virasoro Verma module Basis

Hi I am starting to look at the implementation of the Virasoro algebra and some of its modules in

https://doc.sagemath.org/html/en/refe...

I have a question regarding the method basis() that returns a basis of the module. As the following example shows this particular linear combination of basis elements is zero so I wander in which sense are we getting a basis or a generating set, or even better how to actually get sage to recognize that the combination is actually zero?

sage: g = lie_algebras.VirasoroAlgebra(QQ)
sage: V = g.verma_module(1/2,0)
sage: d = g.basis()
sage: B = V.basis()
sage: v = V.highest_weight_vector()
sage: B[-2,-1] - B[-1,-2] + B[-3] == V.zero()
False
sage: B[-2,-1] - B[-1,-2] + B[-3]
d[-3]*v + d[-2]*d[-1]*v - d[-1]*d[-2]*v
sage: d[-3]*v + d[-2]*(d[-1]*v) - d[-1]*(d[-2]*v) == V.zero()
True
2019-08-28 11:07:56 -0500 commented answer How to get the graded part of a graded ring?

Thanks for the reply, I had seen another question with this answer. What I ended up doing is implementing the same basis(n) method from the source code of GradedCommutativeAlgebra in my quotient ring because I couldn't change the degrees.

2019-08-28 10:46:03 -0500 received badge  Scholar (source)
2019-08-28 10:46:02 -0500 commented answer weighted univariate polynomials

Thanks a lot this is precisely what I needed. I had tried (2,) before but not explicitly adding the ,1,

2019-08-28 07:03:57 -0500 commented question weighted univariate polynomials

That doesn't work for a number of other reasons, I have a particular derivation of degree 1 and doubling the degrees is not an option. I need a number of methods from PolynomialRings and Groebner bases that I cannot coalesce to GradedCommutativeAlgebra and a few more. But still it's striking why that example as in my question is implemented the way it is

2019-08-27 13:55:48 -0500 asked a question weighted univariate polynomials

I have a polynomial algebra in n variables k[x_1,...,x_n]. I know how assign different degrees to each of the generators as in

sage: P = PolynomialRing(QQ, 'x,y,z', order = TermOrder('wdegrevlex', (2,3,4)))
sage: P.inject_variables()
Defining x, y, z
sage: z.degree()
sage:
4

However if I want to do this with only one variable this does not work

sage: P = PolynomialRing(QQ, 'x', order = TermOrder('wdegrevlex', (2)))
sage: P.inject_variables()
Defining x
sage: x.degree()
1

I wander if I can do this in an uniform way cause I need to use a class that takes an arbitrary number of variables.

2019-08-27 09:19:11 -0500 commented question How to get graded component of graded ring

my question was closed as duplicate, but I have been looking quite a bit in ask.sagemath.org and couldn't find the same question. I found similar questions like for freely generated rings only.

2019-08-27 08:34:06 -0500 asked a question How to get the graded part of a graded ring?

I have a graded quotient of a graded polynomial ring, say something like

P  = PolynomialRing(QQ, , 'x,y,z', order=TermOrder('wdegrevlex',(1,2,3)))
I = P.ideal(x*y^2 + x^5, z*y + x^3*y)
Q = P.quotient(I)

I would like to get the vector space over QQ consisting on vectors of degree, say 9, in Q.

2019-08-27 08:32:45 -0500 asked a question How to get graded component of graded ring

I have a graded quotient of a graded polynomial ring, say something like

P  = PolynomialRing(QQ, , 'x,y,z', order=TermOrder('wdegrevlex',(1,2,3)))
I = P.ideal(x*y^2 + x^5, z*y + x^3*y)
Q = P.quotient(I)

I would like to get the vector space over QQ consisting on vectors of degree, say 9, in Q.

2019-05-10 14:44:21 -0500 received badge  Popular Question (source)
2018-10-30 08:02:19 -0500 commented question compute first (and only first) values of Hilbert function

There is no previous definition of 'x' and I is a generic homogeneous ideal Ideal (x_11^3 + ... ) of Multivariate Polynomial Ring in x_11, x_21, x_31, x_12,..., x_26, x_36 over Rational Field.

2018-10-26 01:42:32 -0500 asked a question compute first (and only first) values of Hilbert function

I have an homogeneous ideal (say $I$) and I'm interested in computing the first few values of the Hilbert function. I undestand that doing something like

QQ[['x']](I.hilbert_series()(x)

does give me this, but this seems to require computing the whole Hilbert series which blows up for my problem quickly. Is there a way of getting the first few values without computing the whole thing?

2018-10-24 14:26:50 -0500 received badge  Nice Question (source)
2018-10-24 12:38:41 -0500 asked a question Change degree in InfinitePolynomialRing

If I use

 P.<x,y,z> = InfinitePolynomialRing(QQ)

Assuming any of the orderings 'lex, deglex, degrevlex' I will have

$z_0 < z_1 < z_2 < ... < y_0 < y_1 < ... < x_0 < x_1 < ...$

And each variable having degree 1. I would like to obtain something like 'deglex' but assigning degree $n$ to $x_n,y_n,z_n$ so that in particular I would obtain

$z_0 < y_0 < x_0 < z_1 < y_1 < x_1 < ... $

Is there a way to implement this. It seems that in order to compute Grobner bases on arc schemes these orderings are much more natural that the ones implemented, but I just started looking at Sage so I may have missed the right implementation of polynomial rings in infinitely many variables to work.

2018-10-24 12:22:00 -0500 received badge  Supporter (source)
2018-10-24 12:21:59 -0500 commented answer formal series over InfinitePolynomialRing

Thanks, I've been using the first sum as in your post and more or less I can get by doing some computations up to each order.

2018-10-24 10:47:05 -0500 received badge  Student (source)
2018-10-24 10:37:04 -0500 asked a question formal series over InfinitePolynomialRing

I apologize if the question does not belong here. This is my first try to using sage and I find the documentation hard to read/search. I am trying to work with symbolic power series over a non-Noetherian ring. So for example I have:

sage: P.<x> = InfinitePolynomialRing(QQ) 
sage: R.<t> = PowerSeriesRing(P)

And I'd like to consider the series $f(t) = \sum x_n t^n$ as an element of R. But my first try


    sage: sum(x[n]*t^n,(n,0,oo))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-27-d7d20df9d062> in <module>()
----> 1 sum(x[n]*t**n,(n,Integer(0),oo))

/usr/lib64/python2.7/site-packages/sage/rings/polynomial/infinite_polynomial_ring.pyc in __getitem__(self, i)
   1433             alpha_1
   1434         """
-> 1435         if int(i) != i:
   1436             raise ValueError("The index (= %s) must be an integer" % i)
   1437         i = int(i)

TypeError: int() argument must be a string or a number, not 'function'

I'll appreciate any help or if you can point me to the documentation where to read about this.