7

I experience difficulties when using custom transformation rules. Below I give two concrete problems. I am interested in fixing each of them and in understanding what is wrong with my attitude to the issue in general.

1) Suppose I try to make symbolic computations involving gamma function $\Gamma(z)$ more effective. Particularly, I want $\it{Mathematica}$ to make use of the property $\frac{\Gamma(z+1)}{\Gamma(z)}=z$ in simplification, which it doesn't do on its own. Evaluation of

Simplify[Gamma[z + 1]/Gamma[z]]

returns

Gamma[1 + z]/Gamma[z]

In order to handle this task let me define the first transformation function

tf1[e_] := e /. Gamma[x_]/Gamma[y_] /; Simplify[x - y] == 1 :> y;

Now evaluation of

 Simplify[Gamma[z + 1]/Gamma[z], 
 TransformationFunctions -> {Automatic, tf1}]

indeed gives

z

However, execution of

Simplify[Gamma[z + 1]^2/Gamma[z]^2, 
TransformationFunctions -> {Automatic, tf1}]

results in no real simplification and gives

Gamma[1 + z]^2/Gamma[z]^2

Well, one unwitty way to deal with this problem is to define a separate transformation function for the ratio of squares. But the ratio of the third powers will then require a third transformation function and so on. I would like to handle all these possibilities universally.

I've tried something like

tfUniversal[e_] := 
e /. (Gamma[x_]/Gamma[y_])^n_ /; Simplify[x - y] == 1 :> y^n;

but this didn't work. Is there a way to solve this problem?

2) The second chapter of my adventures includes teaching "Mathematica" identity $\Gamma(z)\Gamma(1-z)=\frac{\pi}{\sin{\pi z}}$. Here problem comes right at the start. I define transformation function

tf2[e_] := 
e /. Gamma[x_] Gamma[y_] /; Simplify[x + y] == 1 :> Pi/Sin[Pi x];

and then evaluate

Simplify[{Gamma[-z] Gamma[1 + z], Gamma[z] Gamma[1 - z]}, 
TransformationFunctions -> {Automatic, tf2}]

which gives

{-\[Pi] Csc[\[Pi] z], Gamma[1 - z] Gamma[z]}

so that simplification occurs in the first case but not in the second. I wonder what is the problem here.

Overall, I am very often troubled with such issues. Is it possible to find some references in the literature on using custom transformation rules?

Any help is highly appreciated, thanks :)

Weather Report
  • 535
  • 2
  • 15
  • 1
    Would FullSimplify[Gamma[z + 1]/Gamma[z]] help ? – b.gates.you.know.what Apr 08 '14 at 14:03
  • 1
    Dear b.gatessucks, thank you for this point. I wasn't aware that the difference between Simplify and FullSimplify is important here. However, the question basically remains since FullSimplify won't work for some other functions (e.g. BarnesG which satisfies BarnesG[z+1]/Barnes[z]=Gamma[z]). – Weather Report Apr 08 '14 at 14:09
  • 1
    I appreciate that gamma functions are just an example here, but as a point of interest there is also Developer`GammaSimplify which will attempt to reduce the number of gamma functions even if the resulting expression is more complex, e.g. Developer`GammaSimplify[Gamma[z+4]/Gamma[z]] – Simon Woods Apr 08 '14 at 21:10
  • @ Simon Woods I looked up at commands of the Developer package. It is stays there in the Section "Details" that the functions like GammaSimplify and others are automatically used by FullSimplify. Could you please kindly comment, why you find that using this package is advantageous with respect to FullSimplify? – Alexei Boulbitch Apr 09 '14 at 07:42

3 Answers3

6

Your rule for tfUniversal is almost correct, and I fixed it up by inspecting objects via FullForm.

FullForm[Gamma[z]^2/Gamma[z + 1]^2]
(* Times[Power[Gamma[z],2], Power[Gamma[Plus[1,z]],-2] *)

while the pattern in your rule has FullForm

FullForm[(Gamma[x_]/Gamma[y_])^n_]
(* Power[Times[Gamma[Pattern[x,Blank[]]],
               Power[Gamma[Pattern[y,Blank[]]],-1]], Pattern[n,Blank[]]]]*)

The important difference is your rule has Power on the outside, exponentiating the ratio, while the quantity you had tried to simplify was a Times of two Powers.

I made a working tfUniversalNew by following the expression you're interested in:

tfUniversalNew[e_] := e /. (
        (Gamma[x_]^p_. Gamma[y_]^q_.) :> Gamma[x]^(p + q) y^(-q) /; And[Simplify[x - y] == 1, p q < 0]
    )

The p q < 0 ensures that you have a ratio. Now

Simplify[Gamma[z + 1]^7/Gamma[z]^2, TransformationFunctions -> {Automatic, tfUniversalNew}]

gives

z^2 Gamma[1 + z]^5

I think similar FullForm inspection can help you create other rules for cases of interest...

evanb
  • 6,026
  • 18
  • 30
4

How about

Simplify[Gamma[z+1]^2/Gamma[z]^2, 
  TransformationFunctions -> {Simplify`SimplifyGamma, Automatic}]
(* z^2 *)

or

FullSimplify[Gamma[z+1]^2/Gamma[z]^2]
(* z^2 *)
Greg Hurst
  • 35,921
  • 1
  • 90
  • 136
2

Immediately after posting I've found the answer to the second question and decided to put it here while the first question still remains unresolved.

The thing is that I expected $\it{Mathematica}$ to give

-\[Pi] Csc[\[Pi] (1 - z)]

when evaluating

Simplify[Gamma[z] Gamma[1 - z], 
TransformationFunctions -> {Automatic, tf2}]

but the LeafCount of the latter expression is actually less the that of the former. So $\it{Mathematica}$ does not render it as a simplification and therefore does not apply transformation.

A way to avoid it is to use some expression with a low LeafCount in the transformation function, e.g.

tf2simpler[e_] := 

e /. Gamma[x_] Gamma[y_] /; Simplify[x + y] == 1 :> simple[y];

and making a replacement rule

replacement = simple[y_] :> Pi/Sin[Pi y];

then, evaluation of

Simplify[{Gamma[-z] Gamma[1 + z], Gamma[z] Gamma[1 - z]}, 
TransformationFunctions -> {Automatic, tf2simpler}] /. replacement

Gives the desirable answer.

{\[Pi] Csc[\[Pi] (1 + z)], \[Pi] Csc[\[Pi] z]}
Weather Report
  • 535
  • 2
  • 15