Ask Your Question
1

Exporting from Sage to Macaulay2

asked 2022-02-06 19:24:16 +0100

Polydarya gravatar image

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.)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-02-06 20:43:13 +0100

Max Alekseyev gravatar image

Try macaulay2(f'{a}+{b}')

edit flag offensive delete link more

Comments

Thanks! 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?

Polydarya gravatar imagePolydarya ( 2022-02-06 22:30:21 +0100 )edit
1

You need to double every { or } that you need in the command - like macaulay2(f'matrix {{{a},{b}}}')

Max Alekseyev gravatar imageMax Alekseyev ( 2022-02-06 22:37:41 +0100 )edit

No! 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.

mwageringel gravatar imagemwageringel ( 2022-02-11 08:18:28 +0100 )edit

@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.

Max Alekseyev gravatar imageMax Alekseyev ( 2022-02-11 16:32:20 +0100 )edit

IMO, 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.

mwageringel gravatar imagemwageringel ( 2022-02-11 19:09:22 +0100 )edit

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2022-02-06 19:24:16 +0100

Seen: 222 times

Last updated: Feb 06 '22