ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 17 Apr 2020 21:23:07 +0200Error with rational input in IntegerVectorshttps://ask.sagemath.org/question/50814/error-with-rational-input-in-integervectors/ I discovered the following unexpected behavior of `IntegerVectors`:
sage: IntegerVectors(2,3).list()
[[2, 0, 0], [1, 1, 0], [1, 0, 1], [0, 2, 0], [0, 1, 1], [0, 0, 2]]
sage: IntegerVectors(2,3/1).list()
[[2, 0, 0], [1, 1, 0]]
The relevant code block in the implementation of `IntegerVectors` seems to be the following:
try:
return IntegerVectors_nnondescents(n, tuple(k))
except TypeError:
pass
return IntegerVectors_nk(n, k)
For `k=3/1` one has that `tuple(k)` does not give a `TypeError` (as opposed to `tuple(3)`) and thus the code never tries to interpret `k` as an integer.Fri, 17 Apr 2020 18:26:59 +0200https://ask.sagemath.org/question/50814/error-with-rational-input-in-integervectors/Answer by vdelecroix for <p>I discovered the following unexpected behavior of <code>IntegerVectors</code>:</p>
<pre><code>sage: IntegerVectors(2,3).list()
[[2, 0, 0], [1, 1, 0], [1, 0, 1], [0, 2, 0], [0, 1, 1], [0, 0, 2]]
sage: IntegerVectors(2,3/1).list()
[[2, 0, 0], [1, 1, 0]]
</code></pre>
<p>The relevant code block in the implementation of <code>IntegerVectors</code> seems to be the following:</p>
<pre><code> try:
return IntegerVectors_nnondescents(n, tuple(k))
except TypeError:
pass
return IntegerVectors_nk(n, k)
</code></pre>
<p>For <code>k=3/1</code> one has that <code>tuple(k)</code> does not give a <code>TypeError</code> (as opposed to <code>tuple(3)</code>) and thus the code never tries to interpret <code>k</code> as an integer.</p>
https://ask.sagemath.org/question/50814/error-with-rational-input-in-integervectors/?answer=50820#post-id-50820Indeed. Thanks Johannes for the bug report (and the investigation)! I opened [#29524](https://trac.sagemath.org/ticket/29524) and proposed a fix there that was positively reviewed by Frédéric Chapoton. Hopefully, it will be in a next release of SageMath (either 9.1 or 9.2).Fri, 17 Apr 2020 21:23:07 +0200https://ask.sagemath.org/question/50814/error-with-rational-input-in-integervectors/?answer=50820#post-id-50820