DownValuesFunction

DownValuesFunction[sym]

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

Details

Examples

open allclose all

Basic 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  (5)

Multiple Definitions  (5)

Several definitions attached to the same symbol can be used:

Make a declaration and 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:

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:

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

Make two declarations with different types and compile functions that use each:

Call the integer case:

Call the real case:

Function declarations that use a symbol definition can call themselves:

Make a declaration and compile a function that uses it:

Call the function:

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

Make a polymorphic declaration:

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:

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

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  (3)

Updating  (2)

DownValuesFunction uses the definitions used when the compilation is carried out:

The result uses the definitions in place when the compilation is done:

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

The result uses the definitions in place when the computation is done:

Defintion Restrictions  (1)

If there is no definition that applies to all cases, an error case will be added:

This works fine:

This triggers the error case:

Patterns with a head specification are not supported:

Compound settings are not supported:

Sequence patterns are not supported:

Optional patterns are not supported:

Alternative patterns are not supported:

Alternative patterns are not supported:

Held patterns are not supported:

Verbatim patterns are not supported:

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

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.

CMS

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

BibTeX

@misc{reference.wolfram_2024_downvaluesfunction, author="Wolfram Research", title="{DownValuesFunction}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/DownValuesFunction.html}", note=[Accessed: 18-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_downvaluesfunction, organization={Wolfram Research}, title={DownValuesFunction}, year={2022}, url={https://reference.wolfram.com/language/ref/DownValuesFunction.html}, note=[Accessed: 18-November-2024 ]}