Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

It is well-known that for any positive integer $n$ the equality $\Gamma(n+\frac12)=\sqrt\pi\,(2n-1)!!/2^n$ holds, where $!!$ stands for the double factorial. I am using FullSimplify[expr,Assumptions -> n \[Element] Integers] on certain expression expr, and the output contains $\Gamma(-\frac12+n)/\sqrt\pi$.

My question is: how can I instruct Mathematica to perform the simplification "$\Gamma(n+\frac12)=\sqrt\pi\,(2n-1)!!/2^n$ whenever $n$ is a positive integer" ? Of course, I want an answer no limited to this specific situation.

Edit: What I want is to "add" the simplification rule above to the list of simplifications included in FullSimplify, not merely "replace" the "string" $\Gamma(\cdots)$ by $\cdots !!/\cdots$.

share|improve this question
you can simply do expr/.Gamma[n+1/2]-> Sqrt[Pi](2 n-1)!!/2^n and check! – PlatoManiac Aug 12 '13 at 18:12
up vote 5 down vote accepted

You could use a function to do this expansion for you:

gammaExpand[e_] := e /. (Gamma[n_ + 1/2 /; FullSimplify[n \[Element] Integers && n > 0]] :> 
                         Sqrt[π] (2 n - 1)!!/2^n)

The FullSimplify in the definition takes care of picking up any assumptions placed in surrounding Assumptions blocks or assignments to $Assumptions.

expr = Sin[Log[Gamma[1/2 + n]]];

This doesn't expand (as it should):


Sin[Log[Gamma[1/2 + n]]]

This does:

Assuming[n \[Element] Integers && n > 0, gammaExpand@expr]

Sin[Log[2^-n Sqrt[π] (-1 + 2 n)!!]]

It would be nice if you could build this rule into FullSimplify itself. It has the option TransformationFunctions for that. However, there is a reason that this doesn't work:

            Assumptions -> n \[Element] Integers && n > 0, 
            TransformationFunctions -> {Automatic, gammaExpand}

Sin[Log[Gamma[1/2 + n]]]

The reason is that the resulting expression is simply more complex than the original, so FullSimplify doesn't have an incentive to perform this step. In fact, whenever it sees anything like the expanded form it will try to reduce it:

FullSimplify[2^-n Sqrt[π] (-1 + 2 n)!!,
             Assumptions -> n \[Element] Integers && n > 0]

Gamma[1/2 + n]

You could try to come up with a modified version of the default ComplexityFunction but that would probably be too much hassle for this simple goal. Easier would be to forbid the reducing transformation using ExcludedForms:

Assuming[n \[Element] Integers && n > 0, 
   FullSimplify[expr // gammaExpand, 
                ExcludedForms -> {Sqrt[π] (2 n_ - 1)!!/2^n_}

Sin[Log[2^-n Sqrt[[Pi]] (-1 + 2 n)!!]]

share|improve this answer
FWIW, ComplexityFunction -> (LeafCount[#] + 100 Count[#, _Gamma, Infinity] &) is suitable setting. Also the pattern Gamma[n_] /; FullSimplify[n - 1/2 \[Element] Integers && n > 1/2] seems to work more generally. – Michael E2 Aug 13 '13 at 1:16
@MichaelE2 I know, had been experimenting with that but noted that in Nasser's follow up question this was already provided, so didn't care to add that here. One big disadvantage would be that it would prevent any simplification with Gamma unrelated to the double factorial that is the issue here. – Sjoerd C. de Vries Aug 13 '13 at 5:33
There's your +1. I guess I should read comments before answering. – Mr.Wizard Aug 14 '13 at 15:59

If you try to define

Gamma[n_ + 1/2] := theExpression /; FullSimplify[ Element[ n, Integers ] && n > 0]

you will get

enter image description here

That is, you cannot "add the simplification rule above to the list of simplifications included in FullSimplify" without unprotecting Gamma first. The following code should do what you ask.

Gamma[n_ + 1/2] := theExpression /; FullSimplify[Element[n, Integers] && n > 0];
Assuming[Element[s, Integers] && s > 0, Gamma[1/2 + s]]

Nevertheless, exercise caution when unprotecting Mathematica definitions.

share|improve this answer

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.