ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 30 Jun 2016 15:23:35 -0500How to convert (some particular) Sage objects into Macaulay2 oneshttps://ask.sagemath.org/question/33975/how-to-convert-some-particular-sage-objects-into-macaulay2-ones/ Hi,
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
MehmetThu, 30 Jun 2016 05:03:45 -0500https://ask.sagemath.org/question/33975/how-to-convert-some-particular-sage-objects-into-macaulay2-ones/Answer by Mehmet Akif Yetim for <p>Hi,</p>
<p>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:</p>
<p>sage: macaulay2('loadPackage "Graphs"')</p>
<p>sage: macaulay2('G = graph({{1,2},{2,3},{3,4}})') </p>
<p>as explained in the Macaulay2 web page.</p>
<p>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,</p>
<p>sage: d={1:[2], 2:[1,3], 3:[2,4], 4:[3]}</p>
<p>sage: G = Graph(d)</p>
<p>sage: macaulay2('H=graph(G)') (or H=macaulay2('graph(G)'))</p>
<p>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.</p>
<p>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. </p>
<p>Can anyone help?</p>
<p>Thanks in advance! :)</p>
<p>Best Regards</p>
<p>Mehmet</p>
https://ask.sagemath.org/question/33975/how-to-convert-some-particular-sage-objects-into-macaulay2-ones/?answer=33983#post-id-33983I'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()))+'})')
Thu, 30 Jun 2016 15:23:35 -0500https://ask.sagemath.org/question/33975/how-to-convert-some-particular-sage-objects-into-macaulay2-ones/?answer=33983#post-id-33983