Opened 4 years ago

# return Infinity from factorial of negative integer

Reported by: Owned by: rws aashu12 major sage-7.4 symbolics Ashutosh Ahelleya N/A u/aashu12/return_infinity_from_factorial_of_negative_integer (Commits) 02fc09cc36e79ed9301f4b58f0268eb81697ba9e

### Description

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

### 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-> http://docs.sympy.org/0.7.1/_modules/sympy/functions/combinatorial/factorials.html

### comment:2 Changed 3 years ago by aashu12

• Owner changed from (none) to aashu12

### comment:3 Changed 3 years ago by rws

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

### comment:4 follow-up: ↓ 6 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.)
NaN
```

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:

 ​02fc09c `Return unsigned infinity for a factorial of negative integer`
Note: See TracTickets for help on using tickets.