14.3.2 GAP and Singular

This example illustrates conversion between Singular and GAP via Sage as an intermediate step. First we create and factor a Singular polynomial.

sage: singular(389)
389
sage: R1 = singular.ring(0, '(x,y)', 'dp')
sage: f = singular('9*x^16-18*x^13*y^2-9*x^12*y^3+9*x^10*y^4-18*x^11*y^2+36*x^8*y^4+18*x^7*y^5-18*x^5*y^6+9*x^6*y^4-18*x^3*y^6-9*x^2*y^7+9*y^8')
sage: F = f.factorize()
sage: print F
[1]:
   _[1]=9
   _[2]=x^6-2*x^3*y^2-x^2*y^3+y^4
   _[3]=-x^5+y^2
[2]:
   1,1,2

Next we convert the factor $ -x^5+y^2$ to a Sage multivariate polynomial. Note that it is important to let $ x$ and $ y$ be the generators of a polynomial ring, so the eval command works.

sage: R.<x,y> = PolynomialRing(QQ,2)
sage: s = F[1][3].sage_polystring(); s
'-x**5+y**2'
sage: g = eval(s); g
-x^5 + y^2

Next we create a polynomial ring in GAP and obtain its indeterminates:

sage: R = gap.PolynomialRing('Rationals', 2); R 
PolynomialRing( Rationals, ["x_1", "x_2"] )
sage: I = R.IndeterminatesOfPolynomialRing(); I
[ x_1, x_2 ]

In order to eval $ g$ in GAP, we need to tell GAP to view the variables x0 and x1 as the two generators of $ R$ . This is the one tricky part. In the GAP interpreter the object I has its own name (which isn't I). We can access its name using I.name().

sage: _ = gap.eval("x := %s[1];; y := %s[2];;"%(I.name(), I.name()))

Now $ x_0$ and $ x_1$ are defined, so we can construct the GAP polynomial $ f$ corresponding to $ g$ :

sage: R.<x,y> = PolynomialRing(QQ,2)
sage: f = gap(str(g)); f
-x_1^5+x_2^2

We can call GAP functions on $ f$ . For example, we evaluate the GAP Value function, which evaluates $ f$ at the point $ (1,2)$ .

sage: f.Value(I, [1,2])
3
sage: g(1,2)        # agrees
3

See About this document... for information on suggesting changes.