20

For example, I hate that Mathematica uses Pochhammer symbol in outputs and prefer all the expressions in Gamma function. How can I ban usage of Pochhammer? I also want all outputs to use HurwitzZeta rather than Zeta.

In another instance I want the results to use my own variant of Polygamma function (modified). How can I mandate its usage when possible?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Anixx
  • 3,585
  • 1
  • 20
  • 32
  • I cannot give an exact example right now, but I think it quite ofthen appears. I am looking for a general solution that would work everywhere. – Anixx Apr 15 '12 at 16:56
  • There might be a way to set this as the default, but I think that FunctionExpand[ expr ] can take the argument TargetFunctions->{Gamma,HurwitzZeta}. – Eli Lansey Apr 15 '12 at 17:31
  • I want FullSimplify to follow these rules. – Anixx Apr 15 '12 at 17:53
  • An example would be helpful, but what about FullSimplify[expr, TransformationFunctions -> {Gamma,HurwitzZeta}] – Eli Lansey Apr 15 '12 at 18:18
  • @EliLansey I think that's ComplexExpand not FunctionExpand (having TargetFunctions option). And there it can only take {Re,Im,Abs,Arg,Conjugate,Sign} as values. – Sjoerd C. de Vries Apr 15 '12 at 20:55
  • @SjoerdC.deVries I wasn't sure about that. Thanks for clarifying. – Eli Lansey Apr 15 '12 at 23:52

3 Answers3

16

You may try for example something like:

f[e_] := 100 Count[e, _Pochhammer, {0, Infinity}] + LeafCount[e];
FullSimplify[Pochhammer[k, n], ComplexityFunction -> f]

(*
->Gamma[k + n]/Gamma[k]
*)
Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
  • Does Mathematica provide access to the default complexity function, so you can just amend it instead of completely replacing? – celtschk Apr 15 '12 at 21:58
  • 5
    @celtschk LeafCount[] IS the default Complexity function – Dr. belisarius Apr 15 '12 at 22:17
  • What complexity is by default assigned to expressions that contain user's functions? Why user-defined functions always expanded to their definitions? Can it be avoided? – Anixx Apr 15 '12 at 23:06
  • @Anixx With the default setting ComplexityFunction->Automatic, forms are ranked primarily according to their LeafCount, with corrections to treat integers with more digits as more complex. – Dr. belisarius Apr 15 '12 at 23:09
  • What complexity is assigned to user-defined functions? Why they are always expanded? – Anixx Apr 15 '12 at 23:11
  • @Anixx Because FullSimplify[expr] tries a wide range of transformations on expr involving elementary and special functions, and returns the simplest form it finds. – Dr. belisarius Apr 15 '12 at 23:51
  • 2
    @celtschk: not quite true that LeafCount is the default complexity function. As the docs ref/ComplexityFunction say, "forms are ranked primarily according to their LeafCount, with corrections to treat integers with more digits as more complex." – murray Apr 16 '12 at 00:21
  • @belisarius so why it assigns high complexity to user-defined functions and expands them? – Anixx Apr 16 '12 at 00:35
  • @Anixx Ohh, I understand you now. I think it should be related to the order in which the expression evaluates, but there are better experts here on Mma evaluation process. Perhaps you should post another question – Dr. belisarius Apr 16 '12 at 00:52
  • 1
    @Anixx by user defined 'functions' do you mean things like f[x_]:=Pochammer[x+1]? If so, then the reason is that MMA replaces any instance of f[x] with the RHS (it is actually not a Function), BEFORE any simplification is done (unless holds are in place), and hence doesn't know about simplification rules for it (see http://mathematica.stackexchange.com/questions/704/functions-vs-patterns). As to creating those rules: no idea – tkott Apr 16 '12 at 11:19
  • 1
    @celtschk, the default complexity function can be found in the Properties & Relations section of the ComplexityFunction documentation. – Simon Woods Sep 04 '12 at 08:04
  • @SimonWoods: Indeed, there it is. Thank you. – celtschk Sep 04 '12 at 18:47
9

Perhaps you will find utility in Format and related functions?

Unprotect[Pochhammer];

Format[Pochhammer[k_, n_]] := HoldForm[ Gamma[k + n]/Gamma[k] ]

Protect[Pochhammer];

Pochhammer[a, b]
Gamma[a + b]/Gamma[a]

Similar things can be done with $PrePrint:

$PrePrint = # /. Pochhammer[k_, n_] :> HoldForm[ Gamma[k + n]/Gamma[k] ] &;

Pochhammer[a, b]
Gamma[a + b]/Gamma[a]
Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
2

I have found ReplaceAll to be useful for when I want to replace instances of Gamma or Binomial calls to show as a factorial.

    x*Gamma[a] + x^2*Gamma[b] - 
  3*Binomial[z, c] /. {Gamma[n_] -> (n - 1)!, 
  Binomial[n_, k_] -> ((n)!/((n - k)!*k!))}

Out:

   x (-1 + a)! + x^2 (-1 + b)! - (3 z!)/(c! (-c + z)!)
T. Webster
  • 886
  • 2
  • 9
  • 18