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

Documentation / Mathematica / Built-in Functions / Programming / Rule Application /


FilledSmallSquare Replace[expr, rules] applies a rule or list of rules in an attempt to transform the entire expression expr.

FilledSmallSquare Replace[expr, rules, levelspec] applies rules to parts of expr specified by levelspec.

FilledSmallSquare Examples: Replace[x^2, x^2 -> a] LongRightArrow.

FilledSmallSquare Replace[x + 1, x -> a] LongRightArrow.

FilledSmallSquare The rules must be of the form lhs -> rhs or lhs :> rhs.

FilledSmallSquare A list of rules can be given. The rules are tried in order. The result of the first one that applies is returned. If none of the rules apply, the original expr is returned.

FilledSmallSquare If the rules are given in nested lists, Replace is effectively mapped onto the inner lists. Thus Replace[expr, , , , ... , ... ] is equivalent to Replace[expr, , ], Replace[expr, , ... ], ... .

FilledSmallSquare Delayed rules defined with :> can contain /; conditions.

FilledSmallSquare Level specifications are described in Section A.3.6.

FilledSmallSquare The default value for levelspec in Replace is {0}.

FilledSmallSquare Replacements are performed to parts specified by levelspec even when those parts have Hold or related wrappers.

FilledSmallSquare Replace takes a Heads option, with default setting Heads -> False.

FilledSmallSquare See Section 2.5.1.

FilledSmallSquare See also: Rule, Set, ReplacePart, ReplaceList, StringReplace, PolynomialReduce.

FilledSmallSquare New in Version 1; modified in 4.

Further Examples