This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)


evaluates rhs and assigns the result to be the value of lhs. From then on, lhs is replaced by rhs whenever it appears.

evaluates the , and assigns the results to be the values of the corresponding .
  • lhs can be any expression, including a pattern.
  • is a typical assignment for a pattern. Notice the presence of on the left-hand side, but not the right-hand side.
  • An assignment of the form sets up a transformation rule associated with the symbol f.
  • Different rules associated with a particular symbol are usually placed in the order that you give them. If a new rule that you give is determined to be more specific than existing rules, it is, however, placed before them. When the rules are used, they are tested in order. »
  • New assignments with identical lhs overwrite old ones. »
  • You can see all the assignments associated with a symbol f using ?f or Definition[f].
  • If you make assignments for functions that have attributes like Flat and Orderless, you must make sure to set these attributes before you make assignments for the functions.
  • If lhs is of the form , then args are evaluated. »
  • When it appears in an unevaluated symbolic form, Set is treated as a scoping construct so that variables in nested occurrences are renamed if necessary. »
  • returns rhs even if for some reason the assignment specified cannot be performed.
  • Some global variables such as $RecursionLimit can only be assigned a certain range or class of values.
Set a value for :
Unset :
Set multiple values:
Set a value for :
Click for copyable input
Click for copyable input
Unset :
Click for copyable input
Set multiple values:
Click for copyable input
Click for copyable input
Ordinary program variables:
Set values for "indexed variables":
Define a function from an expression:
Use Block to temporarily set variables:
Set part of a list:
Set part of an expression:
Replace a row of a matrix:
Replace a column of a matrix:
Default values and options:
Numerical values:
Format values:
A definition for Attributes is associated with , rather than Attributes:
Set and to the same value:
Set and to different values:
Interchange values:
Set part of a sparse array:
is still a sparse array, with its second part changed:
Assign multiple return values of a function to individual variables:
A definition for a pattern with a specific head is associated with that head:
Compute the GCD of two numbers:
Find a fixed point:
Compute using Newton's method:
Use a variable as an abbreviation for a complicated expression used more than once:
A scalar implementation of backsubstitution in a system of linear equations:
A vector implementation of backsubstitution in a system of linear equations:
The right side of an immediate definition is evaluated when the definition is made:
The right side of a delayed definition is evaluated each time the definition is used:
The arguments of the left side of a definition are evaluated before the definition is made:
Definitions with the same left side overwrite earlier ones:
Make definitions for special and general cases using immediate and delayed assignments:
More specific definitions are put in front of more general ones:
The pattern variable is renamed if necessary inside a nested scope:
Module introduces new symbols, distinct from global ones:
Definition prints definitions associated with a symbol:
Information prints various information about a symbol, including any definitions:
OwnValues returns a list of rules corresponding to any downvalues defined:
Use Unset () to clear definitions with a particular left-hand side:
Clear all definitions:
In the presence of global variables, pattern variables may show unexpected behavior:
Delayed assignments behave as expected:
Runaway definitions:
Pattern variables are not symbols; you cannot normally assign to them:
Use local variables for this purpose:
Use upvalues to assign to subscripted variables:
Subscripted variables are distinct from indexed variables:
Compute the arithmetic-geometric mean of two numbers :
New in 1