Handle Code Symbolically
Temporarily prevent expressions from evaluating so that you can work with them symbolically.
Using Hold or HoldForm...
Wrap an expression with Hold or HoldForm
Prevent an expression from evaluating by wrapping it with Hold:
Use HoldForm to hold an expression and suppress the wrapper on output:
Operate on the expression
Modify the expression; for example, replace Reverse with Sort:
Evaluate the expression
Apply ReleaseHold to remove any instances of Hold or HoldForm in an expression, allowing it to evaluate completely:
Using Inactive and Inactivate...
Inactivate a function or functions
Wrap a function with Inactive to prevent it from evaluating. Arguments of inactivated functions are evaluated, but not the inactivated functions themselves:
Apply Inactivate to an entire expression to inactivate all of the functions in the expression:
Use InputForm to see where Inactive has been applied:
- In StandardForm, inactivated functions are displayed in gray.
Operate on the expression
Modify the expression. For example, replace 1 with 10:
Evaluate the expression
Apply Activate to remove any instances of Inactive in an expression, allowing it to evaluate completely:
Specify a pattern to activate only functions that match the pattern: