Ask Your Question
0

Is there a SageMath version of Mathematica's '//' shorthand?

asked 2024-04-22 12:06:01 +0200

reynormalizer gravatar image

If I had some expression x^2 + x^3 - 31 and I want to apply a previously defined function f to it, is there a quicker way of doing f(x^2 + x^3 - 31)?

I'm thinking along the lines of Mathematica's x^2 + x^3 - 31 // f, where // applies the function to the expression that precedes it.

edit retag flag offensive close merge delete

Comments

Please provide a complete code example, including the definition of f.

Max Alekseyev gravatar imageMax Alekseyev ( 2024-04-22 15:32:52 +0200 )edit

Hi

f(x)=x^2+1
g(x)=x^2 + x^3 - 31
f(g(x))

But I'm probably missing something here, maybe you could give the function f in order to check with your function as Max Alekseyev asked you ?.

ortollj gravatar imageortollj ( 2024-04-23 06:40:28 +0200 )edit

@ortollj@Max Alekseyev Writing x^2+x^3-31//Sin is equivalent to Sin[x^2 + x^3 - 31] in Mathematica. OP asks whether there is equivalent of this syntax // in Sagemath.

azerbajdzan gravatar imageazerbajdzan ( 2024-04-23 22:44:46 +0200 )edit

Let's wait clarification from OP. I read the question differently, and I do not understand why f(x^2 + x^3 - 31) is not considered quick enough. This may depend on how f is defined, hence I asked for clarification.

Max Alekseyev gravatar imageMax Alekseyev ( 2024-04-23 23:32:46 +0200 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2024-05-03 11:52:50 +0200

Sébastien gravatar image

updated 2024-05-03 13:26:19 +0200

Sage is based on Interactive Python. Therefore, every feature in IPython works in SageMath. For example, one feature is automatic-parentheses-and-quotes.

So, if you are too lazy to write parenthesis and commas, then you can turn on the autocall magic and use it by starting the line by /:

sage: %autocall 1
Automatic calling is: Smart
sage: f(x,y,z) = x + y^2 + z^3
sage: /f x+1 y+2 z+3                  # no parenthesis, no comma!
(z + 3)^3 + (y + 2)^2 + x + 1

There is also the auto-quoting which can be used if you are too lazy to quote strings. It may be activated by starting the line with a comma:

sage: ,print aujourd'hui                # no parenthesis, no comma, no quotes "" !
aujourd'hui

For more information and options, see the documentation of IPython on the link above or as follows:

$ sage -ipython
Python 3.11.1 (main, Sep  2 2023, 13:40:58) [GCC 9.4.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.6.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: ?
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

Stats

Asked: 2024-04-22 12:06:01 +0200

Seen: 179 times

Last updated: 12 hours ago