Message Boards Message Boards

0
|
3161 Views
|
1 Reply
|
1 Total Likes
View groups...
Share
Share this post:

patterns question

Posted 10 years ago

Hello everyone, I'm newbie. Why in {1, x^1, x^2, x^3} /. x^n_ -> r[n] out {1, x, r[2], r[3]} ? I expected {1, r[1], r[2], r[3]}

Thanks in advance.

POSTED BY: rionilo

Hi,

That is since x^1 is automatically evaluated to x. Compare:

x^1 // FullForm
x^n // FullForm

Use HoldForm[] to get what you expect:

HoldForm[{1, x^1, x^2, x^3}] /. x^n_ -> r[n]

I.M.

POSTED BY: Ivan Morozov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract