Ask Your Question

How to convert (some particular) Sage objects into Macaulay2 ones

asked 2016-06-30 12:03:45 +0200


I do some calculations about graphs and ideals via M2 interface of Sage or just using M2, but for that, I have to use M2 input as below:

sage: macaulay2('loadPackage "Graphs"')

sage: macaulay2('G = graph({{1,2},{2,3},{3,4}})')

as explained in the Macaulay2 web page.

Is there a way to convert a graph or an ideal written in Sage code into Maculay2 ones so that it can be employed in M2 interface. For instance,

sage: d={1:[2], 2:[1,3], 3:[2,4], 4:[3]}

sage: G = Graph(d)

sage: macaulay2('H=graph(G)') (or H=macaulay2('graph(G)'))

Of course M2 won't accept my silly code in the 3rd line, but I've tried various ways like injecting a square free-quadratic-monomial ideal or edge list of a graph into M2 and I always fail. I also have the same problem for ideals.

It's a long-standing problem of mine and it costs me writing heavy codes in Sage for multiple calculations. Calculating via M2 with Sage inputs will save lots of my time.

Can anyone help?

Thanks in advance! :)

Best Regards


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-06-30 22:23:35 +0200

I've got the answer from Dr. Dima Pasechnik, in Sage-Support Google group. Thanks to him!

Some string manipulations and functional programming operators do the job:

sage: macaulay2('loadPackage "Graphs"')

sage: G = Graph({1:[2], 2:[1,3], 3:[2,4], 4:[3]})

sage: macaulay2('H = graph({'+','.join(map(lambda (x,y,_): '{'+str(x)+','+str(y)+'}', G.edges()))+'})')

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-06-30 12:03:45 +0200

Seen: 252 times

Last updated: Jun 30 '16