Ask Your Question

KittyL's profile - activity

2023-03-02 08:55:34 +0100 received badge  Notable Question (source)
2022-11-17 16:38:57 +0100 received badge  Famous Question (source)
2021-08-05 12:00:24 +0100 received badge  Famous Question (source)
2021-06-10 16:56:16 +0100 marked best answer Pass a list of variable names as parameter to a polynomial ring

I am trying to write a function that compute a vector space basis $B$ for the quotient ring $k[x_1,\dots,x_n]/I$. I want to make the list of variables as the input parameter.

I tried this:

var("x,y")
Vlist=[x,y] 
P.<Vlist>=PolynomialRing(QQ,order='degrevlex')
f=x^2+y^3
f.lm()

It gave me error message. I also tried

Vlist=['x,y']

or

Vlist=["x,y"]

None of them works. I know that

P.<x,y>=PolynomialRing(QQ,order='degrevlex')
f=x^2+y^3
f.lm()

works. So I can just type this before I run my function. But is there a way that I can make this as input of the function?

2021-06-10 16:56:15 +0100 received badge  Nice Question (source)
2021-05-18 19:30:37 +0100 received badge  Popular Question (source)
2021-02-02 22:28:28 +0100 received badge  Good Question (source)
2021-02-02 22:28:26 +0100 marked best answer Solving polynomial equations with Groebner basis in $\mathbb{R}$

I am trying to solve the following system of polynomial equations: $$x^2+y^2+z^2=4\ x^2+2y^2=5\ xz=1$$

I used the following command to get a Groebner basis

P.<x,y,z> = PolynomialRing(QQ,order='lex')
PList = [x^2+y^2+z^2-4, x^2+2*y^2-5, x*z-1]
I = ideal(PList)
B = I.groebner_basis(); B
[x + 2*z^3 - 3*z, y^2 - z^2 - 1, z^4 - 3/2*z^2 + 1/2]

Now I want to use B.subs() to plug the solutions for $z$ to solve for $x,y$. It worked well for $z=\pm 1$.

B.subs(z=1)
[x - 1, y^2 - 2, 0]

but not for the $1/\sqrt{2}$ since this is in polynomial ring $\mathbb{Q}[x,y,z]$. If I change the original QQ to RR, the numbers become all decimals.

B.subs(z=1/sqrt(2))
[x - 1.41421356237310, y^2 - 1.50000000000000, 0]

How can I still get exact solutions when using RR? I know I can compute this example by hands, but I'd like to know how to use Sage to solve this kind of problems.

Thank you for any help!

2020-04-12 19:00:34 +0100 received badge  Famous Question (source)
2020-04-01 10:22:31 +0100 received badge  Popular Question (source)
2020-04-01 10:22:31 +0100 received badge  Notable Question (source)
2020-02-02 08:17:40 +0100 received badge  Famous Question (source)
2020-01-26 11:19:50 +0100 received badge  Famous Question (source)
2019-12-18 11:36:53 +0100 received badge  Popular Question (source)
2019-07-01 17:25:24 +0100 received badge  Famous Question (source)
2018-12-11 17:12:00 +0100 received badge  Popular Question (source)
2018-12-11 17:12:00 +0100 received badge  Notable Question (source)
2018-12-06 16:21:41 +0100 received badge  Notable Question (source)
2018-12-06 16:21:41 +0100 received badge  Popular Question (source)
2018-08-30 09:45:31 +0100 received badge  Notable Question (source)
2018-08-10 01:51:21 +0100 received badge  Notable Question (source)
2018-06-17 19:32:48 +0100 received badge  Notable Question (source)
2018-03-14 05:47:58 +0100 received badge  Popular Question (source)
2017-12-11 13:49:33 +0100 received badge  Popular Question (source)
2017-09-29 00:27:31 +0100 received badge  Nice Question (source)
2017-09-18 20:26:56 +0100 commented answer Remove a variable from a polynomial ring k(a,b)[x1,x2,x0] where a,b are parameters

Thank you! That worked! How do we report the error?

2017-09-01 21:09:49 +0100 asked a question Remove a variable from a polynomial ring k(a,b)[x1,x2,x0] where a,b are parameters

I am trying to homogenize polynomials using variable x0 in a polynomial ring k(a,b)[x1,x2] defined as follows:

R.<a,b>    = PolynomialRing( QQ, order='degrevlex' )
K = FractionField( R )
RK.<x1,x2> = PolynomialRing( K, order='degrevlex' )

After homogenization, I define the new polynomial ring with block order:

RKH.<x1,x2,x0>=PolynomialRing(K,order='degrevlex(2),degrevlex(1)')

Then in my program, I need to dehomogenize my polynomials by setting x0=1, and remove the variable x0 from the polynomial ring. This works fine in a polynomial ring without the parameter fraction field. For example

P.<x,y,z>=PolynomialRing(QQ,order='degrevlex(2),degrevlex(1)')
fp=x^2+x*y+4*z^2
R=P.remove_var(z,order='degrevlex');R
R(fp(z=1)).parent()
    Multivariate Polynomial Ring in x, y, z over Rational Field
    Multivariate Polynomial Ring in x, y over Rational Field
    Multivariate Polynomial Ring in x, y over Rational Field

However, with the fraction field k(a,b), the same method does not work any more:

R.<a,b>    = PolynomialRing( QQ, order='degrevlex' )
K = FractionField( R )
RK.<x1,x2> = PolynomialRing( K, order='degrevlex' )
RKH.<x1,x2,x0>=PolynomialRing(K,order='degrevlex(2),degrevlex(1)')
pf=a*x1^2-b*x1*x2+x0^2
RKHn=RKH.remove_var(x0,order='degrevlex')
pfn=pf(x0=1)
RKHn(pfn)
Multivariate Polynomial Ring in x1, x2, x0 over Fraction Field of Multivariate Polynomial Ring in a, b over Rational Field
Error in lines 11-11
 TypeError: not a constant polynomial

I didn't copy down the whole error message so it doesn't look so long. Is there a way to fix this? Thank you for your help!

2017-07-24 21:20:35 +0100 received badge  Popular Question (source)
2017-05-19 14:21:03 +0100 received badge  Enthusiast
2017-05-06 12:09:57 +0100 commented question Insert children of a specified node in a binary tree and retrieve all leaves of a binary tree.

Yes, you are right. I didn't link the one with "insert" since it does not provide me the functionality I was looking for. So I found another one, which does not have "insert", and still cannot do anything since it does not provide a value for each node. Now I decide I should just make a "recursive list" to achieve my goal. It seems Sage does not have a good Binary Tree implementation, at least for my purpose. Thank you for your time!

2017-05-04 21:22:32 +0100 asked a question Insert children of a specified node in a binary tree and retrieve all leaves of a binary tree.

I am trying to use a binary tree to store data. When different cases happens at some step, I will need to create two children from the current node.

I also need to collect all information on the leaves (nodes with no children). I use the following definition of binary trees:

from sage.misc.binary_tree import BinaryTree
T = BinaryTree();

I can insert node the following way:

t.insert(0,[1,2,4]);
t.insert(1,[4,5]);
t.insert(2,[5,0]);

But I couldn't find a way to visualize the tree. Also I don't know how to add two children of one certain node. For example, if 0 is the root (it seems so), 1 is its left child and 2 is its right child (which I am not sure), how do I make sure I add two children for the node 2?

I also looked at this page: (http://doc.sagemath.org/html/en/refer...). I couldn't see how to insert a node with values in it, or how to retrieve information of leaves.

Do I have to define my own tree structure?

Thank you for your help!

2017-04-20 18:57:56 +0100 commented question How to compute syzygy module of an ideal in a quotient ring?

That is a very smart solution. Thank you very much!

2017-04-18 11:34:27 +0100 asked a question How to compute syzygy module of an ideal in a quotient ring?

I am trying to compute the syzygy module of an ideal generated by two polynomials <p,q> modulo I, where I is another ideal. This means to compute a generating set [(p1,q1),...,(ps,qs)] of the module {(g,h): gp+hq is in I}. I know that in Sage, we can use singular command to compute syzygy module:

R.<x,y> = PolynomialRing(QQ, order='lex')
f=2*x^2+y
g=y
h=2*f+g
I=ideal(f,g,h)
M = I.syzygy_module();M
[       -2        -1         1]
[       -y 2*x^2 + y         0]

But this does not work with modulo I:

R.<x,y> = PolynomialRing(QQ, order='lex')
S.<a,b>=R.quo(x^2+y^2)
I=ideal(a^2,b^2);I
M = I.syzygy_module();M
Ideal (-b^2, b^2) of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2)
Error in lines 4-4
Traceback (most recent call last):

Is there a way to do that?

2017-04-15 11:18:18 +0100 commented answer Division algorithm in a polynomial ring with variable coefficients

Thank you for the detailed answer! It worked!

2017-04-15 11:18:18 +0100 received badge  Commentator
2017-03-27 21:26:48 +0100 asked a question Division algorithm in a polynomial ring with variable coefficients

I am working on an algorithm to divide a polynomial f by a list of polynomials [g1, g2, ..., gm]. The following is my algorithm:

def div(f,g): # Division algorithm on Page 11 of Using AG by Cox;
# f is the dividend;
# g is a list of ordered divisors;
# The output consists of a list of coefficients for g and the remainder;
# p is the intermediate dividend;
n = len(g)
p, r, q = f, 0,  [0 for x in range(0,n)]
while p != 0:
    i, divisionoccured = 0, False
    print(p,r,q);
    while i < n and divisionoccured == False:
        if g[i].lt().divides(p.lt()):
            q[i] = q[i] + p.lt()//g[i].lt()
            p = p - (p.lt()//g[i].lt())*g[i]
            divisionoccured = True
        else:
            i = i + 1
    if divisionoccured == False:
        r = r + p.lt()
        p = p - p.lt()
return q, r

Here is an example of implementing the algorithm:

K.<a,b> = FractionField(PolynomialRing(QQ,'a, b'))
P.<x,y,z> = PolynomialRing(K,order='lex')
f=a*x^2*y^3+x*y+2*b
g1=a^2*x+2
g2=x*y-b
div(f,[g1,g2])

Here is the result:

(a*x^2*y^3 + x*y + 2*b, 0, [0, 0])
(((-2)/a)*x*y^3 + x*y + 2*b, 0, [1/a*x*y^3, 0])
(x*y + 4/a^3*y^3 + 2*b, 0, [1/a*x*y^3 + ((-2)/a^3)*y^3, 0])
(4/a^3*y^3 + ((-2)/a^2)*y + 2*b, 0, [1/a*x*y^3 + ((-2)/a^3)*y^3 + 1/a^2*y, 0])
(((-2)/a^2)*y + 2*b, 4/a^3*y^3, [1/a*x*y^3 + ((-2)/a^3)*y^3 + 1/a^2*y, 0])
(2*b, 4/a^3*y^3 + ((-2)/a^2)*y, [1/a*x*y^3 + ((-2)/a^3)*y^3 + 1/a^2*y, 0])
Error in lines 6-6
Traceback (most recent call last):

and some other error messages.

We can see that it worked well until the leading term is 2b. it does not recognize the 2b as a term. I tried:

(x).lt().divides(1)

It gives the answer False. But I tried

(x).lt().divides(a)

It gives error message. Is there a way to solve this? Thank you for your help!

2017-03-27 21:13:38 +0100 marked best answer Computing square free part of a multivariate polynomial

In one of the algorithms I am working on, there is a part asking for the square-free part of a multivariate polynomial. I can find it using a complicated way, namely,

I = ideal(f)
IRad = I.radical().groebner_basis()

But I think this must be a very inefficient way to do it. Is there a better way? Thank you!

2017-03-13 11:19:06 +0100 commented answer The computation of Groebner basis not correct?

I realized I forgot to put order='lex'. Sage must have identified the 'lex' as a variable. Thanks.

2017-03-12 22:44:16 +0100 commented answer The computation of Groebner basis not correct?

Thanks for your answer! I never set parameters. So what is the default? I thought 'lex' means lexicographical order, with whichever order placed in the '< >'. I will check the instructions.

2017-03-12 20:59:54 +0100 asked a question The computation of Groebner basis not correct?

I was trying to compute a Groebner basis for the ideal I=<xz-y, y^2+z,x+1/2yz>, using lex order.

I used the following code:

P.<x,y,z>=PolynomialRing(QQ,'lex')
I=ideal(x*z-y,y^2+z,x+(1/2)*y*z)
G=I.groebner_basis();G

The result is

[z^3 + 2*z, x^2 - 1/2*z, x*y - 1/2*z^2, y^2 + z, x*z - y, y*z + 2*x]

Since the computation is easy, I checked by hands but got different result. So I checked by Singular and got the same result as mine, which is

> groebner(I);
_[1]=z3+2z
_[2]=yz2+2y
_[3]=y2+z
_[4]=2x+yz

So the result from Sage is wrong, since yz^2+2y is in the ideal I, but is not in the Groebner basis from the first computation using I.groebner_basis(). Did I miss something in my command? Or is there a bug that needs to be fixed?