I was trying to answer this question but having hard time with the correct way to write the transformation rule.
Trying to write a rule to transform Gamma[1/2 + n]
to Sqrt[Pi] (Factorial2[2 *(n - 1/2) - 1])/2^(n - 1/2)
. Will worry about the conditions when this transformation is valid later on. I now can't even make Simplify
use this rule.
The rule is being invoked (I add a Print
and see it there), but the final result returned by the transformation function is not being used or returned)
I looked at this answer and tried what is there, but still no success. These are my attempts. The result of the Simplify
command should return Sqrt[Pi] (Factorial2[2 *(n - 1/2) - 1])/2^(n - 1/2)
in this example.
I am not sure if it is scoping issue. Can one use an If
or Cases
in the transformationFunction or must it be based only on the syntax of /. :>
?
I wish help has more examples. Only 3 basic examples are shown and that is it.
When an expression being used inside the tranformation function (like in this case, Gamma[1/2 + n]
then n
here is taken as global symbol, right? I mean it will not have a $$n or it? That what seems to be the case. So I do not see why any of these are not working.
ClearAll[n, f, e];
f = # /. Gamma[1/2 + n] :> Sqrt[Pi] (Factorial2[2*(n - 1/2) - 1])/2^(n - 1/2) &
Simplify[Gamma[1/2 + n], TransformationFunctions -> {Automatic, f}]
ClearAll[n, f, e];
f[e_] := If[MatchQ[e, Gamma[1/2 + n]], Sqrt[Pi] (Factorial2[2 *(n - 1/2) - 1])/2^(n - 1/2), e]
Simplify[Gamma[1/2 + n], TransformationFunctions -> {Automatic, f}]
http://reference.wolfram.com/mathematica/ref/TransformationFunctions.html
ComplexityFunction
doesn't value the new transformed expression as less complex than the original, it won't transform anything. Could this be it? $\endgroup$ComplexityFunction
in addition somehow? Will look into it. $\endgroup$Simplify
and friends' objective is to "more or less" minimize theComplexityFunction
, and you can help out by allowing additional transformations to be tried on parts or subparts. If you don't specify a ComplexityFunction for which the expression you aim to get is simpler, then you are not really trying to simplify. $\endgroup$Gamma
, such asComplexityFunction -> Function[exp, Count[exp, Gamma, Infinity, Heads -> True] 1000 + LeafCount@exp]
$\endgroup$n
and 2) it doesn't take the constraints onn
(positive integer) into account. See my answer for that. $\endgroup$