# Ticket #4302: 4302_speedup1.patch

File 4302_speedup1.patch, 2.2 KB (added by zimmerma, 11 years ago)
• ## sage/rings/polynomial/polynomial_gf2x.pyx

```# HG changeset patch
# User Paul Zimmermann <zimmerma@loria.fr>
# Date 1224348127 -7200
# Node ID a4f95b4f41101f203e14ebc4a6a3bc069e9763c8
# Parent  3be92d723a616f423472372f4ee1a5846da93821
patch for #4302: replace half mults by squarings for computing G matrix

diff -r 3be92d723a61 -r a4f95b4f4110 sage/rings/polynomial/polynomial_gf2x.pyx```
 a cdef GF2X_c _f = (self).x cdef GF2X_c _g = (g).x cdef GF2X_c gpow, tt cdef GF2X_c gpow, g2, tt GF2X_conv_long(gpow, 1) maxlength = GF2X_NumBits(_f) G = Matrix(GF(2), k, n) # first compute g^j mod h, 2 <= j < k for j in range(0, k): # first deal with j=0 for i from 0 <= i < GF2X_NumBits(gpow): mzd_write_bit(G._entries, 0, i, GF2_conv_to_long(GF2X_coeff(gpow, i))) # precompute g^2 GF2X_SqrMod_pre(g2, _g, modulus) gpow = _g for j in range(1, k, 2): if j > 1: GF2X_MulMod_pre(gpow, gpow, g2, modulus) # gpow = g^j for i from 0 <= i < GF2X_NumBits(gpow): mzd_write_bit(G._entries, j, i, GF2_conv_to_long(GF2X_coeff(gpow, i))) #gpow = (gpow * g) % h # we'll need g^k below # we now process 2j, 4j, 8j, ... by squaring each time if 2*j < k: tt = gpow jj = j while 2*jj < k: GF2X_SqrMod_pre(tt, tt, modulus) jj = 2*jj for i from 0 <= i < GF2X_NumBits(tt): mzd_write_bit(G._entries, jj, i, GF2_conv_to_long(GF2X_coeff(tt, i))) # we need that gpow = g^k at the end if k % 2 == 1: # k is odd, last j is k-2 GF2X_MulMod_pre(gpow, gpow, g2, modulus) else:          # k is even, last j is k-1 GF2X_MulMod_pre(gpow, gpow, _g, modulus) verbose("G %d x %d %5.3f s"%(G.nrows(), G.ncols(),cputime(t)),level=1)