Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why doesn't this ReplaceAll work in mathematica

I have

Table[{x1, 1, 2, 3}^i, {i, 0, 3}] /. x1 -> 1/2

But the following does not work, since x1 is not replaced with 1/2

Table[{x1, 1, 2, 3}^i, {i, 0, 3}] // Inverse /. x1 -> 1/2

Could anybody let me know why and how to fix it? Many thanks!

like image 388
Qiang Li Avatar asked Jan 21 '23 17:01

Qiang Li


1 Answers

Look at TreeForm to see how your expression is parsed.

TreeForm@Hold[Table[{x1, 1, 2, 3}^i, {i, 0, 3}] // Inverse /. x1 -> 1/2]
(source: yaroslavvb.com)

Everything after // is taken to be function head that is applied with Postfix notation. So you need some parentheses

(Table[{x1, 1, 2, 3}^i, {i, 0, 3}] // Inverse) /. x1 -> 1/2
like image 87
Yaroslav Bulatov Avatar answered Mar 15 '23 12:03

Yaroslav Bulatov