Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Converting sin(x)^n to sin^n(x)

Hello all!

I am trying to figure out how to change the sage output when it has certain trig functions to a power. For example, if I do the following;

f(x) = sin(x)
g(x) = f(x)^5

I get out

g(x) = sin(x)^5

This can be a bit ambiguous, as someone not paying attention might read that as sin(x^5). Instead I would like to make it output;

g(x) = sin^5(x)

I have tried using wildcards as was suggested to me in another post here: But it doesn't seem to like that (probably because it thinks I'm interrupting a math call function and it's getting syntax errors, which I expected when I tried it originally).

Is there any nice way of reformatting the output? I suspect wildcards would probably be capable if I were more adept at them? I would like it specifically for the basic trig functions. I don't mind if I need to write a "simplify" function to run on an expression to convert it (even if it converts everything to a string), but I can't seem to get anything to work correctly.