Function Repository Resource:

ExpressionToFunctionOperator

An operator form of ExpressionToFunction that can be applied to expressions

Contributed by: Sjoerd Smit
 ResourceFunction["ExpressionToFunctionOperator"][var1,var2,…][expr] returns Function[{var1,var2,…},expr]. ResourceFunction["ExpressionToFunctionOperator"][…,{vari,1,vari,2,…},…][expr] bundles {vari,1,vari,2,…} together in one function slot as a vector argument. ResourceFunction["ExpressionToFunctionOperator"][varspec1→index1,varspec2→index2,…][expr] binds variables specified by varspeci to Slot[indexi].

Details and Options

ResourceFunction["ExpressionToFunctionOperator"][arg1,arg2,][expr] is equivalent to ResourceFunction["ExpressionToFunction"][expr,arg1,arg2,].

Examples

Basic Examples (5)

Create a function from a simple polynomial:

 In[1]:=
 Out[1]=

Evaluate the polynomial at a given value:

 In[2]:=
 Out[2]=

Convert a multivariate PDF to a function:

 In[3]:=
 Out[3]=
 In[4]:=
 Out[4]=
 In[5]:=
 Out[5]=

Bind x and y to the first slot of the function as a vector:

 In[6]:=
 Out[6]=
 In[7]:=
 Out[7]=

Bind arguments to keys in an Association:

 In[8]:=
 Out[8]=
 In[9]:=
 Out[9]=

Bind multiple symbols to a single slot:

 In[10]:=
 Out[10]=
 In[11]:=
 Out[11]=
 In[12]:=
 Out[12]=

Combine named slots with positional slots:

 In[13]:=
 Out[13]=
 In[14]:=
 Out[14]=

Options (5)

Attributes (1)

Use the Attributes option to return a function that holds its arguments:

 In[15]:=
 Out[15]=
 In[16]:=
 Out[16]=
 In[17]:=
 Out[17]=
 In[18]:=
 Out[18]=

Evaluated (4)

By default, the function body remains unevaluated:

 In[19]:=
 Out[19]=

Use EvaluatedTrue to evaluate the PDF:

 In[20]:=
 Out[20]=

When x has a value, using Evaluate directly on the first argument gives the wrong result:

 In[21]:=
 Out[21]=

Use Evaluated True to Block x while the body is being evaluated:

 In[22]:=
 Out[22]=

Applications (3)

Group x and y together as a vector argument and map over a list of points:

 In[23]:=
 Out[23]=
 In[24]:=
 In[25]:=
 In[26]:=
 Out[26]=

Add a parameter of the PDF as an argument:

 In[27]:=
 Out[27]=
 In[28]:=
 Out[28]=

Convert the solution of a differential equation to a function:

 In[29]:=
 Out[29]=
 In[30]:=
 Out[30]=
 In[31]:=
 Out[31]=

Represent the function at parameter value a=10 with OperatorApplied, then map over a range of x values:

 In[32]:=
 Out[32]=

Properties and Relations (3)

ExpressionToFunctionOperator has the exact same functionality as the resource function ExpressionToFunction, but is used in operator form:

 In[33]:=
 Out[33]=
 In[34]:=
 Out[34]=

Note, in particular, that both functions hold the expression that's being transformed into a function unless EvaluatedTrue is used:

 In[35]:=
 Out[35]=
 In[36]:=
 Out[36]=

With evaluation of the expression:

 In[37]:=
 Out[37]=
 In[38]:=
 Out[38]=

Possible Issues (3)

ExpressionToFunctionOperator is meant for expressions that do not already contain functions and may malfunction for such expressions if the replacement variables exist inside such functions:

 In[39]:=
 Out[39]=
 In[40]:=
 Out[40]=

The correct result would be:

 In[41]:=
 Out[41]=

The problem can sometimes be avoided by evaluating the inner function away:

 In[42]:=
 Out[42]=

Sjoerd Smit

Version History

• 1.0.0 – 20 July 2021