I have encountered recently a replacement and I tried to look up documentation but could not quite find anything and hope to get some explanation from experts. The replacement is the following:

Gamma[2*x+c] /. Gamma[t:2*g_ + d_:0 ] -> 1/Sqrt[Pi]*2^(t-1)*Gamma[t/2]*Gamma[(t+1)/2]

I have never seen this way of conditional replacement. This gives correct replacement for any


What I want to know if anyone can explain the piece, what it does:

Gamma[t:2*g_ + d_:0 ]

What I understood is that whenever it sees argument of the type 2*x+c, it replaces and in the replaced output it does the following:

t-> 2*x+c

and +d_:0 is needed to recognise any argument of type


I will be grateful if anyone can explain this type of notations for replacement and what are the scopes and how it will look for multiple variable replacement.

  • $\begingroup$ t:2*g_ + d_ matches 2 x + c, t:2*g_ matches 2 x, and t:2*g_ + d_:0` (or t:2*g_ + d_.) matches both 2x` and 2 x +c. $\endgroup$
    – kglr
    Oct 30, 2018 at 17:42
  • $\begingroup$ The symbol t:2*g_ means that “t” is a name that on the right hand side represents 2*g_. In the second example d_:0 means that “0” is a default value that will be used in case “d” is not supplied. $\endgroup$ Oct 30, 2018 at 18:10

1 Answer 1


Take your expression and wrap it in FullForm[HoldForm[expr]] and it will spell out the details:

  Gamma[2*x + c] /. 
   Gamma[t : 2*g_ + d_: 0] -> 
    1/Sqrt[Pi]*2^(t - 1)*Gamma[t/2]*Gamma[(t + 1)/2]]]

Mathematica graphics

The construct


is a shortcut for a named pattern. t represents the pattern object 2*g_ on the right hand side during the replacement.

The construct


is a shortcut for Optional. It means that if that part of the pattern is omitted it will use 0 for d during the replacement.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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