5
$\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$
3
  • $\begingroup$ FullSimplify[n Gamma[n], Element[n, Integers] && n > 0] does simplify to n!. $\endgroup$
    – Karsten7
    Commented Nov 25, 2015 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$ Commented Nov 25, 2015 at 8:30
  • $\begingroup$ @Karsten, why doesn't FullSimplify[ Gamma[n], Element[n, Integers] && n > 0] simplify to (n - 1)! $\endgroup$ Commented May 1, 2022 at 17:20

4 Answers 4

4
$\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
  • 2
    $\begingroup$ n! == Pochhammer[1, n] == Gamma[n + 1] == n Gamma[n]. $\endgroup$ Commented Nov 25, 2015 at 8:41
  • $\begingroup$ (face turns red) $\endgroup$
    – Jason B.
    Commented Nov 25, 2015 at 8:42
2
$\begingroup$
rsv = RSolveValue[{a[n] == n*a[n - 1] - n!, a[0] == 2}, a[n], n]
2 Pochhammer[1, n] - n Pochhammer[1, n]
Simplify`SimplifyGamma @ rsv
2 n! - n n!
Developer`GammaSimplify @ rsv
2 n! - n n!
$\endgroup$
0
$\begingroup$

Does appending

/. Gamma -> (x |-> Factorial[x - 1]) // Simplify

work?

PS You may need to do previously:

$Assumptions = {n \[Element] Integers, n > 0};
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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