Opened 3 years ago

Last modified 3 years ago

#21560 new defect

return Infinity from factorial of negative integer

Reported by: rws Owned by: aashu12
Priority: major Milestone: sage-7.4
Component: symbolics Keywords:
Cc: Merged in:
Authors: Ashutosh Ahelleya Reviewers:
Report Upstream: N/A Work issues:
Branch: u/aashu12/return_infinity_from_factorial_of_negative_integer (Commits) Commit: 02fc09cc36e79ed9301f4b58f0268eb81697ba9e
Dependencies: Stopgaps:


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.

Change History (10)

comment:1 Changed 3 years ago by aashu12

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

comment:2 Changed 3 years ago by aashu12

  • Owner changed from (none) to aashu12

comment:3 Changed 3 years ago by rws

Note that already

sage: SR(-89).factorial()

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

comment:4 follow-up: Changed 3 years ago by rws

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.

comment:5 Changed 3 years ago by rws

Note also

sage: factorial(-89.)

which would be the third alternative.

comment:6 in reply to: ↑ 4 Changed 3 years ago by aashu12

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

comment:7 Changed 3 years ago by aashu12

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

comment:8 Changed 3 years ago by rws

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.

comment:9 Changed 3 years ago by aashu12

  • Branch set to u/aashu12/return_infinity_from_factorial_of_negative_integer

comment:10 Changed 3 years ago by aashu12

  • Authors set to Ashutosh Ahelleya
  • Commit set to 02fc09cc36e79ed9301f4b58f0268eb81697ba9e

New commits:

02fc09cReturn unsigned infinity for a factorial of negative integer
Note: See TracTickets for help on using tickets.