Ask Your Question
0

Can Sage simplify factorials?

asked 2017-11-01 22:19:30 -0600

burrobert gravatar image

updated 2017-11-02 07:41:04 -0600

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 flag offensive close merge delete

Comments

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.

dan_fulea gravatar imagedan_fulea ( 2017-11-02 10:17:38 -0600 )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)

burrobert gravatar imageburrobert ( 2017-11-02 10:47:49 -0600 )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.

dan_fulea gravatar imagedan_fulea ( 2017-11-02 13:56:03 -0600 )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.

burrobert gravatar imageburrobert ( 2017-11-02 21:12:41 -0600 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2017-11-16 08:59:18 -0600

burrobert gravatar image

updated 2017-11-16 09:00:19 -0600

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!.

edit flag offensive delete link more

Comments

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...

dan_fulea gravatar imagedan_fulea ( 2017-11-16 15:31:17 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2017-11-01 22:19:30 -0600

Seen: 153 times

Last updated: Nov 16