``````

In [3]:

from sage.rings.polynomial.toy_buchberger import *
x,y = QQ['x,y'].gens()
I = ideal(y - 2*x, 1+2*x*y)

B = I.groebner_basis()

set_verbose(1)
buchberger(I)

``````
``````

(-2*x + y, 2*x*y + 1) => -1/2*y^2 - 1/2
G: set([-2*x + y, -1/2*y^2 - 1/2, 2*x*y + 1])

(2*x*y + 1, -2*x + y) => 0
G: set([-2*x + y, -1/2*y^2 - 1/2, 2*x*y + 1])

(2*x*y + 1, -1/2*y^2 - 1/2) => 0
G: set([-2*x + y, -1/2*y^2 - 1/2, 2*x*y + 1])

(-2*x + y, -1/2*y^2 - 1/2) => 0
G: set([-2*x + y, -1/2*y^2 - 1/2, 2*x*y + 1])

3 reductions to zero.

Out[3]:

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

``````
``````

In [3]:

P.<x,y > = PolynomialRing (QQ , order ='degrevlex')
def s_calc(f0,f1,verbose=False):
print('f0 lt', f0.lt())

print('f1 lt', f1.lt())
lcm = f0.lt().lcm(f1.lt())
lcm /= lcm.lc()
print(lcm)
#print(lcm)
#print(lcm//f0.lt()*f0)
#print(lcm//f1.lt()*f1)

s0 = lcm//f0.lt() * f0
s1 = lcm//f1.lt() * f1
print('s0', s0)
print('s1', s1)
if verbose:

print(f0)
print(f1)
print(lcm)
s0 = lcm//f0.lt() * f0
s1 = lcm//f1.lt() * f1
s = s0-s1
return s

f0, f1 = y - 2*x, 1+2*x*y

print(s_calc(f0,f1))

I = ideal(f1, f0)
B = I.groebner_basis()
#print(B)

``````
``````

('f0 lt', -2*x)
('f1 lt', 2*x*y)
x*y
('s0', x*y - 1/2*y^2)
('s1', x*y + 1/2)
-1/2*y^2 - 1/2

``````
``````

In [5]:

f1 = 1 + 2*x*y
f2 = -2*y + y^2
f3 = -2*y^2+x*y
Test_I = ideal(f1,f2,f3)
buchberger(Test_I)

``````
``````

(x*y - 2*y^2, 2*x*y + 1) => -4*y - 1/2
G: set([-4*y - 1/2, y^2 - 2*y, x*y - 2*y^2, 2*x*y + 1])

(2*x*y + 1, -4*y - 1/2) => -1/8*x + 1/2
G: set([-4*y - 1/2, y^2 - 2*y, x*y - 2*y^2, 2*x*y + 1, -1/8*x + 1/2])

(y^2 - 2*y, -4*y - 1/2) => 17/64
G: set([x*y - 2*y^2, 2*x*y + 1, -4*y - 1/2, 17/64, -1/8*x + 1/2, y^2 - 2*y])

(-1/8*x + 1/2, 17/64) => 0
G: set([x*y - 2*y^2, 2*x*y + 1, -4*y - 1/2, 17/64, -1/8*x + 1/2, y^2 - 2*y])

(-4*y - 1/2, 17/64) => 0
G: set([x*y - 2*y^2, 2*x*y + 1, -4*y - 1/2, 17/64, -1/8*x + 1/2, y^2 - 2*y])

(x*y - 2*y^2, -4*y - 1/2) => 0
G: set([x*y - 2*y^2, 2*x*y + 1, -4*y - 1/2, 17/64, -1/8*x + 1/2, y^2 - 2*y])

(-4*y - 1/2, -1/8*x + 1/2) => 0
G: set([x*y - 2*y^2, 2*x*y + 1, -4*y - 1/2, 17/64, -1/8*x + 1/2, y^2 - 2*y])

(2*x*y + 1, -1/8*x + 1/2) => 0
G: set([x*y - 2*y^2, 2*x*y + 1, -4*y - 1/2, 17/64, -1/8*x + 1/2, y^2 - 2*y])

(2*x*y + 1, x*y - 2*y^2) => 0
G: set([x*y - 2*y^2, 2*x*y + 1, -4*y - 1/2, 17/64, -1/8*x + 1/2, y^2 - 2*y])

(x*y - 2*y^2, 17/64) => 0
G: set([x*y - 2*y^2, 2*x*y + 1, -4*y - 1/2, 17/64, -1/8*x + 1/2, y^2 - 2*y])

(x*y - 2*y^2, -1/8*x + 1/2) => 0
G: set([x*y - 2*y^2, 2*x*y + 1, -4*y - 1/2, 17/64, -1/8*x + 1/2, y^2 - 2*y])

(2*x*y + 1, 17/64) => 0
G: set([x*y - 2*y^2, 2*x*y + 1, -4*y - 1/2, 17/64, -1/8*x + 1/2, y^2 - 2*y])

(y^2 - 2*y, 17/64) => 0
G: set([x*y - 2*y^2, 2*x*y + 1, -4*y - 1/2, 17/64, -1/8*x + 1/2, y^2 - 2*y])

(y^2 - 2*y, 2*x*y + 1) => 0
G: set([x*y - 2*y^2, 2*x*y + 1, -4*y - 1/2, 17/64, -1/8*x + 1/2, y^2 - 2*y])

(2*x*y + 1, y^2 - 2*y) => 0
G: set([x*y - 2*y^2, 2*x*y + 1, -4*y - 1/2, 17/64, -1/8*x + 1/2, y^2 - 2*y])

(y^2 - 2*y, -1/8*x + 1/2) => 0
G: set([x*y - 2*y^2, 2*x*y + 1, -4*y - 1/2, 17/64, -1/8*x + 1/2, y^2 - 2*y])

(y^2 - 2*y, x*y - 2*y^2) => 0
G: set([x*y - 2*y^2, 2*x*y + 1, -4*y - 1/2, 17/64, -1/8*x + 1/2, y^2 - 2*y])

(x*y - 2*y^2, y^2 - 2*y) => 0
G: set([x*y - 2*y^2, 2*x*y + 1, -4*y - 1/2, 17/64, -1/8*x + 1/2, y^2 - 2*y])

15 reductions to zero.

Out[5]:

[x*y - 2*y^2, 2*x*y + 1, -4*y - 1/2, 17/64, -1/8*x + 1/2, y^2 - 2*y]

``````
``````

In [ ]:

``````