Message Boards Message Boards


Finding Functions / Better Documentation Search

Posted 9 months ago
0 Replies
4 Total Likes

This is another cross-post of something I did first here

As someone who has used Mathematica for a reasonably long time now, one thing I often forget is how hard it can be to find the functions for a given task when you're just starting out.

Mathematica has a nice Documentation Center , but finding stuff in it often turns into a long slog of randomly clicking through links. The documentation search is okay, but it's generally cluttered with links and cruft and not clever enough on the fuzzy-matching that people usually want.

So we're going to develop and alternative for finding the right function for the job. I'll build up to this and provide a package implementation at the end.

Names and Wildcards

The heart of this approach will be the function Names . This takes a string pattern and returns all the symbols matching that pattern. If you remember nothing else from this, keep in mind that Names is your best friend when working with Mathematica. It allows us to use string pattern-matching syntax to find functions. That lets us use wildcards and other things. For example, to find all the "*View" functions we could do:




And then we can look at the docs for each of these


With these in hand, we can turn to their doc pages. Now, we could obviously select the string and press Command-F for each, but we can do this more automatically, using the function Documentation`HelpLookup . For instance, if we wanted to find the doc page for a function that we know has "Log" and the name and ends in "Plot" , we could just do:





Most of the time, though, the documentation page isn't enough. It's a template for how to use a function, but doesn't give us the whole story. Better is to be able to spelunk a symbol . This is actually built-in as of 10.1 and the function is GeneralUtilities`PrintDefinitionsLocal (there's also a version that opens a new notebook but that one's generally clumsier in my view).

Now we can do stuff like look at functions that help us define layers in NNs:

LinearLayer; (* This autoloads the NN context *)



Putting it All Together

Now we can combine these parts to write a function that will take a string pattern, provide links to the documentation via Documentation`HelpLookup , and also wrap in the GeneralUtilities`PrintDefinitionsLocal data at the bottom of the page. I've written this into a package here.

You can load the package like this:


And then we can go-to-town. First let's find all the functions in the "NeuralNetworks`" context:

DocFind["*", "NeuralNetworks`", Select->"Function"]



Clicking on any of these links will attempt to open the doc page and will stick the PrintDefinitionsLocal data at the bottom:



This makes finding the functions we need so much nicer.

Alternately we can just search for any function with the name "DocFind" in the $Packages :




This is how I generally use the function. And with sophisticated pattern matching we can find functions that we know should exist but we just don't have the names for. Say a constant somewhere in the "PacletManager`" context that has "Dir" in its name:

DocFind["Dir", "PacletManager*", Select->"Constant"]



And now figuring out how the "PacletManager`" works is as simple as doing a few DocFinds and clicking a few links.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract