Ask Your Question
1

Composite function: how to show function names instead of its full expression?

asked 2020-07-27 16:44:25 +0100

delta_omega gravatar image

updated 2020-07-28 12:03:17 +0100

slelievre gravatar image

Suppose I define a function f(x) = x**2 and a function g(y) = f(y) + 2*y.

When I type show(g) the output is: y**2 +2*y.

What should I do to have the show output as f(y) + 2*y instead?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-07-28 12:35:47 +0100

slelievre gravatar image

Not sure Sage supports that kind of "holding".

Here is a workaround.

Define two versions of the function f, one "anonymous" and one "explicit":

sage: f = function('f')
sage: ff(x) = x**2

Use the symbolic one to define g:

sage: g(y) = f(y) + 2*y
sage: g
y |--> 2*y + f(y)

When you need it, substitute:

sage: g.substitute_function(f, ff)
y^2 + 2*y
edit flag offensive delete link more

Comments

It does the trick, but it's a bit frustrating that there is not a more natural way to this. It is a very important feature when you are dealing with long expressions. But thank you very much anyway!

delta_omega gravatar imagedelta_omega ( 2020-07-30 11:52:59 +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: 2020-07-27 16:44:25 +0100

Seen: 232 times

Last updated: Jul 28 '20