({{, (RefLink[UpValues, paclet:ref/UpValues])[f]
gives a list of transformation rules corresponding to all upvalues defined for the symbol f. }})

OpenersNotesSection(Spacer1)Details and Options

You can specify the upvalues for f by making an assignment of the form (RefLink[UpValues, paclet:ref/UpValues])[f]=list.

The list returned by (RefLink[UpValues, paclet:ref/UpValues]) has elements of the form (RefLink[HoldPattern, paclet:ref/HoldPattern])[lhs]:>rhs.

OpenersPrimaryExamplesSection(Spacer1)Examples  (7)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Define upvalues for a symbol g:

g/:f[g[x_]]:=h[x]

These are the upvalues associated with g:

UpValues[g]

OpenersExampleSection1(Spacer1)Scope  (2)

(RefLink[UpValues, paclet:ref/UpValues]) returns rules corresponding to upvalues defined for a symbol:

g/:g[x_]+g[y_]:=gplus[x,y]

UpValues[g]

(RefLink[UpValues, paclet:ref/UpValues]) can be used to set the values directly:

UpValues[h]={h[x_]*h[y_]:>htimes[x,y]};

h[a] h[b]

OpenersExampleSection2(Spacer1)Applications  (1)

Copy a symbol's definitions to another symbol:

g/:g[x_]+g[y_]:=gplus[x,y]

UpValues[h]=UpValues[g]/.{g->h,gplus->hplus}

h[a]+h[b]

OpenersExampleSection3(Spacer1)Properties & Relations  (3)

(RefLink[HoldPattern, paclet:ref/HoldPattern]) is used to protect the rules from their own definitions:

g/:f[g[x_]]:=h[x]

UpValues[g]

f[g[x_]]:>h[x]

(RefLink[Definition, paclet:ref/Definition]) and (RefLink[Information, paclet:ref/Information]) display upvalues but do not return them as values:

g/:f[g[x_]]:=h[x]

Definition[g]

(RefLink[UpValues, paclet:ref/UpValues]) returns a value that can be used in a program:

UpValues[g]

Evaluation of an expression involves applying matching upvalues:

g/:f[g[x_]]:=h[x]

Hold[f[g[a]]]/.UpValues[g]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[UpSet, paclet:ref/UpSet])  ▪  (RefLink[Set, paclet:ref/Set])  ▪  (RefLink[DownValues, paclet:ref/DownValues])  ▪  (RefLink[HoldAllComplete, paclet:ref/HoldAllComplete])  ▪  (RefLink[ClearAll, paclet:ref/ClearAll])  ▪  (RefLink[Information, paclet:ref/Information])  ▪  (RefLink[Save, paclet:ref/Save])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Manipulating Value Lists, paclet:tutorial/ManipulatingValueLists])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Assignments, paclet:guide/Assignments])}, {▪(RefLinkPlain[Symbol Handling, paclet:guide/SymbolHandling])}})}})