SubValues
Details and Options
- You can specify the subvalues for f by making an assignment of the form SubValues[f]=list.
- The list returned by SubValues has elements of the form HoldPattern[lhs]:>rhs.
Examples
open all close allBasic Examples (1)
Scope (4)
SubValues returns rules corresponding to subvalues defined for a symbol:
f[x_][y_] := x + ySubValues[f]SubValues can be defined for heads of any depth:
f[w_][x_][y_][z_] := f[w + x, y z]SubValues[f]f[1][2][3][4]f1[x_][y_][z_] := x + y + z
f2[x_][y_][z_] := x ^ y ^ z
g[x_][y_] := x * yObtain the subvalues of functions whose names start with f:
SubValues /@ Names["f*"]SubValues can be used to set the values directly:
SubValues[f] = {HoldPattern[f[x_][0]] :> x, HoldPattern[f[x_][y_]] :> f[x y][y - 1]}Definition[f]f[1][5]Applications (3)
Create a data object for properties that can be extracted:
myDataObj[x_, y_]["Properties"] := {"Properties", "Sum", "Product"}
myDataObj[x_, y_]["Sum"] := x + y
myDataObj[x_, y_]["Product"] := x yThese definitions are stored as SubValues:
SubValues[myDataObj]Extract all the properties from a given object:
(p |-> p -> myDataObj[2, 3][p]) /@ {"Properties", "Sum", "Product"}The resulting rules are in the order given:
f[x_][y_ /; y > -2] := g1[x, y]
f[x_][y_ /; y < 2] := g2[x, y]SubValues[f]f[3][0]SubValues[f] = Reverse[SubValues[f]]f[3][0]Copy a symbol's definitions to another symbol:
f[x_][0] := x
f[x_][y_] := f[x * y][y - 1]SubValues[g] = SubValues[f] /. f -> gg[1][5]% == f[1][5]Properties & Relations (5)
Values can be defined by immediate or delayed assignments:
f[_][0] = 0;
f[x_][y_] := x + y;SubValues[f]HoldPattern is used to protect the rules from their own definitions:
f[x_][y_] := h[x, y]SubValues[f]Without the HoldPattern, the left-hand side would have evaluated:
f[x_][y_] :> h[x, y]SubValues["sym"] will issue a message if the specified symbol does not exist:
SubValues["f"]If the symbol exists but has no definitions, an empty list is returned:
f;
SubValues["f"]Definition and Information display subvalues but do not return them as values:
f[x_][y_] := h[x, y]Definition[f]%//FullFormSubValues returns a value that can be used in a program:
SubValues[f]Evaluation of an expression involves applying matching subvalues:
f[x_][y_] := h[x, y]Hold[f[x][y]] /. SubValues[f]Related Guides
History
Introduced in 1991 (2.0) | Updated in 1996 (3.0) ▪ 2022 (13.2)
Text
Wolfram Research (1991), SubValues, Wolfram Language function, https://reference.wolfram.com/language/ref/SubValues.html (updated 2022).
CMS
Wolfram Language. 1991. "SubValues." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2022. https://reference.wolfram.com/language/ref/SubValues.html.
APA
Wolfram Language. (1991). SubValues. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SubValues.html
BibTeX
@misc{reference.wolfram_2026_subvalues, author="Wolfram Research", title="{SubValues}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/SubValues.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_subvalues, organization={Wolfram Research}, title={SubValues}, year={2022}, url={https://reference.wolfram.com/language/ref/SubValues.html}, note=[Accessed: 13-June-2026]}