Ask Your Question

Error in rising_factorial

asked 2016-02-16 10:59:07 +0200

Peter Luschny gravatar image

updated 2016-02-16 19:11:27 +0200

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 flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2016-02-16 14:03:57 +0200

eric_g gravatar image

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

edit flag offensive delete link more


But should this function take ints and coerce them?

kcrisman gravatar imagekcrisman ( 2016-02-16 18:44:14 +0200 )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.

Peter Luschny gravatar imagePeter Luschny ( 2016-02-16 18:58:07 +0200 )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)")
eric_g gravatar imageeric_g ( 2016-02-16 21:14:27 +0200 )edit
eric_g gravatar imageeric_g ( 2016-02-17 10:55:15 +0200 )edit

answered 2016-04-15 16:55:07 +0200

eric_g gravatar image

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

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2016-02-16 10:59:07 +0200

Seen: 517 times

Last updated: Feb 16 '16