Scope (2)
Use ScalarPureFunction to obtain a linear pure function of three variables and evaluate it at (1,-2,1):
Use ScalarPureFunction to obtain a transcendental pure function of three variables and evaluate it at (1,1,1):
Applications (3)
Generate a Height Map (1)
To generate a height map for an imaginary mountain in the shape of a two-dimensional Gaussian function, use ScalarPureFunction to represent the height at each point of the mountain as follows:
Poincaré Sections of Hamiltonian Systems with Two Degrees of Freedom (2)
Use ScalarPureFunction in combination with ClickPoincarePlot2D to plot Poincaré sections of particle motion near a black hole horizon:
Poincaré sections of the Yang-Mills-Higgs system:
Properties and Relations (2)
The function ScalarPureFunction shares some similarities with ResourceFunction["ExpressionToFunction"], which also converts expressions into pure functions. However, the two functions differ in their design and in how they handle the same use cases. Below is a comparison:
Use ScalarPureFunction in combination with ResourceFunction["TensorPureFunction"] to compute a Hessian matrix:
Possible Issues (3)
If any of the specified variables have existing definitions, ScalarPureFunction issues a warning and returns unevaluated. For example:
To avoid this issue, wrap the variables with Block to prevent conflicts with global definitions:
Since ScalarPureFunction explicitly checks for global definitions before proceeding, it remains unevaluated when global definitions of the arguments are found. For example:
Evaluate overrides the hold attribute so that ScalarPureFunction behaves as expected with the previously defined inputs:
On the other hand, when using Evaluate explicitly on the function or variable arguments before passing them to ScalarPureFunction, and at least one of the variables in the argument list has a global definition, the expected behavior of holding evaluation and issuing a warning will not occur. Instead, the function will be evaluated with the assigned values, potentially leading to incorrect results. For example:
In this case, since Evaluate forces the immediate evaluation of the input, ScalarPureFunction does not detect existing global definitions and proceeds incorrectly. To avoid this issue, it is recommended to use Clear to remove any prior definitions before applying the function.