Function Repository Resource:

FullSimplifyFunction

Source Notebook

Convert a pure function into a simpler form

Contributed by: E. Chan-López, Carlos Francisco Arias Méndez, Ulrich Neumann and Eric Rimbey

ResourceFunction["FullSimplifyFunction"][expr]

applies a full simplification to all Function expressions within expr.

Details

ResourceFunction["FullSimplifyFunction"] threads over lists.
ResourceFunction["FullSimplifyFunction"] operates on subexpressions with head Function, accepting either a single symbol or a list of parameters.
ResourceFunction["FullSimplifyFunction"] takes the same options as FullSimplify.

Examples

Basic Examples (4) 

Use FullSimplifyFunction to simplify a simple Function:

In[1]:=
ResourceFunction["FullSimplifyFunction"][Function[# + #]]
Out[1]=

Use FullSimplifyFunction to simplify a simple function given as a rule:

In[2]:=
ResourceFunction["FullSimplifyFunction"][
 y -> Function[Cosh[#] - Sinh[#]]]
Out[2]=

Use FullSimplifyFunction to simplify a more complicated function, even when some variables have global values assigned:

In[3]:=
\[CurlyPhi] = 1;
ResourceFunction["FullSimplifyFunction"][
 f -> Function[{\[Theta], \[CurlyPhi]}, a*Cos[\[CurlyPhi]] Sin[\[Theta]] - a*Cos[\[Theta]] Sin[\[CurlyPhi]]]]
Out[4]=

Use FullSimplifyFunction to simplify multiple function rules:

In[5]:=
ResourceFunction[
 "FullSimplifyFunction"][{y -> Function[x, 1/2 (E^-x + E^x)], y -> Function[x, (E^x - E^-x)/(E^x + E^-x)]}]
Out[5]=

Scope (2) 

Use FullSimplifyFunction to simplify expressions involving special functions:

In[6]:=
ResourceFunction["FullSimplifyFunction"][
 Function[z, Csc[3 Pi/2] (BesselI[-1/2, z] - BesselK[1/2, z])/2]]
Out[6]=

Use FullSimplifyFunction with more complicated function rules:

In[7]:=
ResourceFunction["FullSimplifyFunction"][
 x -> Function[t, 1/6 E^(-Sqrt[3] t) (3 - 2 Sqrt[3] + 3 E^(2 Sqrt[3] t) + 2 Sqrt[3] E^(2 Sqrt[3] t)) C[1] - (
    E^(-Sqrt[3] t) (-1 + E^(2 Sqrt[3] t)) C[2])/(2 Sqrt[3])]]
Out[7]=

Options (3) 

Use FullSimplifyFunction with Assumptions:

In[8]:=
ResourceFunction["FullSimplifyFunction"][
 a -> Function[
   x, -Log[(1 - E^(x k[1] + (k[1] (2 I \[Pi] C[1]))/k[1]))/k[1]]], Assumptions -> C[1] \[Element] Integers]
Out[8]=

Use FullSimplifyFunction to simplify a function involving an EllipticF using assumptions:

In[9]:=
ResourceFunction["FullSimplifyFunction"][
 Function[x, E^(EllipticF[x, 1])], Assumptions -> -Pi/2 < x < Pi/2]
Out[9]=

Use FullSimplifyFunction to simplify a function of two variables under specific assumptions:

In[10]:=
ResourceFunction["FullSimplifyFunction"][
 Function[{x, y}, Sqrt[x^2 + y^2] - y], Assumptions -> x == 0 && y >= 0]
Out[10]=

Applications (3) 

Use FullSimplifyFunction with the results of DSolve:

In[11]:=
eqns = {Derivative[1][y][x] == y[x] - a z[x], Derivative[1][z][x] == y[x] - z[x], y[0] == 1, z[0] == 4};
DSolve[eqns, {y, z}, x]
Out[12]=

Use FullSimplifyFunction on the solutions:

In[13]:=
s = ResourceFunction["FullSimplifyFunction"][%]
Out[13]=

Verify the solutions:

In[14]:=
AllTrue @@ Flatten[Simplify[ReplaceAll[s][eqns[[1 ;; -3]]]]]
Out[14]=

Solve an initial value problem for an inhomogeneous linear hyperbolic system with constant coefficients:

In[15]:=
pdes = {D[u[x, t], t] == D[v[x, t], x] + 1, D[v[x, t], t] == -D[u[x, t], x] - 1};
ic = {u[x, 0] == Cos[x]^2, v[x, 0] == Sin[x]};
sol = DSolve[{pdes, ic}, {u, v}, {x, t}]
Out[17]=

Use FullSimplifyFunction on the solutions:

In[18]:=
ResourceFunction["FullSimplifyFunction"][sol]
Out[18]=

Verify the solutions:

In[19]:=
AllTrue @@ Flatten[Simplify[ReplaceAll[%][pdes]]]
Out[19]=

Use FullSimplifyFunction in the solutions of the Euler-Lagrange equations governing the motion of a rolling wheel on an inclined plane. In this particular problem, the translational coordinate y and the rotational coordinate θ are treated as independent variables. Define the equation of motion for the translational coordinate and its initial conditions:

In[20]:=
eqny = {2/3 m g Sin[\[Alpha]] - m y''[t] == 0};
In[21]:=
icvy = {y[0] == y0, y'[0] == v0};

The solution for equation of motion using DSolve:

In[22]:=
First@DSolve[Join[eqny, icvy], y, t]
Out[22]=

Apply FullSimplifyFunction:

In[23]:=
ResourceFunction["FullSimplifyFunction"][%]
Out[23]=

Verify the solution:

In[24]:=
Part[ReplaceAll[%][eqny], 1]
Out[24]=

Use the resource function SymbolToSubscript to format some parts of the solution as subscripts:

In[25]:=
ResourceFunction["SymbolToSubscript"][
 ResourceFunction["FullSimplifyFunction"][
  First@DSolve[Join[eqny, icvy], y, t]]]
Out[25]=

The equation of motion for the rotational coordinate and its initial conditions:

In[26]:=
eqn\[Theta] = {1/3 m R g Sin[\[Alpha]] - 1/2 m R^2 \[Theta]''[t] == 0};
In[27]:=
icv\[Theta] = {\[Theta][0] == \[Theta]0, \[Theta]'[0] == \[Omega]0};

The solution for this equation of motion using DSolve:

In[28]:=
First@DSolve[Join[eqn\[Theta], icv\[Theta]], \[Theta], t]
Out[28]=
In[29]:=
ResourceFunction["FullSimplifyFunction"][%]
Out[29]=

Verify the solution:

In[30]:=
Part[ReplaceAll[%][eqn\[Theta]], 1]
Out[30]=

Use SymbolToSubscript to format some parts of the solution as subscripts:

In[31]:=
ResourceFunction["SymbolToSubscript"][
 ResourceFunction["FullSimplifyFunction"][
  First@DSolve[Join[eqn\[Theta], icv\[Theta]], \[Theta], t]]]
Out[31]=

Properties and Relations (2) 

Use FullSimplifyFunction with the resource function SolutionRulesToFunctions:

In[32]:=
First@DSolve[
  Join[{1/3 g m R Sin[\[Alpha]] - 1/2 m R^2 Derivative[2][\[Theta]][t] == 0}, {\[Theta][0] == \[Theta]0, Derivative[1][\[Theta]][0] == \[Omega]0}], \[Theta][t], t]
Out[32]=
In[33]:=
ResourceFunction["SolutionRulesToFunctions"][%]
Out[33]=

Apply FullSimplifyFunction on the solution:

In[34]:=
ResourceFunction["FullSimplifyFunction"][%]
Out[34]=

An equivalent way to obtain the same results is by using ExpressionToFunction, which ensures proper handling of variable substitution during simplification:

In[35]:=
x = 1;
fun = Function[x, x Gamma[x]];
In[36]:=
ResourceFunction["ExpressionToFunction"][FullSimplify@fun[x], x, "Evaluated" -> True]
Out[36]=

Possible Issues (1) 

By design, FullSimplifyFunction applies FullSimplify to the function body while only wrapping the declared function variables with HoldPattern. Any other parameters in the expression are not automatically protected from evaluation. This behavior can be seen in the following example:

In[37]:=
b = 1;
c = 2;
Block[{b}, ResourceFunction["FullSimplifyFunction"][
  Function[x, c^2 x^2 + 2 b c x + b^2]]]
Out[38]=

Publisher

Ramón Eduardo Chan López

Requirements

Wolfram Language 13.0 (December 2021) or above

Version History

  • 1.1.0 – 12 March 2025
  • 1.0.0 – 02 August 2023

Source Metadata

Related Resources

Author Notes

This function is a generalization of the responses found in a post (titled “Simplifying the exponential expression within the Function”) on the Mathematica StackExchange platform. It incorporates ideas from that discussion and was developed in response to the author's query.

A relevant reference on handling variable scoping using Block can be found in the Stack Overflow Community post, “How to Block Symbols without evaluating them?”, with a significant contribution from Leonid Shifrin.
This issue and the update to FullSimplifyFunction were discussed in the post “Handling ‘vars appears twice in a nested scoping construct’ Warning in Custom Function”, where the function's author and another users analyzed potential improvements. The main motivation for the update was to avoid scoping construct warnings while ensuring assumptions are correctly applied inside FullSimplify.
Many thanks to Sjoerd Smit for his valuable suggestion to use ExpressionToFunction as an alternative approach for ensuring correct variable handling.
Thanks to Michael E2 for raising whether global parameters should be preserved or substituted in the simplified function, and for suggesting the use of Block to handle this explicitly.

License Information