I am trying to give an answer, for this, i need to clarify some points during the answer. In the OP, the ideal $J$ appears once as an ideal in a quotient ring of the polynomial ring (anneau) $A=\Bbb Q[x,y]$, then as an ideal in $A$. This is maybe the point causing problems, so i will restate, hoping to hit the point of the question.
Let $R$ be the ring $R=\Bbb Q[x,y]$. Let $I,J$ be two ideals of $R$. Then we have the chains of inclusions (injections):
$$
\begin{aligned}
&0\to I\to I+J\ ,\text{ and}\\
&0\to J\to I+J\ .
\end{aligned}
$$
Passing to quotients of $R$ we obtain morphisms (surjections):
$$
\begin{aligned}
&R\to R/I\to R/(I+J)\ ,\text{ and}\\
&R\to R/J\to R/(I+J)\ .
\end{aligned}
$$
The $R/I$-module $(I+J)/I$ may be considered an ideal.
(The $R/J$-module $(I+J)/J$ may be considered an ideal.)
Let $Q=$Rq be the quotient mentioned in the OP.
Then we have isomorphisms:
$$
\underbrace{\frac{R/I}{(I+J)/I}}_{\displaystyle=\frac Q{(I+J)/I}}\cong \frac R{I+J}\cong \frac{R/J}{(I+J)/J}\ .
$$
Now i am trying to understand the question inside of the last quotient ring(s), based on the given example. We start explicitly with:
$$
\begin{aligned}
R &= \Bbb Q[x,y]\ ,\\
I &= (\ xy-1\ )\ ,\\
Q &= A/I\ ,\\
J &= (\ 2x^2 - 4y + 1\ , \ 3x^3 - 2x^2 + y^2 - 1\ )\ .
\\
&\qquad\text{ Then:}
\\
I+J &= (\ xy-1\ ,\ 2x^2 - 4y + 1\ , \ 3x^3 - 2x^2 + y^2 - 1\ )\ .
\end{aligned}
$$
(I am using I instead of ideal1 and J instead of ideal2.)
We consider the ideal "generated by $J$" inside the quotient $Q=A/I$. Strictly speaking we map $J$ to $Q=A/I$, and consider the image as an ideal. This ideal is $(J+I)/I$.
The code from the OP is building a Groebner basis now for this ideal of $Q$.
Well, i am modest here, any system of generators is enough for this discussion now. One such basis may be the union of the given generators for $I$ and $J$. And taking them modulo $I$ makes the $I$-generators zero in the quotient, so the $Q=A/I$-ideal $(J+I)/I$ is generated by $(xy-1)$ modulo $I$. OK, now we can try to "do more", and ask for a Groebner basis. Let us type some code for the story so far.
R.<x,y> = PolynomialRing(QQ, 2)
I = R.ideal(x*y - 1)
J = R.ideal([2*x^2 - 4*y + 1, 3*x^3 - 2*x^2 + y^2 - 1])
Q.<X,Y> = R.quotient(I)
print(f'Q is the ring:\n{Q}')
print(f'Q(x), Q(y) are now {Q(x)}, {Q(y)}\n')
# so X, Y are the images of x, respectively y in Q = R/I
JQ = Q.ideal(J.gens())
print(f'The ideal JQ is:\n{JQ}\n')
# so already we have other generators for JQ = (J+I)/I
print(f'... the generators of JQ are:\n')
for gen in JQ.gens():
print(f' {gen}')
print(f'\nJQ has the groebner pasis:\n{JQ.groebner_basis()}')
We copy+paste into the sage interpreter, obtain...
Q is the ring:
Quotient of Multivariate Polynomial Ring in x, y
over Rational Field by the ideal (x*y - 1)
Q(x), Q(y) are now X, Y
The ideal JQ is:
Ideal (2X^2 - 4Y + 1, 3X^3 - 2X^2 + Y^2 - 1)
of Quotient of Multivariate Polynomial Ring in x, y
over Rational Field by the ideal (x*y - 1)
... the generators of JQ are:
2*X^2 - 4*Y + 1
3*X^3 - 2*X^2 + Y^2 - 1
JQ has the groebner pasis:
[1]
The "other way" from the OP is not so clear for me.
We start with $J$, ideal in $R$. Then pick the Groebner basis of $J$.
Then we have to pass somehow to the quotient modulo $I$.
When done explicitly as above, we obtain the generator $1$.
We can also do "this" at $R$-level, considering the ideal
$K=I+J$ with generators the union of the generators for $I,J$,
then asking for a Groebner basis of $K$. Then passing to the quotient.
We obtain a new ideal of the quotient, let us denote it by KQ in the code.
In a dialog with the sage interpreter, this is in the given example...
sage: K = R.ideal(I.gens() + J.gens())
sage: K
Ideal (x*y - 1, 2*x^2 - 4*y + 1, 3*x^3 - 2*x^2 + y^2 - 1)
of Multivariate Polynomial Ring in x, y over Rational Field
sage: K.groebner_basis()
[1]
So there is no difference. Both ways are the same.
We can consider also the ideal KQ:
sage: KQ = Q.ideal(K.gens())
sage: KQ
Ideal (0, 2*X^2 - 4*Y + 1, 3*X^3 - 2*X^2 + Y^2 - 1)
of Quotient of Multivariate Polynomial Ring in x, y
over Rational Field by the ideal (x*y - 1)
(As seen, the $I$-generator goes to zero when passing to the generators of KQ.)
So what does in an "unexpected" way the code in the OP? (In this new notation, that is more structural, seen from where i am staying now.)
I am really not expecting to see $xy$ in $J$, so also not in the small list of elements of a Groebner basis of $J$. Even $XY$ is only "by chance" in the Groebner basis of $K$, since $XY=1$ and $1$ is by chance computed as the only generator in the Groebner basis of $K$.
sage: x*y in J
False
sage: x*y in K
True
sage: X*Y in KQ
True
sage: x*y in J.groebner_basis() # there is no chance for this, since xy not in J
False
sage: X*Y in KQ.groebner_basis()
True
sage: KQ.groebner_basis()
[1]
sage: X*Y
1
ideal2to be the ideal ofRgenerated by $x^2 - 4y + 1, 3x^3-2x^2+y^2-1$, and $xy-1$. – Daniel Schepler Oct 01 '21 at 23:52