Skip to content

Instantly share code, notes, and snippets.

@HajimeKawahara
Created November 15, 2023 11:53
Show Gist options
  • Save HajimeKawahara/4e35b1a3d7029ce9c1e93c64424e5081 to your computer and use it in GitHub Desktop.
Save HajimeKawahara/4e35b1a3d7029ce9c1e93c64424e5081 to your computer and use it in GitHub Desktop.
sagemath example to solve a system of polynomial equations
sage: R = PolynomialRing(ZZ, 7, "x,y,z,a,b,c,d", order="lex")
sage: x,y,z,a,b,c,d = R.gens()
sage: eqs = [c*x + 2*x*x - c*y - a, d*y + x*y - x*z, -y*z + z*z - b]
sage: eqst = tuple(eqs)
sage: I = eqst * R
sage: B = I.groebner_basis()
sage: for eq in list(B):
....: print(str(eq)+",")
....:
....:
2*x^2 + x*c - y*c - a,
x*y - x*z + y*d,
2*x*z*d + y^2*c + y*a + y*c*d - 2*y*d^2 - z^2*c - z*a + b*c,
x*b - z^2*d + b*d,
y^3*c + y^2*a + y^2*c*d - 2*y^2*d^2 + 2*y*b*c - z^3*c - z^2*a - z^2*c*d + z*b*c + 2*a*b + b*c*d,
y^2*b*c + y*a*b + y*b*c*d - 2*y*b*d^2 + 2*z^3*d^2 - z^2*b*c - z*a*b - 2*z*b*d^2 + b^2*c,
y*z - z^2 + b,
y*b^2*c - 2*z^4*d^2 - z^2*b*c*d + 4*z^2*b*d^2 + a*b^2 + b^2*c*d - 2*b^2*d^2,
2*z^5*d^2 + z^3*b*c*d - 4*z^3*b*d^2 - z^2*b^2*c - z*a*b^2 - z*b^2*c*d + 2*z*b^2*d^2 + b^3*c,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment