Suppose I am given two positions, as well as b[0, 0]
and b[0, 1]/Sqrt[2] + b[1, 1]/Sqrt[2]
, where b
is some undefined symbol, so that the expressions remain in an unevaluated form. I would like to create the following rule: whenever the argument of b
in position 1 is 0
and the argument in position 2 is 0
, replace this using the latter expression. For example, let's say the positions are just the first and second arguments, and I have several expressions of the form b[x,y,z]
. Looking at what I am given, I can manually write down the rule like below.
rule=b[0, 0, x_] -> b[0, 1, x]/Sqrt[2] + b[1, 1, x]/Sqrt[2]
Then I would have
b[0,0,0]/. rule
(*b[0, 1, 0]/Sqrt[2] + b[1, 1, 0]/Sqrt[2]*)
and
b[0,0,1]/.rule
(*b[0, 1, 1]/Sqrt[2] + b[1, 1, 1]/Sqrt[2]*)
Here's my attempt at creating the rule programmatically (I haven't gotten around to making this work for given positions yet, so assuming first and second argument).
rule=b[0, 0] -> b[0, 1]/Sqrt[2] + b[1, 1]/Sqrt[2] /.
b[x_, y_] -> b[x, y, Blank[]]
But this doesn't give me what I want, because the Blank[]
is not named and I don't know how to make it named since it is in the r.h.s. of the rule.
b[0,0,0]/. rule
(*b[0, 1, _]/Sqrt[2] + b[1, 1, _]/Sqrt[2]*)
Can anyone help?