Ask Your Question

# Error in rising_factorial

print [rising_factorial(n,n) for n in (0..5)]
print [rising_factorial(n,n) for n in range(6)]


I think both forms should give the same result. But the output is:

[1, 1, 6, 60, 840, 15120]
AttributeError: 'int' object has no attribute 'parent'


Edit: The same error is thrown for falling_factorial. Note that the factorial function does not assume Sage-integers. This is a confusing inconsistency in the interface, at least.

edit retag close merge delete

## 2 answers

Sort by ยป oldest newest most voted

This is because (i) range(6) returns a list of Python integers (int), contrary to (0..5), which is a generator of Sage integers (Integer), and (ii) the function rising_factorial is expecting Sage integers. To get the expected behavior, you should replace range(6) by srange(6) (which returns Sage integers).

more

## Comments

But should this function take ints and coerce them?

( 2016-02-16 11:44:14 -0600 )edit

Thanks Eric, I know the workaround as my first line shows. But this is a blatant bug because rising_factorial(0,0) = 1 no matter what technical type of integer is used.

( 2016-02-16 11:58:07 -0600 )edit

@kcrisman: sure, I'll open a ticket for this tomorrow.

@Peter: rising_factorial(0,0) works because Sage's preparser transforms the 0's into Sage integers, as you can see by means of the function preparse:

sage: preparse("rising_factorial(0,0)")
'rising_factorial(Integer(0),Integer(0))'

( 2016-02-16 14:14:27 -0600 )edit
( 2016-02-17 03:55:15 -0600 )edit

The ticket has been merged in SageMath 7.1. So if you download the latest version of SageMath, the problem has disappeared.

more

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2016-02-16 03:59:07 -0600

Seen: 171 times

Last updated: Feb 16 '16