First time here? Check out the FAQ!

Ask Your Question
2

Displaying tan instead of sin / cos

asked 2 years ago

mn124700 gravatar image

updated 2 years ago

slelievre gravatar image

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

Preview: (hide)

Comments

Welcome to Ask Sage! Thank you for your question.

slelievre gravatar imageslelievre ( 2 years ago )

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.

slelievre gravatar imageslelievre ( 2 years ago )

2 Answers

Sort by » oldest newest most voted
2

answered 2 years ago

Emmanuel Charpentier gravatar image

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,

Preview: (hide)
link

Comments

Awesome! Thank you

mn124700 gravatar imagemn124700 ( 2 years ago )
1

answered 2 years ago

slelievre gravatar image

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

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2 years ago

Seen: 371 times

Last updated: Jun 21 '22