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.Tue, 21 Apr 2020 21:05:29 +0200a basis for quotient module/vector spacehttps://ask.sagemath.org/question/50521/a-basis-for-quotient-modulevector-space/I have a ring (field) $R$, a polynomial ring $R[x_1,x_2,...,x_n]$ and a quotient module (vector space) $R[x_1,x_2,...,x_n]/I$ where $I$ is an ideal of $R[x_1,x_2,...,x_n]$ . For the case, when $R$ is a field, the basis of the quotient vector space can be found to consist of the cosets of monomials which are not divisible by leading monomials of grobner basis of $I$. A similar theorem exists for the case when $R$ is a ring with effective coset representatives. For example, the ring of integers. Can I find these coset representatives that form the basis for the quotient module/vector space in sage?Sat, 04 Apr 2020 19:23:39 +0200https://ask.sagemath.org/question/50521/a-basis-for-quotient-modulevector-space/Answer by mwageringel for <p>I have a ring (field) $R$, a polynomial ring $R[x_1,x_2,...,x_n]$ and a quotient module (vector space) $R[x_1,x_2,...,x_n]/I$ where $I$ is an ideal of $R[x_1,x_2,...,x_n]$ . For the case, when $R$ is a field, the basis of the quotient vector space can be found to consist of the cosets of monomials which are not divisible by leading monomials of grobner basis of $I$. A similar theorem exists for the case when $R$ is a ring with effective coset representatives. For example, the ring of integers. Can I find these coset representatives that form the basis for the quotient module/vector space in sage?</p>
https://ask.sagemath.org/question/50521/a-basis-for-quotient-modulevector-space/?answer=50609#post-id-50609I am not very familiar with the case when `R` is not a field, so let me try to answer the case when `R` is a field.
If `R` is a field and `I` is a zero-dimensional ideal, then `R/I` is a finite dimensional vector space and a basis can be computed using the method `normal_basis`:
sage: R.<x,y,z> = QQ[]
sage: I = R.ideal([x^2 + y^2 - 1, z^3, z - x^3])
sage: I.dimension()
0
sage: I.normal_basis()
[y^3*z^2, y^2*z^2, x*y*z^2, y*z^2, x*z^2, z^2, y^3*z, y^2*z, x*y*z, y*z, x*z, z, y^3, y^2, x*y, y, x, 1]
If the ideal is of positive dimension, then Sage does not currently have a way to compute this directly. However, we can use Singular for this. Given a Gröbner basis of an ideal, the function <a href="http://www.singular.uni-kl.de/Manual/4-1-2/sing_275.htm#SEC315">kbase</a> can be used to find the finitely-many monomials of certain degree in a vector space basis of this infinite-dimensional space. Let us define a wrapper function:
def kbasis(I, d):
gb = I.groebner_basis()
# the Singular interface works with ideals, but in Sage we prefer
# polynomial sequences, so we need these conversions
return singular.kbase(gb.ideal(), d).sage().gens()
Now we get:
sage: R.<x,y,z> = QQ[]
sage: I = R.ideal([x^2 + y^2 - 1, z^3])
sage: kbasis(I, 0)
[1]
sage: kbasis(I, 1)
[z, y, x]
sage: kbasis(I, 2)
[z^2, y*z, x*z, y^2, x*y]
sage: kbasis(I, 3)
[y*z^2, x*z^2, y^2*z, x*y*z, y^3, x*y^2]
In Sage, we can now even construct the infinite union over all degrees of these finite sets, which might be convenient for some purposes:
sage: D = DisjointUnionEnumeratedSets(Family(NN, lambda d: kbasis(I, d), name='kbasis_I'))
sage: D
Disjoint union of Lazy family (kbasis_I(i))_{i in Non negative integer semiring}
sage: D[0:15]
[1, z, y, x, z^2, y*z, x*z, y^2, x*y, y*z^2, x*z^2, y^2*z, x*y*z, y^3, x*y^2]
Mon, 06 Apr 2020 22:26:23 +0200https://ask.sagemath.org/question/50521/a-basis-for-quotient-modulevector-space/?answer=50609#post-id-50609Comment by mwageringel for <p>I am not very familiar with the case when <code>R</code> is not a field, so let me try to answer the case when <code>R</code> is a field.</p>
<p>If <code>R</code> is a field and <code>I</code> is a zero-dimensional ideal, then <code>R/I</code> is a finite dimensional vector space and a basis can be computed using the method <code>normal_basis</code>:</p>
<pre><code>sage: R.<x,y,z> = QQ[]
sage: I = R.ideal([x^2 + y^2 - 1, z^3, z - x^3])
sage: I.dimension()
0
sage: I.normal_basis()
[y^3*z^2, y^2*z^2, x*y*z^2, y*z^2, x*z^2, z^2, y^3*z, y^2*z, x*y*z, y*z, x*z, z, y^3, y^2, x*y, y, x, 1]
</code></pre>
<p>If the ideal is of positive dimension, then Sage does not currently have a way to compute this directly. However, we can use Singular for this. Given a Gröbner basis of an ideal, the function <a href="http://www.singular.uni-kl.de/Manual/4-1-2/sing_275.htm#SEC315">kbase</a> can be used to find the finitely-many monomials of certain degree in a vector space basis of this infinite-dimensional space. Let us define a wrapper function:</p>
<pre><code>def kbasis(I, d):
gb = I.groebner_basis()
# the Singular interface works with ideals, but in Sage we prefer
# polynomial sequences, so we need these conversions
return singular.kbase(gb.ideal(), d).sage().gens()
</code></pre>
<p>Now we get:</p>
<pre><code>sage: R.<x,y,z> = QQ[]
sage: I = R.ideal([x^2 + y^2 - 1, z^3])
sage: kbasis(I, 0)
[1]
sage: kbasis(I, 1)
[z, y, x]
sage: kbasis(I, 2)
[z^2, y*z, x*z, y^2, x*y]
sage: kbasis(I, 3)
[y*z^2, x*z^2, y^2*z, x*y*z, y^3, x*y^2]
</code></pre>
<p>In Sage, we can now even construct the infinite union over all degrees of these finite sets, which might be convenient for some purposes:</p>
<pre><code>sage: D = DisjointUnionEnumeratedSets(Family(NN, lambda d: kbasis(I, d), name='kbasis_I'))
sage: D
Disjoint union of Lazy family (kbasis_I(i))_{i in Non negative integer semiring}
sage: D[0:15]
[1, z, y, x, z^2, y*z, x*z, y^2, x*y, y*z^2, x*z^2, y^2*z, x*y*z, y^3, x*y^2]
</code></pre>
https://ask.sagemath.org/question/50521/a-basis-for-quotient-modulevector-space/?comment=50899#post-id-50899I have created [trac ticket #29543](https://trac.sagemath.org/ticket/29543) to make this functionality more accessible.Tue, 21 Apr 2020 21:05:29 +0200https://ask.sagemath.org/question/50521/a-basis-for-quotient-modulevector-space/?comment=50899#post-id-50899