Scientific Arts LLC MATHEMATICA Tools
Please support these tools with a donation...
Tool Posts
5/15, 2009; 11:04 PM:
Wolfram|Alpha Lookup Tool
4/7, 2009; 8:48 AM:
The Joy of Tagging
4/7, 2009; 8:43 AM:
Mathematica 6 Review
4/7, 2009; 8:38 AM:
Documentation Center Notes
3/23, 2009; 11:59 AM:
FunctionsWithOption
3/18, 2009; 10:16 PM:
Notebook State Saver
3/18, 2009; 9:59 PM:
A WorkLife FrameWork

Links
Scientific Arts

Each post on this site describes a Mathematica tool available from Scientific Arts. Many are free.

 

FunctionsWithOption

Posted on: Monday, March 23, 2009 at 03:59 PM UT

Here is the documentation for the FunctionsWithOption notebook.  Click on the following link to down load it (for some browsers you will have to right click and choose "save as...";  also if your system appends a .txt or other string to the end of the file name, you will have to change it to .nb).

Download the FunctionsWithOption Notebook >>

The full text of the documentation that follows is contained in the FunctionsWithOption Notebook itself.

Purpose

FunctionsWithOption is a simple tool that allows you to find functions that have a particular option.  In a way it is an inverse of Mathematica's Options function.  Whereas the function Options will give you a list of all of the options for a particular function, e.g.:

BE3446812762_1.gif

BE3446812762_2.gif

FunctionsWithOption will give you all the functions that have a particular option

BE3446812762_3.gif

BE3446812762_4.gif

The form of this output is a list of pairs.  The first item in each pair is the function

Various forms of use: Single argument form

Single argument form

FunctionsWithOption takes on several different argument sets.  The first is the simplest.  This is a single argument with the option that you are interested in as in the preceding example.  Here is another example:

BE3446812762_5.gif

BE3446812762_6.gif

Note that, in this form, FunctionsWithOption looks for all of those functions that have the queried option in the Context of that option.  It will not return any results for other Contexts that have functions that use that option.   So, in the above example FunctionsWithOption is looking for all of the functions that have the TaggingRules option in the System` Context because

BE3446812762_7.gif

BE3446812762_8.gif

Care with the Global` Context

Note also that if  the single argument form FunctionsWithOption is called with a symbol from a Context that hasn't yet been loaded, then that symbol will be placed in the Global` Context.  This may not be quite what you want.  There is an option to FunctionsWithOption, DeleteGlobalVersion, which if set as DeleteGlobalVersion→True (the default setting), causes any symbol that is introduced into the Global` Context through the execution of FunctionsWithOption, to be removed.

Here is an example.

First make sure that there is no current symbol called testSymbol

BE3446812762_9.gif

BE3446812762_10.gif

BE3446812762_11.gif

Now execute FunctionsWithOption with DeleteGlobalVersion→True:

BE3446812762_12.gif

BE3446812762_13.gif

The symbol still is not in the Global` context:

BE3446812762_14.gif

BE3446812762_15.gif

It we had executed this with DeleteGlobalVersion→True then testSymbol would remain in the Global` Context after execution:

BE3446812762_16.gif

BE3446812762_17.gif

BE3446812762_18.gif

BE3446812762_19.gif

To clean things up for this example Remove testSymbol:

BE3446812762_20.gif

Two argument forms

There are several two argument forms for FunctionsWithOption.  In all cases the first argument is the symbol that you are querying.

Symbol and Context

For this case the second argument is the Context that you are looking in.  If that Context has not yet been loaded then FunctionsWithOption will load it before looking for the functions in that context that have the queried option.  Only those functions in the Context that have the symbol as an option will be returned: all other contexts will be ignored.   Here is an example for the Combinatorica package. Combinatorica is not loaded by default when Mathematica is first started, but this command will load it.  In this example we are using the option Grid→True to show a formatted output:

BE3446812762_21.gif

BE3446812762_22.gif

Even though the symbol Method is defined in the System` context, it is used in some Combinatorica functions:

BE3446812762_23.gif

BE3446812762_24.gif

Symbol and a list of Contexts

The second argument of FunctionsWithOption can also be a list of Contexts.  In this case FunctionsWithOption returns all of the functions from each of the contexts that have the option.

Here are the functions in the System` Context that have the option Initialization:

BE3446812762_25.gif

BE3446812762_26.gif

Here are the functions in the Combinatorica` Context that have the option Initialization:

BE3446812762_27.gif

BE3446812762_28.gif

And here are the functions in both the System` and Combinatorica` context that have the Initialization option:

BE3446812762_29.gif

BE3446812762_30.gif

A warning:

You might be tempted to execute something like (the following cell is not an executable cell so that you do not accidentally execute it):

FunctionsWithOption[Initialization, Contexts[]]

Note however that this may cause Mathematica to attempt to initialize many of its data paclets which, in addition to possibly taking a very long time, may also cause a large amount of data to be written to your disk.

Symbol and a symbol

The final form is where the second argument for FunctionsWithOption is a symbol.  In this case all of the functions from the context of the second argument are returned that have the first argument as an Option.

AnimateGraph is a function in the Combinatorica package:

BE3446812762_31.gif

AnimateGraph Initialization:→None

Plot is a function in the System` Context:

BE3446812762_32.gif

BE3446812762_33.gif

Note that if the Context of the symbol in second argument has not been loaded when FunctionsWithOption is executed then that symbol will be placed in the Global` Context.  In this case you are not likely to get the results you were expecting.

Symbol and a list of symbols

As in case of explicitly supplying a list of contexts, the second argument for FunctionsWithOption can take a list of symbols.  In this case all of the functions from the set of Contexts for theses symbols that have the option are returned.  Here Plot is in the System` context and NecklacePolynomial is in the Combinatorica` context:

BE3446812762_34.gif

BE3446812762_35.gif

Options

FunctionsWithOption takes several options:

BE3446812762_36.gif

BE3446812762_37.gif

The option Grid determines whether the result form FunctionsWithOption is returned in a formatted grid.  We showed several examples of this above.  

Here are the usage messages for the options LoadContext, ExcluedGlobalContext, and DeleteGlobal:

BE3446812762_38.gif

BE3446812762_39.gif

BE3446812762_40.gif

BE3446812762_41.gif

BE3446812762_42.gif

BE3446812762_43.gif

The remaining explicit options to FunctionsWithOptionFrame and Alignment—are used when Grid→True to format the gridded output. But FunctionsWithOption can also take on any other of the options to Grid as in the following:

BE3446812762_44.gif

BE3446812762_45.gif

Permalink | Comments | Add Comment...

 
 
  *Scientific Arts, LLC is not affiliated with Wolfram Research Inc.; MATHEMATICA® a is a registered trademark of Wolfram Research, Inc.  

All material on this website Copyright © 2005-2009, Scientific Arts, LLC.