This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)
 Documentation / Mathematica / Built-in Functions / Programming / Rule Application  /
Rule

  • lhs -> rhs or lhsrhs represents a rule that transforms lhs to rhs.
  • The character can be entered as -> or \[Rule].
  • lhs -> rhs evaluates rhs immediately.
  • You can apply rules using Replace.
  • The assignment lhs = rhs specifies that the rule lhs -> rhs should be used whenever it applies.
  • lhsrhs can be entered as lhs \[Rule] rhs or lhs -> rhs.
  • In StandardForm, Rule is printed using¬†.
  • Rule is a scoping construct (see Section A.3.8).
  • Symbols that occur as pattern names in lhs are treated as local to the rule. This is true when the symbols appear on the right-hand side of /; conditions in lhs, and when the symbols appear anywhere in rhs, even inside other scoping constructs.
  • See the Mathematica book: Section 2.4.1,¬†Section A.5.5.
  • See also Implementation NotesA.9.33.2MainBookLinkOldButtonDataA.9.33.2.
  • See also: Replace, Set, RuleDelayed, PolynomialReduce.
  • Related package: Utilities`FilterOptions`.

    Further Examples

    The rule x->2 is used to replace each occurrence of x with the number 2.

    In[1]:=

    Out[1]=