[Date Index]
[Thread Index]
[Author Index]
Programming Options for Power Expand
*To*: mathgroup at christensen.cybernetics.net
*Subject*: [mg802] Programming Options for Power Expand
*From*: Jack Goldberg <jackgold at math.lsa.umich.edu>
*Date*: Fri, 21 Apr 1995 01:41:22 -0400
I have received a number (1) of requests for my solution
to my own problem: Enhance PowerExpand so that among
other things it simplifies ArcTan[Tan[x]] = x. The
real question is more general: Should (and can!) one
add options to a built in command? I do not know the
answer to whether one should. I am interested in knowing
what is good Mma programming practice in this regard.
Is what I present next poor programming practice? Why?
(I am most interested in the style, less in how to improve
my code.)
Step(1):
Define rules. I list a few:
In[1]: ArcRules = {
ArcTan[ Tan[x_] ] :> x,
ArcTan[ Cot[x_] ] :> Pi/2 - x,
....
ArcCsc[ Sec[x_] ] :> Pi/2 - z}:
The .... refers to all those combinations ArcYyy[ [Yyy[x_] ] :> x
which I left out to save space.
Step(2)
In[2}: ArcRules = Dispatch[ArcRules];
( *Don't ask me to justify this step. I just lifted it out of
Roman Maeder's package "Algebra`Trigonometry`". *)
Step (3)
In[3]: Unprotect[PowerExpand];
In[4]: PowerExpand[expr_,InverseTrig->True] :=
Module[ {fnt},
fnt = Simplify[ PowerExpand[#//.ArcRules] ]&;
FixedPoint[ fnt,expr ]
]
In[5]: Protect[PowerExpand];
Some trial examples:
ex1 = 1 + Log[ArcTan[Tan[Exp[x]]]];
ex2 = 1 + ArcTan[Log[Exp[Tan[x]]]];
ex3 = ArcSin[Sqrt[1-Cos[x]^2]];
PowerExpand without the "option" leave these expressions unaltered.
PowerExpand[ex1,InverseTrig->True] simplifies to 1+x. The others
work similarly.
I think that I have cheated here. InverseTrig->True acts like
an option but it strikes me that it is in fact a second argument
to PowerExpand. But perhaps that's all options are anyway.
Any discussion on the matters raised by this post are appreciated.
I learn even from those I disagree with!
Thanks all.
Jack
P.S. I hope I made it clear that other rules such as
ArcTanh[ Tanh[x_] ] :> x can be added to the list in
ArcRules at your whim.
Prev by Date:
**A Mathematica Puzzle Involving Computation of Expected Utilities**
Next by Date:
**Mathlink Question**
Previous by thread:
**Re: A Mathematica Puzzle Involving Computation of Expected Utilities**
Next by thread:
**Re: Programming Options for Power Expand**
| |