# Wolfram Function Repository

Instant-use add-on functions for the Wolfram Language

Function Repository Resource:

Get one or more random functions of a single complex variable

Contributed by:
Paco Jain

ResourceFunction["SampleUnivariateFunctions"][] returns a random univariate function in terms of the complex variable | |

ResourceFunction["SampleUnivariateFunctions"][ returns a sample of | |

ResourceFunction["SampleUnivariateFunctions"][All] returns all available functions. |

By default, ResourceFunction["SampleUnivariateFunctions"] returns expressions written in terms of the independent variable z (FormalZ) and zero or more other formal symbols representing unspecified parameters. Domains in z are presumed to be the entire complex plane, but extra parameters may have additional restrictions. It is up to the user to pick suitable values for these extra parameters.

ResourceFunction["SampleUnivariateFunctions"] takes the following options:

"IncludedSubexpressions" | {} | all of the supplied forms must appear as subexpressions of returned functions |

"ExcludedSubexpressions" | {} | none of the supplied forms may appear as subexpressions of returned functions |

"OutputForm" | Automatic | choose the syntactic form in which to return the functions |

"TrueUnivariate" | Automatic | whether to return only functions free of extra symbolic parameters |

Possible values for "OutputForm" are Automatic, "Held", "PureFunction" and "NestedFunction" (see Examples).

Get some arbitrary sample functions:

In[1]:= |

Out[1]= |

In[2]:= |

Out[2]= |

In[3]:= |

Out[3]= |

In[4]:= |

Out[4]= |

Get a random sample of five univariate functions:

In[5]:= |

Out[5]= |

To get all available functions, use the argument All:

In[6]:= |

Out[7]= |

Besides the independent variable *z*, functions may contain unspecified parameters represented by formal symbols: (here, *a*, *b*, *c*, *d* and *e*):

In[8]:= |

Out[8]= |

Formal symbols reside in the "System`" context:

In[9]:= |

Out[9]= |

They are protected and cannot be assigned values:

In[10]:= |

Out[10]= |

Instead, use pattern replacement to give values to such symbols:

In[11]:= |

Out[11]= |

Get a single function containing BesselJ as a subexpression:

In[12]:= |

Out[12]= |

Get all sample functions containing BesselJ as a subexpression and count the number available:

In[13]:= |

Out[14]= |

View a subset of five of these functions:

In[15]:= |

Out[15]= |

Every pattern listed in the value for "IncludedSubexpressions" must be separately included in the result. As such, additional forms in the list value of "IncludedSubexpressions" always reduce (or leave unchanged) the numbers of results:

In[16]:= |

Out[17]= |

In[18]:= |

Out[19]= |

The second sample is a subset of the first:

In[20]:= |

Out[20]= |

To form a more inclusive pattern, allowing *either* BesselJ *or* BesselK, instead use Alternatives:

In[21]:= |

Out[22]= |

Get all sample functions containing BesselJ, but excluding Hypergeometric0F1Regularized and Sum:

In[23]:= |

Get a count of the number of such functions:

In[24]:= |

Out[24]= |

Results can be returned in one of several forms, as determined by the "OutputForm" option. The setting "OutputForm"→Automatic (the default) returns bare expressions, written in terms of formal symbols:

In[25]:= |

Out[26]= |

For ease in substituting user-supplied parameter/variable values, the setting "OutputType"→"PureFunction" can be useful (note that the independent variable, z, always appears as the first argument of the returned Function expressions):

In[27]:= |

Out[28]= |

On supplying values, Function ignores extra parameters, using only the number needed to fill its slots:

In[29]:= |

Out[29]= |

The setting "OutputType"→"NestedFunction" separates the independent variable (z) from other parameters using separate Function wrappers:

In[30]:= |

Out[31]= |

The setting "OutputForm"→ "Held" causes results to be returned wrapped in Hold:

In[32]:= |

Out[33]= |

The setting "OutputForm"→"PureFunction" can be preferable for certain calculations (e.g., using Derivative, Plot, …):

In[34]:= |

Out[34]= |

In[35]:= |

Out[35]= |

In[36]:= |

Out[36]= |

Using "OutputForm"→ "Held" can result in quicker returns for large batches of functions (e.g., All), as each expression is shielded from kernel evaluation:

In[37]:= |

In[38]:= |

Auto-evaluation can cause some functions to change form, hiding the inclusion of certain subexpressions:

In[39]:= |

Out[40]= |

Though we requested a function containing Sqrt as a subexpression, it is absent in the result:

In[41]:= |

Out[41]= |

By viewing the FullForm, we see that what the front end renders as is actually Power[#,Rational[1,2]& at the expression level:

In[42]:= |

Out[42]= |

Using "OutputForm"→ "Held" preserves the "original" form of expressions, prior to kernel evaluation:

In[43]:= |

Out[44]= |

We now see the Sqrt we expect in the expression's FullForm:

In[45]:= |

Out[45]= |

To get functions free of any symbolic parameters besides the independent variable z, use the option setting "TrueUnivariate"→True:

In[46]:= |

Out[46]= |

The setting "TrueUnivariate"→ False returns only functions that *do* contain extra parameters:

In[47]:= |

Out[47]= |

The default setting "TrueUnivariate" → Automatic returns a mix of functions that do and do not contain extra parameters:

In[48]:= |

Out[48]= |

Use SeedRandom to get a repeatable sequence of functions:

In[49]:= |

Out[15]= |

In[50]:= |

Out[50]= |

In[51]:= |

Out[51]= |

This work is licensed under a Creative Commons Attribution 4.0 International License