Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1995
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1995

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

Search the Archive

Re: Adding options to built-in functions

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg793] Re: [mg697] Adding options to built-in functions
  • From: Allan Hayes <hay at haystack.demon.co.uk>
  • Date: Sat, 15 Apr 95 15:25:26 GMT

Jack Goldberg wrote, ([mg697] Adding options to built-in functions)

>I would like to add an option to PowerExpand
>called InverseTrig->False.  This option, when evoked
>would  reduce
>	ArcTan[Tan[x]]  to  x
>and similarly for the other inverse trigs composed
>with the trigs.
>What is the preferred way to introduce your
>own option to a built in command?  Indeed,
>is it even possible? and if possible, desirable?

Here is one way of dealing with PowerExpand

In[1]:=
	Unprotect[PowerExpand];
	
	Options[PowerExpand] =  {LocalInverse ->False};

	pe[g_[f_[x_]]]/;Expand[g-InverseFunction[f]]===0:= x;
	pe[expr_] := PowerExpand[expr];

	PowerExpand[expr_, LocalInverse -> True]:=
		MapAll[pe, expr, Heads->True];
		(*PowerExpand behaves like this*)
	PowerExpand[expr_, LocalInverse -> False]:=
		PowerExpand[expr];
	
	Protect[PowerExpand];
	
Tests

In[9]:=
	PowerExpand[{{ArcSin[Sin[x]]}}[Log[Sqrt[x^2]]]]
Out[9]=
	{{ArcSin[Sin[x]]}}[Log[x]]
In[10]:=
	PowerExpand[{{ArcSin[Sin[x]]}}[Log[Sqrt[x^2]]],
		LocalInverse -> True
	]
Out[10]=
	{{x}}[Log[x]]
	
A general approach might be something like

	Unprotect[foo]
	foo[x___, opts__?OptionQ]/;
		MemberQ[
		   First/@Flatten[{opts}],
		   Alternatives@@(First/@Flatten[{newoptions})]
		] :=
	ExtraDefinitions

	Protect[foo]
	
But, as with PowerExpand, there may be particular feature that can  
help or that have to be taken into account (no existing options,  
MapAll behaviour).

Since the new behaviour has to be triggered by the new option I  
guess that it is fairly safe -- but someone might just use  
Options[foo] in their coding.

Allan Hayes
hay at haystack.demon.co.uk




  • Prev by Date: Re:Re: re: automatic MatrixForm
  • Next by Date: CHAOS & MATH
  • Previous by thread: Adding options to built-in functions
  • Next by thread: Accuracy and Precision