Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return Infinity from factorial of negative integer #21560

Open
rwst opened this issue Sep 22, 2016 · 11 comments
Open

return Infinity from factorial of negative integer #21560

rwst opened this issue Sep 22, 2016 · 11 comments

Comments

@rwst
Copy link
Contributor

rwst commented Sep 22, 2016

sage: factorial(-5)
...
ValueError: factorial -- self = (-5) must be nonnegative

Adapt the function's behaviour to what other CASs (sympy, Wolfram) do at integer n<-1: return unsigned infinity.

Component: symbolics

Author: Ashutosh Ahelleya

Branch/Commit: u/aashu12/return_infinity_from_factorial_of_negative_integer @ 02fc09c

Issue created by migration from https://trac.sagemath.org/ticket/21560

@rwst rwst added this to the sage-7.4 milestone Sep 22, 2016
@sagetrac-aashu12
Copy link
Mannequin

sagetrac-aashu12 mannequin commented Mar 15, 2017

comment:1

I would like to work on this issue. However, one of the CASs sympy, returns a zero for a negative number given as the input. I would like to clarify if it is required to return unsigned infinity or zero. You can refer this-> http://docs.sympy.org/0.7.1/_modules/sympy/functions/combinatorial/factorials.html

@sagetrac-aashu12 sagetrac-aashu12 mannequin self-assigned this Mar 15, 2017
@rwst
Copy link
Contributor Author

rwst commented Mar 15, 2017

comment:3

Note that already

sage: SR(-89).factorial()
Infinity

If you decide against Infinity then please change the above for consistency (you can find the code in libs/pynac/pynac.pyx).

@rwst
Copy link
Contributor Author

rwst commented Mar 15, 2017

comment:4

As to which one it should be, I guess that's arbitrary. You may need to change code that depends on the exception (maybe there is some in combinatorics) anyway. Using zero makes possibly sense, maybe to have sane behavour for some combinatorial sums.

@rwst
Copy link
Contributor Author

rwst commented Mar 15, 2017

comment:5

Note also

sage: factorial(-89.)
NaN

which would be the third alternative.

@sagetrac-aashu12
Copy link
Mannequin

sagetrac-aashu12 mannequin commented Mar 15, 2017

comment:6

I feel that it would be better if Unsigned Infinity is returned because in case we return any other value, too many files in different components have to be modified to make sure that the consistency is proper. I will modify the function such that it returns Unsigned Infinity when the input is negative by importing unsigned_infinity from sage.rings.infinity

@sagetrac-aashu12
Copy link
Mannequin

sagetrac-aashu12 mannequin commented Mar 15, 2017

comment:7

Will it be right here to import unsigned infinity from sage.rings.infinity?

@rwst
Copy link
Contributor Author

rwst commented Mar 15, 2017

comment:8

That's a style question. I personally import from the specific file instead of from all. I remember a discussion here that recommended that because this way less is imported and less time used. I could not find a reference, sorry. You see both styles used in Sage.

@sagetrac-aashu12
Copy link
Mannequin

sagetrac-aashu12 mannequin commented Mar 17, 2017

@sagetrac-aashu12
Copy link
Mannequin

sagetrac-aashu12 mannequin commented Mar 17, 2017

Commit: 02fc09c

@sagetrac-aashu12
Copy link
Mannequin

sagetrac-aashu12 mannequin commented Mar 17, 2017

Author: Ashutosh Ahelleya

@sagetrac-aashu12
Copy link
Mannequin

sagetrac-aashu12 mannequin commented Mar 17, 2017

New commits:

02fc09cReturn unsigned infinity for a factorial of negative integer

@mkoeppe mkoeppe removed this from the sage-7.4 milestone Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants