Thanks for the bug report!
On Tue, Mar 22, 2016 at 7:51 PM, Barry M Trager <
b...@us.ibm.com> wrote:
> Hi David,
> I am trying to use the BCHCode function in Sage version 7.0.
> Since you included your email address in the code, I hope its ok to sent
> this bug note to you.
> It seems that it doesn't work properly when the finite field argument is not
> a prime field, for example:
> codes.BCHCode(65,56,GF(8,"c"),38)
> returns:
> Linear code of length 65, dimension 0 over Finite Field in c of size 2^3
> But the code actually has dimension 4.
> The problem is the way you compute the polynomial g as a product of calls to
> minpoly()
> In this case, they are giving the minpoly of elements over GF(2) instead of
> the minpoly over GF(8).
>
> One way to fix it is to directly compute the polynomial over the bigger
> field, and then map it back.
>
> from sage.rings.finite_rings.hom_finite_field import
> FiniteFieldHomomorphism_generic
> q = F.order()
> R = IntegerModRing(n)
> m = R(q).multiplicative_order()
> FF = GF(q**m,"z")
> z = FF.gen()
> e = z.multiplicative_order()/n
> a = z**e # order n
> #P = PolynomialRing(F,"x")
> #x = P.gen()
> # new code
> f = FiniteFieldHomomorphism_generic(Hom(F, FF));
> PP = PolynomialRing(FF,"x")
> x = PP.gen()
> cosetlist = reduce(operator.add, R.cyclotomic_cosets(q,
> range(b,b+delta-1)))
> g = reduce(operator.mul, [x + a^j for j in
> cosetlist]).map_coefficients(f.section(), F)
>
> I am rather new to Sage, so perhaps this isn't the best way to do this,
> another way is to represent
> FF as an explicit extension of F by factoring the minpoly of a (or z),
> however since you
> have all the cyclotomic cosets, it seems simplest to just construct the
> polynomial which has
> those powers of "a" as roots, and then map this back to a poly over F. I
> don't know if you want
> to special case the situation when F is a prime field for efficiency. If you
> do, I should point out that
> even in the primefield case, the old code was calling minpoly for each
> element of the cosets and then
> calling lcm, but if you just call minpoly on the first element of each
> coset, the resulting polynomials
> are relatively prime to each other so you can just multiply them instead of
> calling lcm.
> (i.e. minpoly on each element of a coset returns the same polynomial, in the
> case of a primefield)
>
>
> Barry Trager
>
>
>