Ask Your Question

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

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 close merge delete

## 1 answer

Sort by ยป oldest newest most voted

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

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!

( 2020-07-30 04:52:59 -0600 )edit

## Your Answer

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

Add Answer

## Stats

Asked: 2020-07-27 09:44:25 -0600

Seen: 63 times

Last updated: Jul 28 '20