WolframLang: Functions that Transform Expression by Rules

By Xah Lee. Date: . Last updated: .

Functions that Transform Expression by Rules

The following functions take a expression and a rule or list of rules, and transform expression accordingly.

ReplaceAll[expr, rules]

🔸 SHORT SYNTAX: expr /. rules

  • Replace expr by transformation rules rules.
  • rules can be a single rule or a list of rules.

Note: this is the most frequently used.

ReplaceAll

ReplaceRepeated[expr, rules]

🔸 SHORT SYNTAX: expr //. rules

repeatedly performs replacements until expr no longer changes.

ReplaceRepeated

Replace[expr, rules, levelSpec]

applies a rule or list of rules in an attempt to transform the entire expression, at levelSpec

Replace

ReplaceAt[expr, rules, positionSpec]

transforms expr by replacing the particular positions using rules

ReplaceAt

ReplaceList[expr, rules]

transform the entire expression by applying a rule or list of rules in all possible ways, and returns a list of the results obtained.

ReplaceList

Pattern Matching