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 argumentx_ match an argument assigning to the name x_h match if the head is hp1|p2 match if one of pi matchesf[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:
The result is the same:
Scope (13)
Multiple Definitions (1)
Several definitions attached to the same symbol can be used:
Compile a function that uses the definitions:
This calls the definition that uses a condition:
This calls the definition that uses a literal 2:
This calls the last catchall definition:
Multiple Declarations (1)
Definitions attached to a symbol can be used in more than one declaration with different types:
Make two declarations with different types and compile functions that use each:
Call the integer case:
Call the real case:
Polymorphic Declarations (1)
Definitions attached to a symbol can be declared with a polymorphic type:
Make a polymorphic declaration and compile functions that use it for different types:
Call the integer case:
Call the real case:
Recursive Calls (1)
Function declarations that use a symbol definition can call themselves:
Make a declaration and compile a function that uses it:
Call the function:
Unnamed Patterns (1)
A pattern argument does not need a name:
Compile a function that uses the definition:
Call the function with different values:
Repeated Patterns (1)
If the same name appears more than once in a definition, when called, the value must be the same:
Compile a function that uses the definition:
Call the function with different values:
Call the function with the same value and it uses the definition for the same value:
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 :
Compile a function that uses the definition:
The input is even:
The input is odd:
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 :
Make a declaration:
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)
Compilation supports compounds patterns for certain types such as "InertExpression" and "PackedArray":
Compile a function that uses the definition:
This function matches the input so a result is generated:
Compile a function with a different type to use the declaration:
Sequences (1)
Compilation supports certain sequence patterns for "InertExpression":
Compile a function that uses the definition:
This sequence gets flattened:
The pattern with a sequence does not match, so this returns a failure:
The pattern can have a compound head of any expression type:
This matches:
This does not match:
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:
The compiled version is much faster:
An animation of the output:
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)
If there is no definition that applies to particular arguments, a runtime error case will be added:
This returns a result:
There is no definition that works for this input and hence a runtime error results:
Type Consistency (1)
All the branches of pattern definitions must return the same type:
All the branches of pattern definitions must compile for the arguments:
This compiles:
This does not compile:
Unsupported Patterns (1)
Optional patterns are not supported:
Held patterns are not supported:
Verbatim patterns are not supported:
Sequence Patterns (1)
Sequence patterns do not support polymorphic declarations:
Make a polymorphic declaration, but the compilation cannot use it:
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: 17-November-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: 17-November-2025]}