3
$\begingroup$

I have read in my lecture notes on Mathematica that functions (in the general sense) can be applied to lists of data and that they can return new lists with data. I have tried this and I have got these results, see following picture:

enter image description here

As you can see, in this picture the function Sin[x] works fine on the lists but the functions Eigenvalues and Characteristic polynomials they do not...

Do I miss something here or am I wrong at all?

Thanks.

$\endgroup$
  • 4
    $\begingroup$ I suggest you read reference.wolfram.com/language/tutorial/Attributes.html $\endgroup$ – Bill Nov 1 at 3:24
  • 3
    $\begingroup$ Some functions are Listable (which is what Bill was referring to, a bit vague....), which mean they automatically thread over lists. But not all functions have this attribute. $\endgroup$ – user6014 Nov 1 at 3:30
  • 1
    $\begingroup$ Also keep in mind that some functions automatically map themselves over lists, yet do not have a Listable attribute. StringSplit (and many other string functions) is a good example of this. Usually these are functions with multiple arguments where the automatic mapping is only done with the first argument. $\endgroup$ – Sjoerd Smit Nov 2 at 12:57
6
$\begingroup$

The problem with using Names and Attributes is that sometimes the symbol doesn't acquire the attribute until it is used. For instance:

listable =  Select[Names["System`*"], MemberQ[Attributes[#], Listable] &];
MemberQ[listable, "FresnelC"]

False

Use FresnelC:

FresnelC[{1, 2, 3}]

{FresnelC[1], FresnelC[2], FresnelC[3]}

Now, check the attributes:

Attributes["FresnelC"]

{Listable, NumericFunction, Protected, ReadProtected}

If we run the above code again:

listable =  Select[Names["System`*"], MemberQ[Attributes[#], Listable] &];
MemberQ[listable, "FresnelC"]

True

So, if you really want a list of all listable functions using Names and Attributes, you need to evaluate the symbol and then check the attributes. However, then you will be performing an autoload for every system symbol, which will take a while and bloat your memory. So, instead, I recommend you use EntityValue:

EntityValue[
    EntityClass["WolframLanguageSymbol", "Attributes"->ContainsAny[{"Listable"}]],
    "Name"
] //Short

{"Abs","AbsArg","AiryAi","AiryAiPrime","AiryAiZero","AiryBi",<<434>>,"WhittakerW","WordStem","ZernikeR","Zeta","ZetaZero"}

$\endgroup$
  • $\begingroup$ Thank you @Carl. (I was wondering why the list is shorter in v12.0 than in v9.9) $\endgroup$ – kglr Nov 2 at 0:15
5
$\begingroup$

The list of functions with the Attributes Listable in the System context

listable =  Select[Names["System`*"], MemberQ[Attributes[#], Listable] &];

Length @ listable (* Version 12.0.0 *)

340

Short[listable, 10]

{Abs, AbsArg, AiryAi, AiryAiPrime, AiryAiZero, AiryBi, AiryBiPrime, AiryBiZero, AlgebraicIntegerQ, AlgebraicNumberDenominator, AlgebraicNumberNorm, AlgebraicNumberTrace, AlgebraicUnitQ, AngerJ, Apart, ArcCos, ArcCosh, ArcCot, ArcCoth, ArcCsc, ArcCsch, ArcSec,
<< 300 >>,
Times, ToExpression, Together, ToHeldExpression, ToLowerCase, ToUpperCase, TrigFactor, TrigToExp, TukeyWindow, UnitBox, UnitDimensions, Unitize, UnitSimplify, UnitStep, UnitTriangle, VertexWeightedGraphQ, WeberE, WelchWindow, WhittakerM, WhittakerW, Zeta, ZetaZero}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.