# How to make Sage know that a set is an ideal

I have constructed the following ideal

J = {0, x*y*z - x*y - x*z + y*z - x + y - z, x*z - y*z - x + y - 1, x*y*z + x*y + x*z + y*z - z - 1, x*y + x*z + x - y + z, -x*y*z - x*y + x*z - y*z - x - y - z, ....}


in the ring

$$R = F[X,Y,Z]/(X^2-1,Y^2-1,Z^2-1)$$

where $F=GF(3)$ and $x$ (resp; $y$, $z$) is the residue class of $X$ (resp. $Y$, $Z$) modulo the ideal $(X^2-1, Y^2-1, Z^2-1)$. By its construction, the set $J$ is indeed an ideal, containing 2187 elements, so it is hard to write or copy all its elements. I want to find a Groebner basis of $J$, by writing

B = J.groebner_basis(),


but Sage returns

TypeError: R must be a commutative ring.


This error seems to mean that Sage doesn' t remember that $J$ is the above set anymore and consider $J$ as an inappropriate new objet of a new ring $R$!

I must first construct the ideal

H = ideal(0, x*y*z - x*y - x*z + y*z - x + y - z, x*z - y*z - x + y - 1, x*y*z + x*y + x*z + y*z - z - 1, x*y + x*z + x - y + z, -x*y*z - x*y + x*z - y*z - x - y - z, ....)


and then compute

B = H.groebner_basis().


That works, but, as I previously said, it is not easy to construct the ideal $H$ because that needs copy and paste 2187 elements!

Therefore I'd like to know whether there is another way to the task, without copying and pasting all of the elements of $J$, and declaring the ideal of these elements, is there a way to convert a set of elements in a ring (which is already an ideal) to the underlying ideal?

edit retag close merge delete

I have updatet the question because it contained some syntax errors

( 2020-08-12 16:23:31 +0200 )edit

The computation

B=H.groebner_basis()

answers my preeceding question "Does sage allow computation of a groebner basis of an ideal J in the quotient ring Z/pZ[X_1,...X_r]/I?". The answer is "YES".

( 2020-08-12 16:35:10 +0200 )edit

Please provide enough code for anyone to reproduce in a fresh Sage session. For instance what is F?

If the question is not self-contained, at least provide an explicit reference to a previous question where things are defined.

( 2020-08-13 02:49:05 +0200 )edit

From your previous questions it would seem this is the context.

Construct a finite field, a multivariate polynomial ring over it, and the quotient by the ideal generated by three polynomials:

sage: F = GF(3)
sage: FXYZ.<X, Y, Z> = F[]
sage: R.<x, y, z> = FXYZ.quo([X^2 - 1, Y^2 - 1, Z^2 - 1])


Check what we have so far:

sage: R
Quotient of Multivariate Polynomial Ring in X, Y, Z
over Finite Field of size 3 by the ideal (X^2 - 1, Y^2 - 1, Z^2 - 1)

sage: R.gens()
(x, y, z)

sage: x^2, y^2, z^2
(1, 1, 1)


Now how do you construct the ideal J?

( 2020-08-13 02:49:53 +0200 )edit

Thank for your remarks, the set $F$ is the finite field $GF(3)$ as you knew. The ideal $J$ is a "multicyclic code" of dimension $3$, and is equal the set of polynomials of $R$ which vanishes on a finite subset of $F^3$. Here is the code :

def code(POLS,ZER):

     C=Set({})
for f in ENS:
V={f.lift()(c) for c in POLS}
if V=={0}:
C=C+Set({f})
return C


In my case, POLS is the set of polynomials of $R$ ( of degree $\leqslant (1,1)$, using the lexicographical order) and ZER a subset of $F^3$ consisting of a unique element. More time is needed to provide the codes for constructing POLS, I will provide these latter on.

( 2020-08-13 06:45:00 +0200 )edit

For the construction of the POLS, I used the following program :

def vect2pol(c,Vars):

       n=len(c)
po=0
for i in range(n):
po=po+c[i]*Vars[i]
return po


where : c is a tuple of an element from a finite field

Vars a list of monomials with the same length as c

for example

list2pol((1, 2, 1, 2, 0, 0, 1, 1),[1, z, y, yz, x, xz, xy, xy*z])

produces

xyz + xy - yz + y - z + 1.

In my case, POLS is the list of elements of $R$. I first construct the cartesian product $F3^8$ :

S=Set(list(cartesian_product([F3]*8))).

Then I apply the function vect2pol to the elements of S, with Vars =[1, z, y, yz, x, xz, xy, xy*z]:

POLS={vect2pol(c,Vars) for c in S ...(more)

( 2020-08-13 09:55:22 +0200 )edit

The set $J$ is then those of the polynomials of $R$ which vanishes on ${(1,2,1)}$ (It may be not be equal to the initial $J$ in my question), but that doesn't matter, it also contains 2187 elements). Using the command nbruin gave below, I entered

J1=ideal(*J);J1

B=J1.groebner_basis();B

and Sage returned

[x - 1, y + 1, z - 1].

The problem is solved : $J1$ is the ideal whose elements are the same as those of $J$ and no copy and paste were needeed!

( 2020-08-13 10:35:49 +0200 )edit

Sort by » oldest newest most voted

Try:

ideal(*J)


This is standard python syntax: f(*[a1,a2,a3]) does the same thing as f(a1,a2,a3).

Incidentally, I think you've hidden some of the commands. The code you suggest should produce:

sage: J.groebner_basis()
AttributeError: 'set' object has no attribute 'groebner_basis'


Finally, it seems you want to compute a Groebner basis of an ideal in a quotient ring. There is no such thing! Groebner bases are for ideals of polynomial rings. You should take the inverse image of that ideal in the polynomial ring (that's easy to do: just lift the generators and add the generators of the quotienting ideal to it) and compute a Groebner basis of that.

more

Thank you very much, the command you give works : using the ideal $J$ from above, I write

H=ideal(*J)

then

B =H.groebner_basis()

and Sage return the result! No copy and paste of the elements of $J$ are needed, wonderful !

( 2020-08-13 09:30:05 +0200 )edit

Strangely, the method groebner_basis() works for an ideal in the quotient ring R (see the above example, in the comments in response to slelievre). Perhaps, as you have said, Sage use the lift() method to compute a Gröbner basis in $F3[X,Y,Z]$ and the returned to $R$. I was confused when I first used this for ideals in quotient ring, this is why I asked the question "Does sage allow computation of a groebner basis of an ideal J in the quotient ring Z/pZ[X_1,...X_r]/I?

( 2020-08-13 10:45:33 +0200 )edit