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.
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:
But also:
And there is a simple explanation why
sage
reacts like this. As said, the human factor should also factorize sometimes.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)
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 equationx == y
instead of the more complicatedfactorial(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: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.
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.