13
$\begingroup$

Is there a way to loop through all the Functions (Elementary and Special functions) that exist in Mathematica?

I want to construct a table of some identities and maybe I can discover something surprising if I plug every function that there is into my formula.

I.e. I want to do something like:

for function in Mathematica
print function[x]^2

(Note this is not Mathematica syntax, but I hope you get the idea)

Thanks, Michał

$\endgroup$
  • $\begingroup$ But different functions accept different arguments also. How do you plan to handle this if you have list of all the functions? $\endgroup$ – Nasser May 10 at 4:37
  • 3
    $\begingroup$ @Nasser I didn't think about it. Anyway, where can I find such a list of all functions, please? $\endgroup$ – Michał Kuczynski May 10 at 4:41
  • 2
    $\begingroup$ Have you already seen MathematicalFunctionData[]? $\endgroup$ – J. M.'s technical difficulties May 10 at 4:48
  • $\begingroup$ Can you extract all the names from reference.wolfram.com/language/guide/AlphabeticalListing ? Was there a line of code that did this in Petzold's Mathematica Guidebook for Symbolics? $\endgroup$ – Bill May 10 at 4:49
  • 1
    $\begingroup$ Maybe combining it with FromEntity[] will work? $\endgroup$ – Michał Kuczynski May 10 at 4:54
13
$\begingroup$

Single-argument functions:

funclist = Select[("ArgumentsPattern" /. SyntaxInformation[#]) === {_} &][
  FromEntity /@ MathematicalFunctionData[]]; 

Grid[Prepend[Thread[{funclist, Through[funclist@2]}], 
     Item[#, Background -> LightBlue] & /@ {"f", "f @ 2"}], 
 Dividers -> All]

enter image description here

| improve this answer | |
$\endgroup$
  • 6
    $\begingroup$ This isn't kglr's fault, but note that the list misses functions like LogisticSigmoid[] and InverseHaversine[]. $\endgroup$ – J. M.'s technical difficulties May 10 at 7:02
9
$\begingroup$

I am sure there is a way to do this using MathematicalFunctionData, just to obtain list of functions. But I could not find it. I got lost in help pages of Entities , FromEntity[], ToEntity[], and so on.

Here is lazy person's way of doing it.

isFunction[name_String] := Module[{m},
   m = SyntaxInformation[Symbol[name]];
   If[Length[m] > 0, True, False]
   ];

n = 0;
pkg = "System`";
names = Names[pkg <> "*"];

tbl = First@Last@Reap@Do[

      Print["Proccesing entry ", k];

       If[isFunction[names[[k]]],
          n++;
          Sow[{n, pkg <> names[[k]]}]
       ]

      , {k, 1, Length[names]}
      ];

Which gives

{{1, "System`AASTriangle"}, 
 {2, "System`AbelianGroup"}, 
 {3, "System`Abort"}, 
 {4, "System`AbortKernels"}, 
 {5, "System`AbortProtect"}, 
 {6, "System`AbortScheduledTask"}, {7, 
 .....
 {2300, "System`ListLogLinearPlot"}, 
 {2301, "System`ListLogLogPlot"}, 
 {2302, "System`ListLogPlot"}, 
 {2303, "System`ListPicker"}, 
 {2304, "System`ListPickerBox"}, 
 {2305, "System`ListPlay"}, 
 {2306, "System`ListPlot"}, 
 {2307, "System`ListPlot3D"}, 
 {2308, "System`ListPointPlot3D"}, 
 {2309, "System`ListPolarPlot"}, 
 {2310, "System`ListQ"}, 
 {2311, "System`ListSliceContourPlot3D"}, 
 {2312, "System`ListSliceDensityPlot3D"}, 
 {2313, "System`ListSliceVectorPlot3D"}, 
 {2314, "System`ListStepPlot"}, 
 {2315, "System`ListStreamDensityPlot"}, 
 {2316, "System`ListStreamPlot"}, 
 .....
 {4431, "System`$DefaultFrontEnd"}, 
 {4432,  "System`$DisplayFunction"}, 
 {4433, "System`$FormatType"}, 
 {4434,  "System`$FrontEndSession"}, 
 {4435, "System`$SoundDisplayFunction"}}

If when running the above code, you get pop-up windows asking you to login to Wolfram Cloud, just close it. I got such screen many times. I have no idea why it is asking me to login to Wolfram cloud.

Do not worry that they are strings in this list. You could always convert string to Mathematica expression using ToExpression to use the functions.

| improve this answer | |
$\endgroup$
  • $\begingroup$ This is great, thank you! $\endgroup$ – Michał Kuczynski May 10 at 6:03
  • 5
    $\begingroup$ @MichałKuczynski you are welcome. But you should wait to accept, sometime better answer for your needs might come along. I think you might want to accept Kglr answer instead of mine as it gives you single argument functions which is what you wanted for your tests and it is better answer than mine also. Mine was a hack/workaround since I did not know how to use MathematicalFunctionData $\endgroup$ – Nasser May 10 at 6:21

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.