DownValuesFunctionCopy to clipboard.
✖
DownValuesFunction
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.
Examples
open allclose allBasic Examples (1)Summary of the most common use cases
Define a squaring function and use its definition to create a compiled function for the integer-typed case:

https://wolfram.com/xid/0dqv23fi62q-yfmkga

https://wolfram.com/xid/0dqv23fi62q-xfdfag

Use the compiled function with an integer argument:

https://wolfram.com/xid/0dqv23fi62q-w6t3ze

Alternatively, use FunctionDeclaration to associate the definition of a function with a type specification:

https://wolfram.com/xid/0dqv23fi62q-shdxn5


https://wolfram.com/xid/0dqv23fi62q-s66bzm

Scope (5)Survey of the scope of standard use cases
Multiple Definitions (5)
Several definitions attached to the same symbol can be used:

https://wolfram.com/xid/0dqv23fi62q-gzk889
Make a declaration and compile a function that uses the definitions:

https://wolfram.com/xid/0dqv23fi62q-no84zo

This calls the definition that uses a condition:

https://wolfram.com/xid/0dqv23fi62q-sb7ump

This calls the definition that uses a literal 2:

https://wolfram.com/xid/0dqv23fi62q-gigtxg

This calls the last catchall definition:

https://wolfram.com/xid/0dqv23fi62q-1ufc89

Definitions attached to a symbol can be used in more than one declaration with different types:

https://wolfram.com/xid/0dqv23fi62q-yscitd
Make two declarations with different types and compile functions that use each:

https://wolfram.com/xid/0dqv23fi62q-5zzk67


https://wolfram.com/xid/0dqv23fi62q-jq7835


https://wolfram.com/xid/0dqv23fi62q-mn482z

Definitions attached to a symbol can be declared with a polymorphic type:

https://wolfram.com/xid/0dqv23fi62q-js617x
Make two declarations with different types and compile functions that use each:

https://wolfram.com/xid/0dqv23fi62q-5upnd4


https://wolfram.com/xid/0dqv23fi62q-xzk6rl


https://wolfram.com/xid/0dqv23fi62q-k9eljy

Function declarations that use a symbol definition can call themselves:

https://wolfram.com/xid/0dqv23fi62q-wonkqn
Make a declaration and compile a function that uses it:

https://wolfram.com/xid/0dqv23fi62q-jbiotv


https://wolfram.com/xid/0dqv23fi62q-76eliv

Function declarations that do not apply to all inputs can use a predicate to strip out:

https://wolfram.com/xid/0dqv23fi62q-3uj39c
Make a polymorphic declaration:

https://wolfram.com/xid/0dqv23fi62q-32jwuq
This compiles for a Boolean type, but the predicate for the Floor case is known to be False at compile time, so it is stripped out:

https://wolfram.com/xid/0dqv23fi62q-qg83lj

This compiles for a real type and uses the branch with the Floor:

https://wolfram.com/xid/0dqv23fi62q-wjuxq0

Applications (1)Sample problems that can be solved with this function
Symbol Definitions (1)
Declarations that use symbol definitions are useful if the declaration is used more than once:

https://wolfram.com/xid/0dqv23fi62q-54a6c6
A FunctionDeclaration that refers to the symbol:

https://wolfram.com/xid/0dqv23fi62q-chk2hh
A function that uses the symbol:

https://wolfram.com/xid/0dqv23fi62q-3vycle
Compiled code for the function:

https://wolfram.com/xid/0dqv23fi62q-o1w4rd


https://wolfram.com/xid/0dqv23fi62q-w7lkob
A vector plot based on the data that was created:

https://wolfram.com/xid/0dqv23fi62q-9gkflt

The compiled version is much faster:

https://wolfram.com/xid/0dqv23fi62q-1dq2su


https://wolfram.com/xid/0dqv23fi62q-1rnr08


https://wolfram.com/xid/0dqv23fi62q-39u4qh

Possible Issues (3)Common pitfalls and unexpected behavior
Updating (2)
DownValuesFunction uses the definitions used when the compilation is carried out:

https://wolfram.com/xid/0dqv23fi62q-21ibba

https://wolfram.com/xid/0dqv23fi62q-da449o

https://wolfram.com/xid/0dqv23fi62q-ftapdu


https://wolfram.com/xid/0dqv23fi62q-9c0jad
The result uses the definitions in place when the compilation is done:

https://wolfram.com/xid/0dqv23fi62q-qqyp6l

KernelFunction uses the definitions used when the computation is carried out:

https://wolfram.com/xid/0dqv23fi62q-vzawbp

https://wolfram.com/xid/0dqv23fi62q-y3x6b1

https://wolfram.com/xid/0dqv23fi62q-q1nidq


https://wolfram.com/xid/0dqv23fi62q-33iwiz
The result uses the definitions in place when the computation is done:

https://wolfram.com/xid/0dqv23fi62q-pomfij

Defintion Restrictions (1)
If there is no definition that applies to all cases, an error case will be added:

https://wolfram.com/xid/0dqv23fi62q-qoewpk

https://wolfram.com/xid/0dqv23fi62q-ht44pk


https://wolfram.com/xid/0dqv23fi62q-0ei96q


https://wolfram.com/xid/0dqv23fi62q-xcz37h


Patterns with a head specification are not supported:

https://wolfram.com/xid/0dqv23fi62q-vpwpju

https://wolfram.com/xid/0dqv23fi62q-hrg2f9


Compound settings are not supported:

https://wolfram.com/xid/0dqv23fi62q-uz1l9l

https://wolfram.com/xid/0dqv23fi62q-iabvny


Sequence patterns are not supported:

https://wolfram.com/xid/0dqv23fi62q-npypl9

https://wolfram.com/xid/0dqv23fi62q-dpp51t


Optional patterns are not supported:

https://wolfram.com/xid/0dqv23fi62q-k170ye

https://wolfram.com/xid/0dqv23fi62q-tswkpl


Alternative patterns are not supported:

https://wolfram.com/xid/0dqv23fi62q-0z2g9y

https://wolfram.com/xid/0dqv23fi62q-623fhs


Alternative patterns are not supported:

https://wolfram.com/xid/0dqv23fi62q-lonany

https://wolfram.com/xid/0dqv23fi62q-lpmng4


Held patterns are not supported:

https://wolfram.com/xid/0dqv23fi62q-wlubw0

https://wolfram.com/xid/0dqv23fi62q-9ht9ya


Verbatim patterns are not supported:

https://wolfram.com/xid/0dqv23fi62q-8vvxjn

https://wolfram.com/xid/0dqv23fi62q-2kfnd6


All the branches of pattern definitions must have a consistent type:

https://wolfram.com/xid/0dqv23fi62q-giaao9

https://wolfram.com/xid/0dqv23fi62q-ttvqun


Wolfram Research (2022), DownValuesFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/DownValuesFunction.html.
Text
Wolfram Research (2022), DownValuesFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/DownValuesFunction.html.
Wolfram Research (2022), DownValuesFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/DownValuesFunction.html.
CMS
Wolfram Language. 2022. "DownValuesFunction." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/DownValuesFunction.html.
Wolfram Language. 2022. "DownValuesFunction." Wolfram Language & System Documentation Center. Wolfram Research. 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
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="2022", howpublished="\url{https://reference.wolfram.com/language/ref/DownValuesFunction.html}", note=[Accessed: 21-April-2025
]}
BibLaTeX
@online{reference.wolfram_2025_downvaluesfunction, organization={Wolfram Research}, title={DownValuesFunction}, year={2022}, url={https://reference.wolfram.com/language/ref/DownValuesFunction.html}, note=[Accessed: 21-April-2025
]}