Hey everyone:

I was hoping some of you could provide some insight where my knowledge is 
lacking. I'm trying to add to the M2/Sage interface by adding a conversion 
for the M2 Divide class. Sage can already convert polynomials, so my hope 
was to just have it treat the Divide class as two polynomials, one in the 
numerator and the other in the denominator. Here is an example of an object 
in the divide class:
macaulay2.eval("""
K = toField(QQ[zet]/(zet^8 - zet^7 +zet^5 - zet^4 +zet^3 -zet + 1))
A=matrix{{zet^1,0},{0,zet^13}}
needsPackage "InvariantRing"
G=generateGroup({A},K)
P = molienSeries G
 """)

P is a "Divide" object. Here is an example of Sage converting a polynomial 
from M2 to Sage:
macaulay2.eval(""" 
needsPackage "Points"; 
M = matrix{{1,2,3},{4,5,6}}
R = QQ[x,y,MonomialOrder=>Lex]; 
(Q,inG,G) = points(M,R) 
G#0
ring G#0
""") 
G0 = macaulay2('G#0').to_sage(); G0

G in M2 is a list of polynomials, and G#0 is the first one. Here's what it 
looks like:

 3      2
y  - 15y  + 74y - 120

I convert this to a sage object, G0, and it appears as:

y^3 - 15*y^2 + 74*y - 120

The part that I really need is where Sage changes M2's two-line display for 
exponents on variables to just the standard Sage notation. I'm looking at the 
to_sage()
method in the source code but I can't seem to figure out how it's doing it. Am 
I missing something obvious? G#0 is a polynomial ring I believe, and here 
is the code in the to_sage function for PolynomialRings:
            elif cls_str == "PolynomialRing":
                from sage.rings.all import PolynomialRing
                from sage.rings.polynomial.term_order import 
inv_macaulay2_name_mapping

                #Get the base ring
                base_ring = self.coefficientRing().to_sage()

                #Get a string list of generators
                gens = str(self.gens())[1:-1]

                # Check that we are dealing with default degrees, i.e. 1's.
                if self.degrees().any("x -> x != {1}").to_sage():
                    raise ValueError("cannot convert Macaulay2 polynomial ring 
with non-default degrees to Sage")
                #Handle the term order
                external_string = self.external_string()
                order = None
                if "MonomialOrder" not in external_string:
                    order = "degrevlex"
                else:
                    for order_name in inv_macaulay2_name_mapping:
                        if order_name in external_string:
                            order = inv_macaulay2_name_mapping[order_name]
                if len(gens) > 1 and order is None:
                    raise ValueError("cannot convert Macaulay2's term order to 
a Sage term order")

                return PolynomialRing(base_ring, order=order, names=gens)


Where in this code does that conversion happen? It's like parsing ascii 
art...

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to