On Tuesday, June 25, 2019 at 3:10:29 AM UTC-7, Peter Luschny wrote:
>
> Am Di., 25. Juni 2019 um 10:49 Uhr 'luisfe' :
>
> | When n =0, k ranges from 0 to -1 so there is no k and the list 
> constructed in ib(n,m) 
> |  is just the empty list. Not an empty list of polynomials, just an empty 
> list.
>
> Well, then the way 'sum' is implemented is possibly improvable?
>
> The type information for "binomial(m*n-1, m*k)*polynomial(m,k)" 
> is there, regardless of what the value of the integers m, n, and k is.
>

No, it's not there, that's the problem. Do this:

    sage: def list_polys(m, n): return [binomial(m*n-1, 
m*k)*cyclotomic_polynomial(m*(k+1)) for k in (0..n-1)]
    sage: list_polys(2,0)
    []

Python evaluates the argument inside sum(...) before applying the sum 
function to it. In this case, it gets an empty list, and so has no way of 
knowing whether it came from a polynomial or anything else. I'm not sure 
what behavior would improve this. If you wanted to try to parse the 
arguments and determine that the expression binomial(m*n-1, 
m*k)*cyclotomic_polynomial(m*(k+1)) was supposed to be a polynomial, you 
need to plug in actual numbers for m, n, and k: Python functions don't have 
defined output types, so you can't tell what "cyclomic_polynomial(m*(k+1))" 
will be until you plug in numbers. In this case, m=2 and n=0, but what 
value should you plug in for k? I can imagine situations where plugging in 
k=0 is right but k=-1 is wrong, and vice versa, so what would a good 
default be?

Sage's solution, as pointed out by slelievre, seems like the right choice.

 

> (The definition of 'polynomial' here does not matter as long as it is a 
> polynomial.) 
>
> To see this try this:
>
> def ib(m, n): 
>     R = ZZ['x']
>     p = lambda m,n,k: binomial(m*n-1, m*k)*cyclotomic_polynomial(m*(k+1))
>     print type(R(p(2,n,0)))
>     return [p(m,n,k) for k in (0..n-1)]
>
> for n in (0..3): 
>     r = ib(2,n)
>     print(type(r), r)
>
> The output includes in *all* cases
> <type 
> 'sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint'>
>
> So why not use this information to return the zero of this ring if the sum 
> range (a..b) has not a <= b? 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-support.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/371b91a6-43b1-44d3-86f7-01e52368e164%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to