Replacing gamma at half integers by double factorial

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$.

• you can simply do expr/.Gamma[n+1/2]-> Sqrt[Pi](2 n-1)!!/2^n and check! Aug 12 '13 at 18:12

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

ClearAll[gammaExpand]
gammaExpand[e_] := e /. (Gamma[n_ + 1/2 /; FullSimplify[n ∈ 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):

gammaExpand@expr

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

This does:

Assuming[n ∈ 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:

FullSimplify[expr,
Assumptions -> n ∈ 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 ∈ 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 ∈ Integers && n > 0,
FullSimplify[expr // gammaExpand,
ExcludedForms -> {Sqrt[π] (2 n_ - 1)!!/2^n_}
]
]

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

• 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. 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. Aug 13 '13 at 5:33

If you try to define

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

you will get 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.

Unprotect[Gamma];
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.