# Can Sage simplify factorials?

I am starting out with Sage and am playing around with some simple equations involving factorials. I have not been able to find a way for Sage to simplify the equations. Does anyone know how, if possible, this is done? The set up is:

sage: var("x, y, z")

(x, y, z)

sage: eq1 = x^2 - y^2 == 0

sage: solve(eq1, x, y)

([x == -y, x == y], [1, 1])

sage: eq2 = factorial(x) - factorial(y) == 0

sage: solve(eq2, x, y)

([factorial(x) == factorial(y)], [1])

sage: eq2.simplify()

factorial(x) - factorial(y) == 0

sage: eq2.simplify_factorial()

factorial(x) - factorial(y) == 0

sage: eq2.simplify_full()

factorial(x) - factorial(y) == 0

As you can see sage can handle polynomials in eq1 but does not seem to recognise that x == y is a solution for eq2. I have tried adding some assume commands in to restrict to positive integers but this does not help. I have not been able to find anything in the documentation so far about this seemingly simple situation which must occur frequently so if anyone has any suggestions please let me know.

edit retag close merge delete

This is a very special equation. Feel free to implement it!

For my taste, a computer algebra system is good to provide calculus support. The human "operator" should always know what she or he is doing. For instance:

sage: var( 'k' );
sage: eq = (3*k+1)*factorial(k) == 2*factorial(k+1)
sage: solve( eq, k )
[k == 1/3*(2*factorial(k + 1) - factorial(k))/factorial(k)]
sage: solve( eq.simplify_full(), k )
[k == 1, factorial(k) == 0]


But also:

sage: var( 'k' );
sage: eq = k^2*factorial(k) == factorial(k+1)
sage: solve( eq.simplify_full(), k )
[k == -1/2*sqrt(5) + 1/2, k == 1/2*sqrt(5) + 1/2, factorial(k) == 0]


And there is a simple explanation why sage reacts like this. As said, the human factor should also factorize sometimes.

( 2017-11-02 10:17:38 -0500 )edit

Thanks Dan. My aim was to use Sage to solve a system of 6 or more equations in 6 or more variables. There are a few hundred of these that I wanted to iterate through using Sage to automate the process. The equations involve factorials. If Sage is unable to deduce that x = y when x! = y! then it can’t solve the system. I have tested Sage with such a system of equations. It merely returns the input because it can’t simplify the equation of two factorials. I also tried using the gamma function instead but the same problem occurs. On the other hand for some functions f Sage does recognise that x = y is a solution to f(x) = f(y) (such as polynomials) and as a result can solve a system of equations involving those f. The human operator can’t step in to help Sage ...(more)

( 2017-11-02 10:47:49 -0500 )edit
1

Yes, i realized that the situation behind the post would be a complicated situation, but i have no idea how to explain to the solve call the special property (injectivity starting from $1$) of the factorial. In the posted case, the human operator can simply help the machine by using the equation x == y instead of the more complicated factorial(x) == factorial(y). Simplification for factorials is a general step, that may be applied or not, basicly it uses only $(k+1)! = k\cdot k!$. Sage can for instance compute:

sage: var( 'k,n' );
sage: sum( k*factorial(k), k, 0, n )
factorial(n + 1) - 1


and more complicated sums of the same type. But it also can "hurt". Please try to give a toy example, where the operator (me for instance) cannot simply rephrase the equations.

( 2017-11-02 13:56:03 -0500 )edit

Hi Dan. Here is the type of system that I would like to solve:

x2 = x1!

x3 = x2!

x5 = x4!

x5 = x3*x4

The solution can be worked out by hand fairly easily to give a one parameter solution set using x1 as the parameter. However, I can’t work out how to force Sage to find solutions to these types of systems. Maybe it isn’t possible. I would be interested to know. The difficulty appears to be that when solving the system you need to be able to simplify the equation x4! = x3*x4. By hand you know that this implies

(x4 - 1)! = x3 = x1!!

So x4 = x1! + 1. But Sage seems to get stuck and throws up its hands and outputs the original equations. Any suggestions are welcome.

( 2017-11-02 21:12:41 -0500 )edit

Sort by » oldest newest most voted

Given that I have been unable to find a way of doing this and no one else has explained how, I believe the answer to my question is that sage cannot provide x = y as a symbolic solution to the positive integer equation x! = y!.

more

Sorry, had no further idea to search for the solution. (In the above example, one may try to declare manually the minimal (one, two or three) variable(s), then let it / them take explicitly the values in [ 0..20 ] or so, the search may deliver the solutions, but this is not in the spirit of the question...)

Just accept the own answer, make it green! One up from me...

( 2017-11-16 15:31:17 -0500 )edit