MathGroup Archive 1995

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

Search the Archive

Re: list of Mma commands with specified properties

  • To: mathgroup at
  • 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>,
Jack Goldberg  <jackgold at> 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:

    n = Names["System`*"];
    Short[n, 2]

    {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:

    Select[Names["System`*"], MemberQ[Attributes[#], Listable]&];
    Short[%, 5]

    {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:




    {Analytic -> False, Direction -> Automatic}

The following contortions are based on material in Ch. 10 of
Maeder's second book, "The Mathematica Programmer":

    hn = ToHeldExpression /@ n;
    Short[%, 2]

    {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.

    Attributes[HeldList] = HoldAll;
    hn = HeldList @@ hn;
    Short[hn, 2]

    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:

    hn = hn /. Hold[x_] :> x;
    Short[hn, 2]

    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.

    SetAttributes[hasTrig, HoldFirst]
    hasTrig[x_] :=
	    MemberQ[First /@ Options[Unevaluated[x]], Trig]



Now Select from the HeldList in the usual way.  It makes no difference
that the head of the expression is HeldList rather than List.

    Select[hn, hasTrig]

    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.


		Dave Wagner
		Principia Consulting
		princon at

  • 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