Wolfram Research

Function Repository Resource:

TensorPureFunction (1.0.0) current version: 2.0.1 »

Source Notebook

Get a pure function whose argument is a matrix for a given tensor

Contributed by: E. Chan-López & Víctor Castellanos

ResourceFunction["TensorPureFunction"][t][argvars]

gives the corresponding pure function representation of a tensor t for a matrix of variables argvars.

Details

The t must be a tensor of any rank.
The argvars must be a tensor of rank 2 (matrix) containing the variables of interest.
ResourceFunction["TensorPureFunction"][t][argvars] can be used to obtain different functions with array arguments in the basic vector calculus and with multilinear functions to study normal forms in applied bifurcation theory.

Examples

Basic Examples (3) 

Define a function that takes a matrix of variables as input and returns a vector:

In[1]:=
func = ResourceFunction["TensorPureFunction"][{x^2 + y}][{{x, y}}]
Out[1]=

Apply the function:

In[2]:=
func[{a, b}]
Out[2]=

Use TensorPureFunction with a tensor of rank 3:

In[3]:=
t3 = ResourceFunction["TensorPureFunction"][
   D[{x^3 y - 2 x y^4 - y^6, x^2 y^2 - 5 x y^3}, {{x, y}, 2}]][{{x, y}}]
Out[3]=

Apply the function:

In[4]:=
t3[{1, 1}] // MatrixForm
Out[4]=

Use TensorPureFunction with a tensor of rank 4:

In[5]:=
t4 = ResourceFunction["TensorPureFunction"][
   D[{x^3 y - 2 x y^4 - y^6, x^2 y^2 - 5 x y^3}, {{x, y}, 3}]][{{x, y}}]
Out[5]=

Apply the function:

In[6]:=
t4[{1, 1}] // MatrixForm
Out[6]=

Scope (4) 

Use TensorPureFunction to compute a Jacobian matrix:

In[7]:=
jacobian = ResourceFunction["TensorPureFunction"][
   Simplify@D[{x^3 - 2 x y - y^6, x y^2 - 5 x y}, {{x, y}}]][{{x, y}}]
Out[7]=

Apply the Jacobian function:

In[8]:=
jacobian[{1, 1}] // MatrixForm
Out[8]=

Use TensorPureFunction to compute a Hessian matrix:

In[9]:=
hessian = ResourceFunction["TensorPureFunction"][
   D[x^3 - 2 x y - y^6, {{x, y}, 2}]][{{x, y}}]
Out[9]=

Apply the Hessian function:

In[10]:=
hessian[{1, 1}] // MatrixForm
Out[10]=

Applications (2) 

Multilinear Functions (2) 

Use TensorPureFunction with the following trilinear function:

In[11]:=
d3 = ResourceFunction["TensorPureFunction", ResourceVersion->"1.0.0"][{-2 x3 y1 y2 - 2 x2 y1 y3 - 2 x1 y2 y3, 4 x2 x3 y1 + 4 x1 x3 y2 + 4 x1 x2 y3}][{{x1, y1}, {x2, y2}, {x3, y3}}]
Out[11]=

Apply the trilinear function:

In[12]:=
d3[{{1, 1}, {1, 2}, {1, -1}}] // MatrixForm
Out[12]=

Properties and Relations (3) 

Use TensorPureFunction with the resource function JacobianMatrix:

In[13]:=
ResourceFunction["TensorPureFunction"][
  Simplify@
   ResourceFunction["JacobianMatrix"][{x^3 - 2 x y - y^6, x y^2 - 5 x y}, {x, y}]][{{x, y}}]
Out[13]=

This is equivalent the computing the Jacobian directly:

In[14]:=
jacobian = ResourceFunction["TensorPureFunction"][
   Simplify@D[{x^3 - 2 x y - y^6, x y^2 - 5 x y}, {{x, y}}]][{{x, y}}]
Out[14]=
In[15]:=
% === jacobian
Out[15]=

Use TensorPureFunction with the resource function HessianMatrix:

In[16]:=
ResourceFunction["TensorPureFunction"][
  ResourceFunction["HessianMatrix"][x^3 - 2 x y - y^6, {x, y}]][{{x, y}}]
Out[16]=

This is equivalent the computing the Hessian directly:

In[17]:=
hessian = ResourceFunction["TensorPureFunction"][
   D[x^3 - 2 x y - y^6, {{x, y}, 2}]][{{x, y}}]
Out[17]=
In[18]:=
% === hessian
Out[18]=

Use TensorPureFunction with the resource function DVectorField:

In[19]:=
d21 = ResourceFunction["TensorPureFunction"][
   ResourceFunction["DVectorField"][{x - y^2, 2 y/x}, {x, y}, {1, 2}, 2, "MultilinearFunction"]][{{x1, y1}, {x2, y2}}]
Out[19]=
In[20]:=
d22 = ResourceFunction["DVectorField"][{x - y^2, 2 y/x}, {x, y}, {1, 2}, 2, "PureMultilinearFunction"]
Out[20]=

Apply the two functions to show that the same vector is obtained:

In[21]:=
SameQ[d21[{{1, 1}, {1, 2}}], d22[{{1, 1}, {1, 2}}]]
Out[21]=

Publisher

Ramón Eduardo Chan López

Version History

  • 2.0.1 – 20 March 2024
  • 2.0.0 – 02 October 2023
  • 1.0.0 – 08 November 2022

Source Metadata

Related Resources

Author Notes

The current implementation is inspired by extensive discussion available on Mathematica Stack Exchange Community in the post 274661.

License Information