# What exactly happens when adding a Blank after a built-in function used in the rules of ReplaceAll?

Well, this question is just for curiosity, personally I never use ReplaceAll like this:

Cos[2 x] /. Sin_[2 x_] -> 2 Sin[x] Cos[x]
(* => 2 Cos[x]^2 *)


How to explain the result?

-
As a starting point towards understanding what's happening (in addition to Rojo's explanation): ponder on why MatchQ[Cos[2 x], Sin_[2 x_]] returns the result it indeed returns... also, consider the similarities between what you have and the following snippet: Cos[2 x] /. f_[2 x_] -> 2 f[x] Cos[x]. –  Ｊ. Ｍ. Oct 29 '12 at 5:39

## 1 Answer

It's quite simple, but you made it look confusing because of your naming

Cos[2 x] matches this pattern, _[2 _]

Now, you name the head Sin (bad practice :P), and the internal blank, x and transform that to 2 "the head"["the argument"] Cos["the argument"]. In this case, the head is Cos so the result becomes 2 Cos[x] Cos[x] which is 2 Cos[x]^2

-
You've been using reverse ticks all day... Something messed up in your keyboard settings? –  rm -rf Oct 29 '12 at 5:30
@rm-rf yeah, I'm trying out W8 and couldn't get it to take my custom keyboard layout. And it seems the layout I'm using has the opposite tick on the same key... –  Rojo Oct 29 '12 at 6:24