ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 21 Jun 2022 00:55:20 +0200Displaying tan instead of sin / coshttps://ask.sagemath.org/question/62899/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, EricMon, 20 Jun 2022 18:09:18 +0200https://ask.sagemath.org/question/62899/displaying-tan-instead-of-sin-cos/Comment by slelievre for <p>Newbie question. How do I get SageMath to use tan in its result instead of the ratio and sin and cos?</p>
<p>Example:</p>
<pre><code>sage: a = sin(x^2 + x + 1) / cos(x^2 + x + 1)
sage: a
sin(x^2 + x + 1)/cos(x^2 + x + 1)
</code></pre>
<p>I would hope to see instead:</p>
<pre><code>tan(x^2 + x + 1)
</code></pre>
<p>Thanks, Eric</p>
https://ask.sagemath.org/question/62899/displaying-tan-instead-of-sin-cos/?comment=62905#post-id-62905I 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.Mon, 20 Jun 2022 18:38:04 +0200https://ask.sagemath.org/question/62899/displaying-tan-instead-of-sin-cos/?comment=62905#post-id-62905Comment by slelievre for <p>Newbie question. How do I get SageMath to use tan in its result instead of the ratio and sin and cos?</p>
<p>Example:</p>
<pre><code>sage: a = sin(x^2 + x + 1) / cos(x^2 + x + 1)
sage: a
sin(x^2 + x + 1)/cos(x^2 + x + 1)
</code></pre>
<p>I would hope to see instead:</p>
<pre><code>tan(x^2 + x + 1)
</code></pre>
<p>Thanks, Eric</p>
https://ask.sagemath.org/question/62899/displaying-tan-instead-of-sin-cos/?comment=62904#post-id-62904Welcome to Ask Sage! Thank you for your question.Mon, 20 Jun 2022 18:37:00 +0200https://ask.sagemath.org/question/62899/displaying-tan-instead-of-sin-cos/?comment=62904#post-id-62904Answer by Emmanuel Charpentier for <p>Newbie question. How do I get SageMath to use tan in its result instead of the ratio and sin and cos?</p>
<p>Example:</p>
<pre><code>sage: a = sin(x^2 + x + 1) / cos(x^2 + x + 1)
sage: a
sin(x^2 + x + 1)/cos(x^2 + x + 1)
</code></pre>
<p>I would hope to see instead:</p>
<pre><code>tan(x^2 + x + 1)
</code></pre>
<p>Thanks, Eric</p>
https://ask.sagemath.org/question/62899/displaying-tan-instead-of-sin-cos/?answer=62908#post-id-62908`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,
Mon, 20 Jun 2022 21:40:12 +0200https://ask.sagemath.org/question/62899/displaying-tan-instead-of-sin-cos/?answer=62908#post-id-62908Comment by mn124700 for <p><code>slelievre</code>'s answer is general, and should be kept in mind ; in this specific case, <code>SR</code> has a specific suitable method :</p>
<pre><code>sage: a.trig_reduce()
tan(x^2 + x + 1)
</code></pre>
<p>HTH,</p>
https://ask.sagemath.org/question/62899/displaying-tan-instead-of-sin-cos/?comment=62911#post-id-62911Awesome! Thank youTue, 21 Jun 2022 00:55:20 +0200https://ask.sagemath.org/question/62899/displaying-tan-instead-of-sin-cos/?comment=62911#post-id-62911Answer by slelievre for <p>Newbie question. How do I get SageMath to use tan in its result instead of the ratio and sin and cos?</p>
<p>Example:</p>
<pre><code>sage: a = sin(x^2 + x + 1) / cos(x^2 + x + 1)
sage: a
sin(x^2 + x + 1)/cos(x^2 + x + 1)
</code></pre>
<p>I would hope to see instead:</p>
<pre><code>tan(x^2 + x + 1)
</code></pre>
<p>Thanks, Eric</p>
https://ask.sagemath.org/question/62899/displaying-tan-instead-of-sin-cos/?answer=62906#post-id-62906Sage'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)
Mon, 20 Jun 2022 18:42:45 +0200https://ask.sagemath.org/question/62899/displaying-tan-instead-of-sin-cos/?answer=62906#post-id-62906