DownValuesFunction[sym]
represents a function that uses definitions attached to sym when compiling.


DownValuesFunction
DownValuesFunction[sym]
represents a function that uses definitions attached to sym when compiling.
Details

- DownValuesFunction can be used directly in compiled code.
- DownValuesFunction can be used in compiled declarations specified by FunctionDeclaration.
- DownValuesFunction specifications typically use Typed to give type annotations.
- When DownValuesFunction is compiled, it creates a function from symbol declarations and compiles it.
- Declarations that use DownValuesFunction can use polymorphic types.
- The following pattern constructs are supported:
-
_ match an argument x_ match an argument assigning to the name x _h match if the head is h x_?test match if test[x] evaluates to True p/;cond match if cond evaluates to True Except[p] match if p does not match p1|p2 match if one of pi matches f[g[p]] match a compound expression (for inert expressions and packed arrays) __,___ match a sequence (for inert expressions)
Examples
open all close allBasic Examples (1)
Define a squaring function and use its definition to create a compiled function for the integer-typed case:
Use the compiled function with an integer argument:
Alternatively, use FunctionDeclaration to associate the definition of a function with a type specification:
Scope (13)
Multiple Definitions (1)
Multiple Declarations (1)
Polymorphic Declarations (1)
Recursive Calls (1)
Unnamed Patterns (1)
Repeated Patterns (1)
Matching the Head (1)
A pattern can be written to match the head:
Make a polymorphic declaration that uses the definition:
Compile a function that uses the declaration with an argument that does not match the head:
Call the function with an integer and that uses the definition that does not match the head:
Compile a function that uses the declaration with an argument that does match the head:
Call the function with a real and that uses the definition that matches the head:
Pattern Test (1)
Compiled patterns can use PatternTest:
Condition (1)
Compiled patterns can use Condition:
Compile a function that uses the definition:
The input has arguments in order:
The input has arguments not in order, so in the output, they are reversed:
Except (1)
Compiled patterns can use Except:
Make a declaration and compile a function that uses it:
The argument is even, so the first definition is not used:
The argument is odd, so the first definition is used:
Compile a function that uses the definition:
The argument is even and greater than 20, so the first definition is not used:
The argument is odd and greater than 20, so the first definition is used:
The argument is odd but less than 20, so the first definition is not used:
Alternatives (1)
Compiled patterns can use Alternatives:
Compile a function to use the declaration:
This function matches the input, so a result is generated:
Compile a function with a different type to use the declaration:
This function also matches the input, so a result is generated:
Compound Patterns (1)
Applications (1)
Symbol Definitions (1)
Declarations that use symbol definitions are useful if the declaration is used more than once:
A FunctionDeclaration that refers to the symbol:
A function that uses the symbol:
Compiled code for the function:
A vector plot based on the data that was created:
Possible Issues (5)
Updating (1)
DownValuesFunction uses the definitions used when the compilation is carried out:
The result uses the definitions in place when the compilation is done:
Definition Restrictions (1)
Type Consistency (1)
Unsupported Patterns (1)
Tech Notes
Related Guides
Text
Wolfram Research (2022), DownValuesFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/DownValuesFunction.html (updated 2025).
CMS
Wolfram Language. 2022. "DownValuesFunction." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/DownValuesFunction.html.
APA
Wolfram Language. (2022). DownValuesFunction. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DownValuesFunction.html
BibTeX
@misc{reference.wolfram_2025_downvaluesfunction, author="Wolfram Research", title="{DownValuesFunction}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/DownValuesFunction.html}", note=[Accessed: 13-August-2025]}
BibLaTeX
@online{reference.wolfram_2025_downvaluesfunction, organization={Wolfram Research}, title={DownValuesFunction}, year={2025}, url={https://reference.wolfram.com/language/ref/DownValuesFunction.html}, note=[Accessed: 13-August-2025]}