MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to NOT convert Sin[x]/Cos[x] to Tan[x] ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg44828] Re: How to NOT convert Sin[x]/Cos[x] to Tan[x] ?
  • From: poujadej at yahoo.fr (Jean-Claude Poujade)
  • Date: Wed, 3 Dec 2003 04:24:09 -0500 (EST)
  • References: <bq5b08$k05$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

AES/newspost <siegman at stanford.edu> wrote in message news:<bq5b08$k05$1 at smc.vnet.net>...
> The Mathematica Book says "Mathematica automatically uses functions like 
> Tan whenever it can" and shows as an example that Sin[x]^2/Cos[x] is 
> converted to  Sin[x] Tan[x] .
> 
> Any simple way to stop this in displaying the output of a symbolic 
> calculation?  
> 
> The obvious attempt of applying /.Tan[x]->Sin[x]/Cos[x] doesn't seem to 
> do what's wanted.
> 
> [And out of curiousity, WHY does it do this?  That is, why is Tan 
> apparently given a higher priority than Cos?]

A [not very simple!] way to do what you want :

In[1]:=rep = {Tan -> (sin[#]/cos[#]&), Cos -> cos, Sin -> sin,
      Times[Power[cos[x_],-1],sin[x_]] -> tan[x]};

a test :
In[2]:=Sin[x]^2/Cos[x] /. rep  
Out[2]=sin[x]^2/cos[x]

another test :
In[3]:=(Tan[x]+Sin[x]+Cos[x]+Sin[x]^2/Cos[x])Sin[x]^2/Cos[x] /. rep  

Out[3]=\!\(\(sin[x]\^2\ \((cos[x] + sin[x] + sin[x]\/cos[x] +
sin[x]\^2\/cos[x])\)\)\
\/cos[x]\)

it's better with ReplaceRepeated :

In[4]:=(Tan[x]+Sin[x]+Cos[x]+Sin[x]^2/Cos[x])Sin[x]^2/Cos[x] //. rep  

Out[4]=\!\(\(sin[x]\^2\ \((cos[x] + sin[x] + sin[x]\^2\/cos[x] +
tan[x])\)\)\/cos[x]\
\)

In case you don't want lower case, turn ouput cell into input cell 
and restore uppercase : 

\!\(\(Sin[x]\^2\ \((Cos[x] + Sin[x] + Sin[x]\^2\/Cos[x] +
Tan[x])\)\)\/Cos[x]\
\)

Et voila!
(I hope there is a better way to do this)
---
jcp


  • Prev by Date: RE: Namespaces/Context in Packages?
  • Next by Date: Re: Operator that Adds Arguments
  • Previous by thread: Re: Re: How to NOT convert Sin[x]/Cos[x] to Tan[x] ?
  • Next by thread: Re: NIntegrate