---------!!!!!!!!!!!!!!!!!!!!!!!!!!!!---------
---------!!!  WELCOME TO COCOA 5  !!!---------
---------!!!!!!!!!!!!!!!!!!!!!!!!!!!!---------

-- as in cocoa-4:  polynomial rings
Qa   ::= QQ[a[1..5]];
Qaxy ::= QQ[x,y,a[1..5]], Lex;

Use Qaxy;
(a[1]+a[2])*(x+y);


-- NEW -->  more coefficient rings
Use Qa_xy ::= Qa[x,y];
(a[1]+a[2])*(x+y);

-- first example in Robbiano's presentation
G1 := a[1]*x*y + a[2];
G2 := a[3]*x^2 + a[4]*y^2 + a[5];
G1;  G2;


-- NEW -->  fraction fields
L := NewFractionField(Qa);  -- QQ(a)
Use L_xy ::= L[x,y];        -- QQ(a)[x,y]

-- now we want to map G1, G2 into this ring....

-- NEW -->  homomorphisms

-- Qa_xy -> L_xy :  QQ[a][x,y] --> Q(a)[x,y]    (Qa-algebra --> ring)
-- Qa --> L_xy   :  QQ[a] --> QQ(a) --> QQ(a)[x,y]  (homomorphisms composition)

CoeffHom := CanonicalHom(Qa,L);
Psi := PolyRingHom(Qa_xy,L_xy,  CoeffHom, [x,y]);

RGB := ReducedGBasis(ideal(Psi(G1), Psi(G2)));
indent(RGB);  -- was Set/Unset Indentation in CoCoA-4 

Denoms := [CommonDenom(F) | F In RGB];
indent(Denoms);    // elements of QQ[a]



FreeLocus := lcm(Denoms);
FreeLocus;  // elements of L

-- The free locus comprises the following components: ------------------
factor(FreeLocus).factors;


-- Now we want to compute  (G1, G2, D) intersected QQ[a]  where D is:
D := det(jacobian([G1,G2]));  D;  -- in QQ[a][x,y]

Use Qaxy; -- QQ[x,y,a[1..5]]
-- Qa_xy --> Qaxy  :  QQ[a][x,y] --> QQ[a,x,y]
-- Qa --> Qaxy     :  QQ[a] --> QQ[a,x,y]       (QQ-algebra homomorphism)
phi := PolyAlgebraHom(Qa, Qaxy, [a[1],a[2],a[3],a[4],a[5]]);
psi := PolyRingHom(Qa_xy, Qaxy, phi, [x,y]);

-- The smooth scheme is generated by: -----------------------------------
SmoothScheme := elim([x,y], ideal(psi(G1), psi(G2), psi(D)));
SmoothScheme;

-- The optimal scheme is generated by: ----------------------------------
OptScheme := [phi(FreeLocus)*F | F In gens(SmoothScheme)]; --  phi: Qa --> Qaxy
OptScheme;
