Ask Your Question
2

Displaying tan instead of sin / cos

asked 2022-06-20 18:09:18 +0100

mn124700 gravatar image

updated 2022-06-20 18:36:47 +0100

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

edit retag flag offensive close merge delete

Comments

Welcome to Ask Sage! Thank you for your question.

slelievre gravatar imageslelievre ( 2022-06-20 18:37:00 +0100 )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.

slelievre gravatar imageslelievre ( 2022-06-20 18:38:04 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2022-06-20 21:40:12 +0100

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,

edit flag offensive delete link more

Comments

Awesome! Thank you

mn124700 gravatar imagemn124700 ( 2022-06-21 00:55:20 +0100 )edit
1

answered 2022-06-20 18:42:45 +0100

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)
edit flag offensive delete link more

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: 2022-06-20 18:09:18 +0100

Seen: 337 times

Last updated: Jun 21 '22