| 1 | initial version |
Use order that depends on degree (eg. degrevlex), compute Grobner basis wrt such order, and check if it contains any polynomials of degree 1. Any such polynomial will gives a desired linear combination:
K = GF(2) # can be an arbitrary field
R.<a,b> = PolynomialRing(K,order='degrevlex')
I = R.ideal(a^2-1,a*b)
print([f for f in I.groebner_basis() if f.degree()==1])
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.