ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 11 Feb 2022 20:17:29 +0100Exporting from Sage to Macaulay2https://ask.sagemath.org/question/60967/exporting-from-sage-to-macaulay2/ I am trying to use Macaulay2 in CoCalc and I am running into a problem that I can't make Macaulay2 take any input that was previosly computed by Sage:
a = 2
b = 3
macaulay2('a+b')
This gives an Error message instead of 5. How do I correct it?
(In the end of the day I need to work with fans because Macaulay2 Polyhedra package has some functions that Sage packages don't have, but I guess knowing the answer to the question above should be enough for me. Thank you.)Sun, 06 Feb 2022 19:24:16 +0100https://ask.sagemath.org/question/60967/exporting-from-sage-to-macaulay2/Answer by Max Alekseyev for <p>I am trying to use Macaulay2 in CoCalc and I am running into a problem that I can't make Macaulay2 take any input that was previosly computed by Sage:</p>
<pre><code>a = 2
b = 3
macaulay2('a+b')
</code></pre>
<p>This gives an Error message instead of 5. How do I correct it?
(In the end of the day I need to work with fans because Macaulay2 Polyhedra package has some functions that Sage packages don't have, but I guess knowing the answer to the question above should be enough for me. Thank you.)</p>
https://ask.sagemath.org/question/60967/exporting-from-sage-to-macaulay2/?answer=60972#post-id-60972Try `macaulay2(f'{a}+{b}')`Sun, 06 Feb 2022 20:43:13 +0100https://ask.sagemath.org/question/60967/exporting-from-sage-to-macaulay2/?answer=60972#post-id-60972Comment by Max Alekseyev for <p>Try <code>macaulay2(f'{a}+{b}')</code></p>
https://ask.sagemath.org/question/60967/exporting-from-sage-to-macaulay2/?comment=61069#post-id-61069@mwageringel: My answer addresses the specific question posed by the OP. You basically saying that the OP should not do things the way shown in the question. It's a valid concern, but strictly speaking it is irrelevant to my answer. Also, it'd be more informative if you add your comment as yet another answer. Relatedly, you'd probably not like how the OP deals with macaulay2 in another question: https://ask.sagemath.org/question/61045/ and may have suggestions on how to improve the approach there.Fri, 11 Feb 2022 16:32:20 +0100https://ask.sagemath.org/question/60967/exporting-from-sage-to-macaulay2/?comment=61069#post-id-61069Comment by Max Alekseyev for <p>Try <code>macaulay2(f'{a}+{b}')</code></p>
https://ask.sagemath.org/question/60967/exporting-from-sage-to-macaulay2/?comment=61075#post-id-61075I stand on my answer as it does address the raised question. Please add your answer and I'd gladly upvote it.Fri, 11 Feb 2022 20:17:29 +0100https://ask.sagemath.org/question/60967/exporting-from-sage-to-macaulay2/?comment=61075#post-id-61075Comment by mwageringel for <p>Try <code>macaulay2(f'{a}+{b}')</code></p>
https://ask.sagemath.org/question/60967/exporting-from-sage-to-macaulay2/?comment=61072#post-id-61072IMO, it would be better to correct the existing answer which has already been accepted. Otherwise it might encourage similar usage as seen in the linked question. It is irrelevant to the linked question though, since the speed problem there is not due to the Sage-Macaulay2 conversion, but it is a result of the computation in Macaulay2 itself being slow.Fri, 11 Feb 2022 19:09:22 +0100https://ask.sagemath.org/question/60967/exporting-from-sage-to-macaulay2/?comment=61072#post-id-61072Comment by mwageringel for <p>Try <code>macaulay2(f'{a}+{b}')</code></p>
https://ask.sagemath.org/question/60967/exporting-from-sage-to-macaulay2/?comment=61065#post-id-61065No! This answer is not the right thing to do. It fails in all but the most basic examples because it relies on Macaulay2 understanding the string representation of Sage objects. Instead, you would usually write
macaulay2(a) + macaulay2(b)
In cases in which you need to pass the operation `+` as string to Macaulay2, you can use
macaulay2('%s + %s' % (macaulay2(a).name(), macaulay2(b).name()))
Here, `.name()` gives you the name of the identifier that represents the object in the Macaulay2 interpreter.Fri, 11 Feb 2022 08:18:28 +0100https://ask.sagemath.org/question/60967/exporting-from-sage-to-macaulay2/?comment=61065#post-id-61065Comment by Max Alekseyev for <p>Try <code>macaulay2(f'{a}+{b}')</code></p>
https://ask.sagemath.org/question/60967/exporting-from-sage-to-macaulay2/?comment=60975#post-id-60975You need to double every { or } that you need in the command - like `macaulay2(f'matrix {{{a},{b}}}')`Sun, 06 Feb 2022 22:37:41 +0100https://ask.sagemath.org/question/60967/exporting-from-sage-to-macaulay2/?comment=60975#post-id-60975Comment by Polydarya for <p>Try <code>macaulay2(f'{a}+{b}')</code></p>
https://ask.sagemath.org/question/60967/exporting-from-sage-to-macaulay2/?comment=60974#post-id-60974Thanks! This works with a+b, however
macaulay2(f'matrix {{a},{b}}')
yields an error, "SyntaxError: f-string: single '}' is not allowed" - how can I make them into a matrix?Sun, 06 Feb 2022 22:30:21 +0100https://ask.sagemath.org/question/60967/exporting-from-sage-to-macaulay2/?comment=60974#post-id-60974