ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 15 Apr 2016 09:55:07 -0500Error in rising_factorialhttp://ask.sagemath.org/question/32565/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.Tue, 16 Feb 2016 03:59:07 -0600http://ask.sagemath.org/question/32565/error-in-rising_factorial/Answer by eric_g for <pre><code>print [rising_factorial(n,n) for n in (0..5)]
print [rising_factorial(n,n) for n in range(6)]
</code></pre>
<p>I think both forms should give the same result. But the output is: </p>
<pre><code>[1, 1, 6, 60, 840, 15120]
AttributeError: 'int' object has no attribute 'parent'
</code></pre>
<p>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.</p>
http://ask.sagemath.org/question/32565/error-in-rising_factorial/?answer=33121#post-id-33121The ticket has been merged in SageMath 7.1. So if you download the latest version of SageMath, the problem has disappeared.Fri, 15 Apr 2016 09:55:07 -0500http://ask.sagemath.org/question/32565/error-in-rising_factorial/?answer=33121#post-id-33121Answer by eric_g for <pre><code>print [rising_factorial(n,n) for n in (0..5)]
print [rising_factorial(n,n) for n in range(6)]
</code></pre>
<p>I think both forms should give the same result. But the output is: </p>
<pre><code>[1, 1, 6, 60, 840, 15120]
AttributeError: 'int' object has no attribute 'parent'
</code></pre>
<p>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.</p>
http://ask.sagemath.org/question/32565/error-in-rising_factorial/?answer=32567#post-id-32567This 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). Tue, 16 Feb 2016 07:03:57 -0600http://ask.sagemath.org/question/32565/error-in-rising_factorial/?answer=32567#post-id-32567Comment by eric_g for <p>This is because (i) <code>range(6)</code> returns a list of Python integers (<code>int</code>), contrary to <code>(0..5)</code>, which is a generator of Sage integers (<code>Integer</code>), and (ii) the function <code>rising_factorial</code> is expecting Sage integers. To get the expected behavior, you should replace <code>range(6)</code> by <code>srange(6)</code> (which returns Sage integers). </p>
http://ask.sagemath.org/question/32565/error-in-rising_factorial/?comment=32577#post-id-32577This is now [http://trac.sagemath.org/ticket/20075](http://trac.sagemath.org/ticket/20075)Wed, 17 Feb 2016 03:55:15 -0600http://ask.sagemath.org/question/32565/error-in-rising_factorial/?comment=32577#post-id-32577Comment by eric_g for <p>This is because (i) <code>range(6)</code> returns a list of Python integers (<code>int</code>), contrary to <code>(0..5)</code>, which is a generator of Sage integers (<code>Integer</code>), and (ii) the function <code>rising_factorial</code> is expecting Sage integers. To get the expected behavior, you should replace <code>range(6)</code> by <code>srange(6)</code> (which returns Sage integers). </p>
http://ask.sagemath.org/question/32565/error-in-rising_factorial/?comment=32574#post-id-32574@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))'Tue, 16 Feb 2016 14:14:27 -0600http://ask.sagemath.org/question/32565/error-in-rising_factorial/?comment=32574#post-id-32574Comment by Peter Luschny for <p>This is because (i) <code>range(6)</code> returns a list of Python integers (<code>int</code>), contrary to <code>(0..5)</code>, which is a generator of Sage integers (<code>Integer</code>), and (ii) the function <code>rising_factorial</code> is expecting Sage integers. To get the expected behavior, you should replace <code>range(6)</code> by <code>srange(6)</code> (which returns Sage integers). </p>
http://ask.sagemath.org/question/32565/error-in-rising_factorial/?comment=32573#post-id-32573Thanks 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.Tue, 16 Feb 2016 11:58:07 -0600http://ask.sagemath.org/question/32565/error-in-rising_factorial/?comment=32573#post-id-32573Comment by kcrisman for <p>This is because (i) <code>range(6)</code> returns a list of Python integers (<code>int</code>), contrary to <code>(0..5)</code>, which is a generator of Sage integers (<code>Integer</code>), and (ii) the function <code>rising_factorial</code> is expecting Sage integers. To get the expected behavior, you should replace <code>range(6)</code> by <code>srange(6)</code> (which returns Sage integers). </p>
http://ask.sagemath.org/question/32565/error-in-rising_factorial/?comment=32571#post-id-32571But should this function take `int`s and coerce them?Tue, 16 Feb 2016 11:44:14 -0600http://ask.sagemath.org/question/32565/error-in-rising_factorial/?comment=32571#post-id-32571