# Displaying tan instead of sin / cos

Newbie question. How do I get SageMath to use tan in its result instead of the ratio and sin and cos?

Example:

sage: a = sin(x^2 + x + 1) / cos(x^2 + x + 1)
sage: a
sin(x^2 + x + 1)/cos(x^2 + x + 1)

I would hope to see instead:

tan(x^2 + x + 1)

Thanks, Eric

edit retag close merge delete

Welcome to Ask Sage! Thank you for your question.

( 2022-06-20 18:37:00 +0200 )edit

I added an example in text mode, which is preferrable to an image.

Indeed, it can be copied and pasted, making it easier to explore the issue.

( 2022-06-20 18:38:04 +0200 )edit

Sort by ยป oldest newest most voted

slelievre's answer is general, and should be kept in mind ; in this specific case, SR has a specific suitable method :

sage: a.trig_reduce()
tan(x^2 + x + 1)

HTH,

more

Awesome! Thank you

( 2022-06-21 00:55:20 +0200 )edit

Sage's symbolic ring has "wildcards" for advanced substitutions.

For example, starting from the expression in the question:

sage: w0 = SR.wild(0)
sage: a.subs({sin(w0)/cos(w0): tan(w0)})
tan(x^2 + x + 1)
more