Ask Your Question
0

Error in rising_factorial

asked 2016-02-16 03:59:07 -0500

Peter Luschny gravatar image

updated 2016-02-16 12:11:27 -0500

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
2

answered 2016-02-16 07:03:57 -0500

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

Comments

But should this function take ints and coerce them?

kcrisman gravatar imagekcrisman ( 2016-02-16 11:44:14 -0500 )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 11:58:07 -0500 )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))'
eric_g gravatar imageeric_g ( 2016-02-16 14:14:27 -0500 )edit
eric_g gravatar imageeric_g ( 2016-02-17 03:55:15 -0500 )edit
0

answered 2016-04-15 09:55:07 -0500

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

Stats

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

Seen: 119 times

Last updated: Feb 16 '16