Show Factorial instead of Gamma in the result of RSolve

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.

• FullSimplify[n Gamma[n], Element[n, Integers] && n > 0] does simplify to n!. Nov 25, 2015 at 8:17
• @Karsten, but FullSimplify[n Gamma[n] (2 - n), n ∈ Integers && n > 0] doesn't produce factorials, thus necessitating the use of ComplexityFunction. Nov 25, 2015 at 8:30
• @Karsten, why doesn't FullSimplify[ Gamma[n], Element[n, Integers] && n > 0] simplify to (n - 1)! May 1, 2022 at 17:20

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)! *)


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! *)

• n! == Pochhammer[1, n] == Gamma[n + 1] == n Gamma[n]. Nov 25, 2015 at 8:41
• (face turns red) Nov 25, 2015 at 8:42
rsv = RSolveValue[{a[n] == n*a[n - 1] - n!, a[0] == 2}, a[n], n]

2 Pochhammer[1, n] - n Pochhammer[1, n]

SimplifySimplifyGamma @ rsv

2 n! - n n!

DeveloperGammaSimplify @ rsv

2 n! - n n!


Does appending

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


work?

PS You may need to do previously:

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