On Sunday, 8 November 2015 18:31:00 UTC, Sihuang Hu wrote:
>
> I just used the following commands to construct an matrix:
>
> q = 2
> r = 2
> s = 2
> n = s*(r+1)
> d = 3
> P = matrix(ZZ, r+2, r+2, lambda u, k: Krawtchouk(r+1, q, k, u))
>
> But sage gives me two different results at different times:
>
> [ 1 3 3 1]
> [ 1 1 -1 -1]
> [ 1 -1 -1 1]
> [ 1 -3 3 -1]
>
> and
>
> [ 1 3 3 1]
> [ 1 0 -3 -1]
> [ 1 -3 3 1]
> [ 1 -3 3 -5]
>
> The upper matrix is the right one. But sometimes I get the lower matrix.
> Anyone knows why this happens? Thanks :)
>
No idea (unless you create another function named Krawtchouk, or something
along these lines, e.g. a function used in the it). The whole
implementation is
def Krawtchouk(n,q,l,i):
"""
Compute ``K^{n,q}_l(i)``, the Krawtchouk polynomial:
see :wikipedia:`Kravchuk_polynomials`.
It is given by
.. math::
K^{n,q}_l(i)=\sum_{j=0}^l (-1)^j(q-1)^{(l-j)}{i \choose j}{n-i
\choose l-j}
"""
from sage.rings.arith import binomial
# Use the expression in equation (55) of MacWilliams & Sloane, pg 151
# We write jth term = some_factor * (j-1)th term
kraw = jth_term = (q-1)**l * binomial(n, l) # j=0
for j in range(1,l+1):
jth_term *= -q*(l-j+1)*(i-j+1)/((q-1)*j*(n-j+1))
kraw += jth_term
return kraw
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.