Sergey V.
Sergey V.

Reputation: 1028

Difference between Rule and Pattern

Please, explain me the main difference between the Rule and the Pattern in the following examples:

enter image description here

Why we are got the different results for -> and :>?

Another one thing I want to reproduce is what should I do to obtain from expression 5+4 the result 41 via transform 5+4 to 5^2+4^2 so that to use something like:

(5 + 4) /. (x_ + y_) -> (x^2 + y^2)

or

(5 + 4) /. (x_ + y_) :> (x^2 + y^2)

instead of

{5, 4} /. {x_, y_} :> x^2 + y^2

Upvotes: 0

Views: 40

Answers (0)

Related Questions