Ask Your Question
1

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

asked 4 years ago

delta_omega gravatar image

updated 4 years ago

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?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 4 years ago

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
Preview: (hide)
link

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 ( 4 years ago )

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: 4 years ago

Seen: 249 times

Last updated: Jul 28 '20