Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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]. – J. M. Oct 29 '12 at 5:39
up vote 4 down vote accepted

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

share|improve this answer
You've been using reverse ticks all day... Something messed up in your keyboard settings? – R. M. 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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.