First time here? Check out the FAQ!

Ask Your Question
0

Error in rising_factorial

asked 9 years ago

Peter Luschny gravatar image

updated 9 years ago

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.

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
2

answered 9 years ago

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

Preview: (hide)
link

Comments

But should this function take ints and coerce them?

kcrisman gravatar imagekcrisman ( 9 years ago )

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 ( 9 years ago )

@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 ( 9 years ago )
eric_g gravatar imageeric_g ( 9 years ago )
0

answered 8 years ago

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.

Preview: (hide)
link

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: 9 years ago

Seen: 670 times

Last updated: Feb 16 '16