# Mathematica syntax

Please I'mm trying to understand this sentence in Mathematica if $d=(x4+34x3+45)y^4$ ; my task to replace all y2y2 by x3+2x+2x3+2x+2 some suggest to me to use this line

d=d/.y^u_ :->(x^3+2x+2)^(u/2) /; EvenQ[u]


Can any one explain this line and thank you in advance.

• it needs to replace all $y^2$ by $x^3+2x+2$ – Ramez Hindi Nov 18 '16 at 7:55
• – corey979 Nov 18 '16 at 8:34
• You can search the documentation for the special character combinations you see but don't understand, e.g. /. and /;. Their FullForm names are ReplaceAll and Condition respectively. – Marius Ladegård Meyer Nov 18 '16 at 9:30
• note you have a syntax error. the sequence :-> should just be :>. ( It may also appear as a colon followed by a special arrow character, but not the three character sequence you have there ) – george2079 Nov 18 '16 at 18:09
• @george2079 i agree with you and this what makes me ask about its meaning what is the difference between :> and -> what is the meaning of y^u_ i need to know the meaning of y^u_ – Ramez Hindi Nov 18 '16 at 19:31

d = (x^4 + 34 x^3 + 45) y^4
d /. y^u_ :> (x^3 + 2 x + 2)^(u/2) /; EvenQ[u] picking this apart, /. y^u_ says replace every sub expression matching the pattern y to an exponent, where the exponent can be anything. Whatever the exponent is, gets named u. As a subtlety there must be an explicit exponent, ie. y by itself is not recognized as y^1

All the way to the right the /; EvenQ[u] is a Conditional that says only apply this rule if u is even.

The :> is a RuleDelayed , replace y^u with the following expression using the specific value of u at the time of the replacement. In this example the delayed rule is actually not needed. You will get the same if you use a regular rule: ->

For your very specific example you could have just done more simply

d /. y^4 -> (x^3 + 2 x + 2)^2

• Really you are amazing nice and helpful explanation and clarifications , thank you very much – Ramez Hindi Nov 18 '16 at 20:13