factorial(n)*(n+1) rewriting

123 views
Skip to first unread message

Gaurav Dhingra

unread,
Jun 18, 2015, 5:19:21 AM6/18/15
to sy...@googlegroups.com
Hi all

I was looking on the issue https://github.com/sympy/sympy/issues/8531 though i disagree for that simplification to occur. 

>>> n = Symbol('n', integer=True, positiv=True)
>>> factrial(n)*(n+1)   # i think this should not be simplified to factorial(n+1)
factorial(n)*(n+1)        # currently happens, which i think is correct.


>>> n = Symbol('n', integer=True, positiv=True)
>>> ( factorial(n)*(n+1) ).rewrite(factorial)
factorial(n)*(n + 1)            # why not returned as factorial(n + 1) ??

I was thinking if there is currently any way of rewriting it as `factorial(n + 1)`


Gaurav Dhingra


Richard Fateman

unread,
Jun 20, 2015, 7:38:30 PM6/20/15
to sy...@googlegroups.com
I thiink this hack is pretty worthless unless you have a better notion of "one more than".
e.g. factorial( (n-1)*(n+1)) * n^2  is factorial(n^2), right?

Aaron Meurer

unread,
Jul 20, 2015, 3:16:19 PM7/20/15
to sy...@googlegroups.com
combsimp() would be the place for this. In general, rewrite() doesn't do any advanced simplification. It just rewrites functions in terms of other functions (like factorial(x).rewrite(gamma) just replaces all 'factorial' instances with gamma with the appropriate shift).

It seems combsimp(factorial(n)*(n+1)) doesn't work, but it's only because it doesn't know about factorial, only gamma. This works:

In [5]: combsimp((factorial(n)*(n+1)).rewrite(gamma)).rewrite(factorial)
Out[5]: (n + 1)!


Aaron Meurer

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/cd82ac7a-7384-4891-9bca-63a0558975d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gaurav Dhingra

unread,
Jul 21, 2015, 1:23:11 AM7/21/15
to sy...@googlegroups.com
Thanks @asmeurer, that will be good.
Reply all
Reply to author
Forward
0 new messages