4
$\begingroup$

Now I wanted to solve for a recurring function with RSolve. Here's how I tried:

RSolveValue[{a[n] == n*a[n - 1] - n!, a[0] == 2}, a[n], n]
(*2 Pochhammer[1, n] - n Pochhammer[1, n]*)
Simplify[%, Element[n, Integers]]
(* -(-2 + n) Pochhammer[1, n] *)
FunctionExpand[%]
(* -(-2 + n) n Gamma[n] *)

Actually the result should be $(2-n)n!$, but how can I simplify the result by assuming n be positive, so the result could look nicer.

$\endgroup$
2
  • $\begingroup$ FullSimplify[n Gamma[n], Element[n, Integers] && n > 0] does simplify to n!. $\endgroup$ – Karsten 7. Nov 25 '15 at 8:17
  • $\begingroup$ @Karsten, but FullSimplify[n Gamma[n] (2 - n), n ∈ Integers && n > 0] doesn't produce factorials, thus necessitating the use of ComplexityFunction. $\endgroup$ – J. M.'s torpor Nov 25 '15 at 8:30
3
$\begingroup$

You can increase penalty for Gamma and Pochhammer headers:

simplify[expr_, n_] := 
  FullSimplify[expr, n ∈ Integers && n > 0, 
   ComplexityFunction -> ((LeafCount@# + 
        10 Count[#, _Gamma | _Pochhammer, {0, ∞}]) &)];

simplify[RSolveValue[{a[n] == n*a[n - 1] - n!, a[0] == 2}, a[n], n], n]
(* -(-2 + n) n (-1 + n)! *)
$\endgroup$
3
$\begingroup$

Don't know if this suits your needs or not, but if you are certain that the argument to Gamma is a non-negative integer, then just make the replacement manually

RSolveValue[{a[n] == n*a[n - 1] - n!, a[0] == 2}, a[n], n]
(* 2 Pochhammer[1, n] - n Pochhammer[1, n] *)

Simplify[%, Element[n, Integers]]
(* -(-2 + n) Pochhammer[1, n] *)

FunctionExpand[%]
(* -(-2 + n) n Gamma[n] *)

% /. n Gamma[n] -> Factorial[n]
(* -(-2 + n) n! *)
$\endgroup$
2
  • 1
    $\begingroup$ n! == Pochhammer[1, n] == Gamma[n + 1] == n Gamma[n]. $\endgroup$ – J. M.'s torpor Nov 25 '15 at 8:41
  • $\begingroup$ (face turns red) $\endgroup$ – Jason B. Nov 25 '15 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.