[Date Index]
[Thread Index]
[Author Index]
Re: list of Mma commands with specified properties
*To*: mathgroup at christensen.cybernetics.net
*Subject*: [mg707] Re: list of Mma commands with specified properties
*From*: wagner at bullwinkle.cs.Colorado.EDU (Dave Wagner)
*Date*: 10 Apr 1995 23:35:17 GMT
In article <3m4pfm$e47 at news0.cybernetics.net>,
Jack Goldberg <jackgold at math.lsa.umich.edu> wrote:
>
>Hi Group;
> A student asked me "Which Mma commands have the option
>of allowing Trig->False so that she could set Trig->True?"
> This question raises a more general issue which I pose to
>you in the form of two questions:
> (1) How does one ask for a list of commands which have a
> specified option such as Trig->False ?
>(I won't clutter cyberspace with my makeshift solution, since I'll
>bet there is a "professional" way to do it.)
> (2) Same question for attributes, say for instance, Listable?
Hi Jack,
The answer to the second question is easier than the first.
The reason is that Attributes can take a string as an argument,
whereas Options cannot.
First of all, it's easy to find the names of all symbols defined by
the system:
In[1]:=
n = Names["System`*"];
Short[n, 2]
Out[2]//Short=
{Abort, $Aborted, AbortProtect, Above, Abs,
AbsoluteDashing, <<1109>>, Xor, ZeroTest, Zeta}
Although these look like symbols, they're actually strings (the
quotes don't print in normal OutputForm).
Now since Attributes can take a string as an argument, finding
all Listable functions is quite easy:
In[3]:=
Select[Names["System`*"], MemberQ[Attributes[#], Listable]&];
Short[%, 5]
Out[4]//Short=
{Abs, AiryAi, AiryAiPrime, AiryBi, AiryBiPrime,
ArcCos, ArcCosh, ArcCot, ArcCoth, ArcCsc, ArcCsch,
ArcSec, ArcSech, ArcSin, ArcSinh, <<118>>, Tan,
Tanh, Times, ToExpression, Together,
ToHeldExpression, Zeta}
Note, however, that Options cannot take a string argument.
This is an inconsistency that I wish WRI would address:
In[5]:=
Options["Limit"]
Out[5]=
{Null}
In[6]:=
Options[Limit]
Out[6]=
{Analytic -> False, Direction -> Automatic}
The following contortions are based on material in Ch. 10 of
Maeder's second book, "The Mathematica Programmer":
In[7]:=
hn = ToHeldExpression /@ n;
Short[%, 2]
Out[8]//Short=
{Hold[Abort], Hold[$Aborted], Hold[AbortProtect],
<<1113>>, Hold[ZeroTest], Hold[Zeta]}
(The things in the list are now real live symbols, not just strings.)
Define a new kind of list that holds its arguments.
Apply it to the list of held symbols.
In[9]:=
Attributes[HeldList] = HoldAll;
hn = HeldList @@ hn;
Short[hn, 2]
Out[11]//Short=
HeldList[Hold[Abort], Hold[$Aborted],
Hold[AbortProtect], <<1114>>, Hold[Zeta]]
Now that the entire list is held, we can remove the individual
Hold[] from each symbol:
In[12]:=
hn = hn /. Hold[x_] :> x;
Short[hn, 2]
Out[13]//Short=
HeldList[Abort, $Aborted, AbortProtect, Above, Abs,
<<1110>>, Xor, ZeroTest, Zeta]
Define a function that tests for your criterion, in this case,
does the symbol have the Trig option? Note that the function
holds its argument but Options does not, hence the Unevaluated
wrapper around the argument to Options.
In[14]:=
SetAttributes[hasTrig, HoldFirst]
hasTrig[x_] :=
MemberQ[First /@ Options[Unevaluated[x]], Trig]
In[16]:=
hasTrig[Simplify]
Out[16]=
True
Now Select from the HeldList in the usual way. It makes no difference
that the head of the expression is HeldList rather than List.
In[18]:=
Select[hn, hasTrig]
Out[18]=
HeldList[Apart, ApartSquareFree, Cancel, Coefficient,
CoefficientList, Collect, Denominator, Expand,
ExpandAll, ExpandDenominator, ExpandNumerator,
Exponent, Factor, FactorList, FactorSquareFree,
FactorSquareFreeList, FactorTerms, FactorTermsList,
Numerator, PolynomialGCD, PolynomialLCM,
PolynomialMod, PolynomialQ, Resultant, Simplify,
Together, Variables]
>
>Another student asked this question (actually it was me):
> (3) Is there a way of forcing the front end to produce
> output in MatrixForm in a given Mma session rather than
> a list of lists (of equal length) as it does now?
>This is of value when one knows in advanced that a particular
>session will be dealing entirely with matrices.
>Jack
>
Dunno.
Dave Wagner
Principia Consulting
princon at csn.net
http://www.csn.net/princon
Prev by Date:
**Calling functions before loading the package**
Next by Date:
**Constructing expressions**
Previous by thread:
**Re: list of Mma commands with specified properties**
Next by thread:
**Re: list of Mma commands with specified properties**
| |